Commit 7da1da83 by Michael Koch Committed by Michael Koch

InetAddress.java, URL.java: Reformated.

2003-09-29  Michael Koch  <konqueror@gmx.de>

	* java/net/InetAddress.java,
	java/net/URL.java: Reformated.

From-SVN: r71897
parent 6cd6aed7
2003-09-29 Michael Koch <konqueror@gmx.de>
* java/net/InetAddress.java,
java/net/URL.java: Reformated.
2003-09-29 Bryce McKinlay <bryce@mckinlay.net.nz> 2003-09-29 Bryce McKinlay <bryce@mckinlay.net.nz>
* boehm.cc (_Jv_BuildGCDescr): Put first word of object in most * boehm.cc (_Jv_BuildGCDescr): Put first word of object in most
......
...@@ -138,7 +138,7 @@ public class InetAddress implements Serializable ...@@ -138,7 +138,7 @@ public class InetAddress implements Serializable
* *
* @since 1.1 * @since 1.1
*/ */
public boolean isMulticastAddress () public boolean isMulticastAddress()
{ {
int len = addr.length; int len = addr.length;
...@@ -156,7 +156,7 @@ public class InetAddress implements Serializable ...@@ -156,7 +156,7 @@ public class InetAddress implements Serializable
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isAnyLocalAddress () public boolean isAnyLocalAddress()
{ {
// This is the IPv4 implementation. // This is the IPv4 implementation.
// Any class derived from InetAddress should override this. // Any class derived from InetAddress should override this.
...@@ -168,7 +168,7 @@ public class InetAddress implements Serializable ...@@ -168,7 +168,7 @@ public class InetAddress implements Serializable
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isLoopbackAddress () public boolean isLoopbackAddress()
{ {
// This is the IPv4 implementation. // This is the IPv4 implementation.
// Any class derived from InetAddress should override this. // Any class derived from InetAddress should override this.
...@@ -181,7 +181,7 @@ public class InetAddress implements Serializable ...@@ -181,7 +181,7 @@ public class InetAddress implements Serializable
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isLinkLocalAddress () public boolean isLinkLocalAddress()
{ {
// This is the IPv4 implementation. // This is the IPv4 implementation.
// Any class derived from InetAddress should override this. // Any class derived from InetAddress should override this.
...@@ -195,7 +195,7 @@ public class InetAddress implements Serializable ...@@ -195,7 +195,7 @@ public class InetAddress implements Serializable
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isSiteLocalAddress () public boolean isSiteLocalAddress()
{ {
// This is the IPv4 implementation. // This is the IPv4 implementation.
// Any class derived from InetAddress should override this. // Any class derived from InetAddress should override this.
...@@ -226,7 +226,7 @@ public class InetAddress implements Serializable ...@@ -226,7 +226,7 @@ public class InetAddress implements Serializable
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isMCGlobal () public boolean isMCGlobal()
{ {
// This is the IPv4 implementation. // This is the IPv4 implementation.
// Any class derived from InetAddress should override this. // Any class derived from InetAddress should override this.
...@@ -240,7 +240,7 @@ public class InetAddress implements Serializable ...@@ -240,7 +240,7 @@ public class InetAddress implements Serializable
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isMCNodeLocal () public boolean isMCNodeLocal()
{ {
// This is the IPv4 implementation. // This is the IPv4 implementation.
// Any class derived from InetAddress should override this. // Any class derived from InetAddress should override this.
...@@ -254,12 +254,12 @@ public class InetAddress implements Serializable ...@@ -254,12 +254,12 @@ public class InetAddress implements Serializable
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isMCLinkLocal () public boolean isMCLinkLocal()
{ {
// This is the IPv4 implementation. // This is the IPv4 implementation.
// Any class derived from InetAddress should override this. // Any class derived from InetAddress should override this.
if (!isMulticastAddress ()) if (!isMulticastAddress())
return false; return false;
return (addr [0] == 0xE0 return (addr [0] == 0xE0
...@@ -272,7 +272,7 @@ public class InetAddress implements Serializable ...@@ -272,7 +272,7 @@ public class InetAddress implements Serializable
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isMCSiteLocal () public boolean isMCSiteLocal()
{ {
// This is the IPv4 implementation. // This is the IPv4 implementation.
// Any class derived from InetAddress should override this. // Any class derived from InetAddress should override this.
...@@ -287,7 +287,7 @@ public class InetAddress implements Serializable ...@@ -287,7 +287,7 @@ public class InetAddress implements Serializable
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isMCOrgLocal () public boolean isMCOrgLocal()
{ {
// This is the IPv4 implementation. // This is the IPv4 implementation.
// Any class derived from InetAddress should override this. // Any class derived from InetAddress should override this.
...@@ -299,7 +299,7 @@ public class InetAddress implements Serializable ...@@ -299,7 +299,7 @@ public class InetAddress implements Serializable
/** /**
* Returns the hostname represented by this InetAddress * Returns the hostname represented by this InetAddress
*/ */
public String getHostName () public String getHostName()
{ {
if (hostName == null) if (hostName == null)
lookup (null, this, false); lookup (null, this, false);
...@@ -312,9 +312,9 @@ public class InetAddress implements Serializable ...@@ -312,9 +312,9 @@ public class InetAddress implements Serializable
* *
* @since 1.4 * @since 1.4
*/ */
public String getCanonicalHostName () public String getCanonicalHostName()
{ {
SecurityManager sm = System.getSecurityManager (); SecurityManager sm = System.getSecurityManager();
if (sm != null) if (sm != null)
{ {
try try
...@@ -323,23 +323,23 @@ public class InetAddress implements Serializable ...@@ -323,23 +323,23 @@ public class InetAddress implements Serializable
} }
catch (SecurityException e) catch (SecurityException e)
{ {
return getHostAddress (); return getHostAddress();
} }
} }
// Try to find the FDQN now // Try to find the FDQN now
InetAddress address = new InetAddress (getAddress (), null); InetAddress address = new InetAddress (getAddress(), null);
return address.getHostName (); return address.getHostName();
} }
/** /**
* Returns the IP address of this InetAddress as array of bytes * Returns the IP address of this InetAddress as array of bytes
*/ */
public byte[] getAddress () public byte[] getAddress()
{ {
// An experiment shows that JDK1.2 returns a different byte array each // An experiment shows that JDK1.2 returns a different byte array each
// time. This makes sense, in terms of security. // time. This makes sense, in terms of security.
return (byte[]) addr.clone (); return (byte[]) addr.clone();
} }
/* Helper function due to a CNI limitation. */ /* Helper function due to a CNI limitation. */
...@@ -351,7 +351,7 @@ public class InetAddress implements Serializable ...@@ -351,7 +351,7 @@ public class InetAddress implements Serializable
/* Helper function due to a CNI limitation. */ /* Helper function due to a CNI limitation. */
private static SecurityException checkConnect (String hostname) private static SecurityException checkConnect (String hostname)
{ {
SecurityManager s = System.getSecurityManager (); SecurityManager s = System.getSecurityManager();
if (s == null) if (s == null)
return null; return null;
...@@ -372,56 +372,63 @@ public class InetAddress implements Serializable ...@@ -372,56 +372,63 @@ public class InetAddress implements Serializable
* *
* @since 1.0.2 * @since 1.0.2
*/ */
public String getHostAddress () public String getHostAddress()
{ {
StringBuffer sbuf = new StringBuffer (40); StringBuffer sb = new StringBuffer (40);
int len = addr.length; int len = addr.length;
int i = 0; int i = 0;
if (len == 16) if (len == 16)
{ // An IPv6 address. { // An IPv6 address.
for (; ; i += 2) for ( ; ; i += 2)
{ {
if (i >= 16) if (i >= 16)
return sbuf.toString (); return sb.toString();
int x = ((addr [i] & 0xFF) << 8) | (addr [i + 1] & 0xFF); int x = ((addr [i] & 0xFF) << 8) | (addr [i + 1] & 0xFF);
boolean empty = sbuf.length () == 0; boolean empty = sb.length() == 0;
if (empty) if (empty)
{ {
if (i == 10 && x == 0xFFFF) if (i == 10 && x == 0xFFFF)
{ // IPv4-mapped IPv6 address. { // IPv4-mapped IPv6 address.
sbuf.append (":FFFF:"); sb.append (":FFFF:");
break; // Continue as IPv4 address; break; // Continue as IPv4 address;
} }
else if (i == 12) else if (i == 12)
{ // IPv4-compatible IPv6 address. { // IPv4-compatible IPv6 address.
sbuf.append (':'); sb.append (':');
break; // Continue as IPv4 address. break; // Continue as IPv4 address.
} }
else if (i > 0) else if (i > 0)
sbuf.append ("::"); sb.append ("::");
} }
else else
sbuf.append (':'); sb.append (':');
if (x != 0 || i >= 14) if (x != 0 || i >= 14)
sbuf.append (Integer.toHexString (x).toUpperCase ()); sb.append (Integer.toHexString (x).toUpperCase());
} }
} }
for ( ; ; ) for ( ; ; )
{ {
sbuf.append (addr[i] & 0xFF); sb.append (addr [i] & 0xff);
i++; i++;
if (i == len) if (i == len)
break; break;
sbuf.append ('.');
sb.append ('.');
} }
return sbuf.toString(); return sb.toString();
} }
/** /**
* Returns a hashcode of the InetAddress * Returns a hashcode of the InetAddress
*/ */
public int hashCode () public int hashCode()
{ {
// There hashing algorithm is not specified, but a simple experiment // There hashing algorithm is not specified, but a simple experiment
// shows that it is equal to the address, as a 32-bit big-endian integer. // shows that it is equal to the address, as a 32-bit big-endian integer.
...@@ -466,10 +473,10 @@ public class InetAddress implements Serializable ...@@ -466,10 +473,10 @@ public class InetAddress implements Serializable
/** /**
* Returns then <code>InetAddress</code> as string * Returns then <code>InetAddress</code> as string
*/ */
public String toString () public String toString()
{ {
String result; String result;
String address = getHostAddress (); String address = getHostAddress();
if (hostName != null) if (hostName != null)
result = hostName + "/" + address; result = hostName + "/" + address;
...@@ -542,13 +549,13 @@ public class InetAddress implements Serializable ...@@ -542,13 +549,13 @@ public class InetAddress implements Serializable
public static InetAddress getByName (String hostname) public static InetAddress getByName (String hostname)
throws UnknownHostException throws UnknownHostException
{ {
SecurityManager s = System.getSecurityManager (); SecurityManager s = System.getSecurityManager();
if (s != null) if (s != null)
s.checkConnect (hostname, -1); s.checkConnect (hostname, -1);
// Default to current host if necessary // Default to current host if necessary
if (hostname == null) if (hostname == null)
return getLocalHost (); return getLocalHost();
// Assume that the host string is an IP address // Assume that the host string is an IP address
byte[] address = aton (hostname); byte[] address = aton (hostname);
...@@ -590,7 +597,7 @@ public class InetAddress implements Serializable ...@@ -590,7 +597,7 @@ public class InetAddress implements Serializable
public static InetAddress[] getAllByName (String hostname) public static InetAddress[] getAllByName (String hostname)
throws UnknownHostException throws UnknownHostException
{ {
SecurityManager s = System.getSecurityManager (); SecurityManager s = System.getSecurityManager();
if (s != null) if (s != null)
s.checkConnect (hostname, -1); s.checkConnect (hostname, -1);
...@@ -607,17 +614,17 @@ public class InetAddress implements Serializable ...@@ -607,17 +614,17 @@ public class InetAddress implements Serializable
return lookup (hostname, null, true); return lookup (hostname, null, true);
} }
private static native String getLocalHostname (); private static native String getLocalHostname();
/** /**
* Returns the local host * Returns the local host address.
* *
* @exception UnknownHostException If no IP address for the host could * @exception UnknownHostException If no IP address for the host could
* be found * be found
*/ */
public static InetAddress getLocalHost () throws UnknownHostException public static InetAddress getLocalHost() throws UnknownHostException
{ {
SecurityManager s = System.getSecurityManager (); SecurityManager s = System.getSecurityManager();
// Experimentation shows that JDK1.2 does cache the result. // Experimentation shows that JDK1.2 does cache the result.
// However, if there is a security manager, and the cached result // However, if there is a security manager, and the cached result
...@@ -636,7 +643,7 @@ public class InetAddress implements Serializable ...@@ -636,7 +643,7 @@ public class InetAddress implements Serializable
if (s == null && localhost != null) if (s == null && localhost != null)
return; return;
String hostname = getLocalHostname (); String hostname = getLocalHostname();
if (s != null) if (s != null)
{ {
...@@ -677,7 +684,7 @@ public class InetAddress implements Serializable ...@@ -677,7 +684,7 @@ public class InetAddress implements Serializable
/** /**
* Needed for serialization * Needed for serialization
*/ */
private void readResolve () throws ObjectStreamException private void readResolve() throws ObjectStreamException
{ {
// FIXME: implement this // FIXME: implement this
} }
...@@ -685,7 +692,7 @@ public class InetAddress implements Serializable ...@@ -685,7 +692,7 @@ public class InetAddress implements Serializable
private void readObject (ObjectInputStream ois) private void readObject (ObjectInputStream ois)
throws IOException, ClassNotFoundException throws IOException, ClassNotFoundException
{ {
ois.defaultReadObject (); ois.defaultReadObject();
addr = new byte [4]; addr = new byte [4];
addr [3] = (byte) address; addr [3] = (byte) address;
...@@ -710,6 +717,6 @@ public class InetAddress implements Serializable ...@@ -710,6 +717,6 @@ public class InetAddress implements Serializable
for (; i < len; i++) for (; i < len; i++)
address = address << 8 | (((int) addr [i]) & 0xFF); address = address << 8 | (((int) addr [i]) & 0xFF);
oos.defaultWriteObject (); oos.defaultWriteObject();
} }
} }
...@@ -183,7 +183,8 @@ public final class URL implements Serializable ...@@ -183,7 +183,8 @@ public final class URL implements Serializable
static static
{ {
String s = System.getProperty("gnu.java.net.nocache_protocol_handlers"); String s = System.getProperty ("gnu.java.net.nocache_protocol_handlers");
if (s == null) if (s == null)
cache_handlers = true; cache_handlers = true;
else else
...@@ -761,7 +762,7 @@ public final class URL implements Serializable ...@@ -761,7 +762,7 @@ public final class URL implements Serializable
// First, see if a protocol handler is in our cache. // First, see if a protocol handler is in our cache.
if (cache_handlers) if (cache_handlers)
{ {
if ((ph = (URLStreamHandler) ph_cache.get(protocol)) != null) if ((ph = (URLStreamHandler) ph_cache.get (protocol)) != null)
return ph; return ph;
} }
...@@ -831,7 +832,7 @@ public final class URL implements Serializable ...@@ -831,7 +832,7 @@ public final class URL implements Serializable
if (ph != null if (ph != null
&& cache_handlers) && cache_handlers)
if (ph instanceof URLStreamHandler) if (ph instanceof URLStreamHandler)
ph_cache.put(protocol, ph); ph_cache.put (protocol, ph);
else else
ph = null; ph = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment