InetAddress.java: Reformatted to better match classpath's version.

2003-06-18  Michael Koch  <konqueror@gmx.de>

	* java/net/InetAddress.java:
	Reformatted to better match classpath's version.
	* java/net/URL.java
	(equals): Simplified.
	* java/net/URLConnection.java
	(setDoInput): Revised documentation.
	(getDefaultUseCaches): Likewise.
	(setRequestProperty): Added @since tag.

From-SVN: r68143
This commit is contained in:
Michael Koch 2003-06-18 08:09:48 +00:00 committed by Michael Koch
parent a26574f5bc
commit 75da2103e4
4 changed files with 64 additions and 19 deletions

View file

@ -1,3 +1,14 @@
2003-06-18 Michael Koch <konqueror@gmx.de>
* java/net/InetAddress.java:
Reformatted to better match classpath's version.
* java/net/URL.java
(equals): Simplified.
* java/net/URLConnection.java
(setDoInput): Revised documentation.
(getDefaultUseCaches): Likewise.
(setRequestProperty): Added @since tag.
2003-06-17 Michael Koch <konqueror@gmx.de> 2003-06-17 Michael Koch <konqueror@gmx.de>
* java/net/InetSocketAddress.java * java/net/InetSocketAddress.java

View file

@ -68,19 +68,21 @@ import java.io.ObjectStreamException;
*/ */
public class InetAddress implements Serializable public class InetAddress implements Serializable
{ {
private static final long serialVersionUID = 3286316764910316507L;
// The Serialized Form specifies that an int 'address' is saved/restored. // The Serialized Form specifies that an int 'address' is saved/restored.
// This class uses a byte array internally so we'll just do the conversion // This class uses a byte array internally so we'll just do the conversion
// at serialization time and leave the rest of the algorithm as is. // at serialization time and leave the rest of the algorithm as is.
private int address; private int address;
transient byte[] addr; transient byte[] addr;
String hostName; String hostName;
// The field 'family' seems to be the AF_ value. // The field 'family' seems to be the AF_ value.
// FIXME: Much of the code in the other java.net classes does not make // FIXME: Much of the code in the other java.net classes does not make
// use of this family field. A better implementation would be to make // use of this family field. A better implementation would be to make
// use of getaddrinfo() and have other methods just check the family // use of getaddrinfo() and have other methods just check the family
// field rather than examining the length of the address each time. // field rather than examining the length of the address each time.
int family; int family;
private static final long serialVersionUID = 3286316764910316507L;
/** /**
* Needed for serialization * Needed for serialization
@ -96,8 +98,10 @@ public class InetAddress implements Serializable
ois.defaultReadObject(); ois.defaultReadObject();
addr = new byte[4]; addr = new byte[4];
addr[3] = (byte) address; addr[3] = (byte) address;
for (int i = 2; i >= 0; --i) for (int i = 2; i >= 0; --i)
addr[i] = (byte) (address >>= 8); addr[i] = (byte) (address >>= 8);
// Ignore family from serialized data. Since the saved address is 32 bits // Ignore family from serialized data. Since the saved address is 32 bits
// the deserialized object will have an IPv4 address i.e. AF_INET family. // the deserialized object will have an IPv4 address i.e. AF_INET family.
// FIXME: An alternative is to call the aton method on the deserialized // FIXME: An alternative is to call the aton method on the deserialized
@ -112,8 +116,10 @@ public class InetAddress implements Serializable
// or a 16 byte IPv6 address. // or a 16 byte IPv6 address.
int len = addr.length; int len = addr.length;
int i = len - 4; int i = len - 4;
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();
} }
@ -123,6 +129,7 @@ public class InetAddress implements Serializable
{ {
addr = address; addr = address;
hostName = hostname; hostName = hostname;
if (address != null) if (address != null)
family = getFamily (address); family = getFamily (address);
} }
@ -135,10 +142,13 @@ public class InetAddress implements Serializable
public boolean isMulticastAddress () public boolean isMulticastAddress ()
{ {
int len = addr.length; int len = addr.length;
if (len == 4) if (len == 4)
return (addr[0] & 0xF0) == 0xE0; return (addr[0] & 0xF0) == 0xE0;
if (len == 16) if (len == 16)
return addr[0] == (byte) 0xFF; return addr[0] == (byte) 0xFF;
return false; return false;
} }
@ -199,11 +209,13 @@ public class InetAddress implements Serializable
// it says 172.16.0.0 - 172.255.255.255 are site local addresses // it says 172.16.0.0 - 172.255.255.255 are site local addresses
// 172.16.0.0/12 // 172.16.0.0/12
if (addr[0] == 0xAC && (addr[1] & 0xF0) == 0x01) if (addr [0] == 0xAC
&& (addr [1] & 0xF0) == 0x01)
return true; return true;
// 192.168.0.0/16 // 192.168.0.0/16
if (addr[0] == 0xC0 && addr[1] == 0xA8) if (addr [0] == 0xC0
&& addr [1] == 0xA8)
return true; return true;
// XXX: Do we need to check more addresses here ? // XXX: Do we need to check more addresses here ?
@ -257,7 +269,7 @@ public class InetAddress implements Serializable
} }
/** /**
* Utility reoutine to check if InetAddress is a site local multicast address * Utility routine to check if InetAddress is a site local multicast address
* *
* @since 1.4 * @since 1.4
*/ */
@ -341,8 +353,10 @@ public class InetAddress implements Serializable
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;
try try
{ {
s.checkConnect(hostname, -1); s.checkConnect(hostname, -1);
@ -415,8 +429,10 @@ public class InetAddress implements Serializable
int hash = 0; int hash = 0;
int len = addr.length; int len = addr.length;
int i = len > 4 ? len - 4 : 0; int i = len > 4 ? len - 4 : 0;
for ( ; i < len; i++) for ( ; i < len; i++)
hash = (hash << 8) | (addr[i] & 0xFF); hash = (hash << 8) | (addr[i] & 0xFF);
return hash; return hash;
} }
@ -425,7 +441,8 @@ public class InetAddress implements Serializable
*/ */
public boolean equals (Object obj) public boolean equals (Object obj)
{ {
if (obj == null || ! (obj instanceof InetAddress)) if (obj == null
|| ! (obj instanceof InetAddress))
return false; return false;
// "The Java Class Libraries" 2nd edition says "If a machine has // "The Java Class Libraries" 2nd edition says "If a machine has
@ -436,11 +453,14 @@ public class InetAddress implements Serializable
// shows that the latter is correct. // shows that the latter is correct.
byte[] addr1 = addr; byte[] addr1 = addr;
byte[] addr2 = ((InetAddress) obj).addr; byte[] addr2 = ((InetAddress) obj).addr;
if (addr1.length != addr2.length) if (addr1.length != addr2.length)
return false; return false;
for (int i = addr1.length; --i >= 0; ) for (int i = addr1.length; --i >= 0; )
if (addr1[i] != addr2[i]) if (addr1[i] != addr2[i])
return false; return false;
return true; return true;
} }
@ -451,10 +471,12 @@ public class InetAddress implements Serializable
{ {
String result; String result;
String address = getHostAddress(); String address = getHostAddress();
if (hostName != null) if (hostName != null)
result = hostName + "/" + address; result = hostName + "/" + address;
else else
result = address; result = address;
return result; return result;
} }
@ -505,8 +527,10 @@ public class InetAddress implements Serializable
throw new UnknownHostException ("IP address has illegal length"); throw new UnknownHostException ("IP address has illegal length");
} }
/** If host is a valid numeric IP address, return the numeric address. /**
* Otherwise, return null. */ * If host is a valid numeric IP address, return the numeric address.
* Otherwise, return null.
*/
private static native byte[] aton (String host); private static native byte[] aton (String host);
private static native InetAddress[] lookup (String hostname, private static native InetAddress[] lookup (String hostname,
@ -523,9 +547,9 @@ public class InetAddress implements Serializable
public static InetAddress getByName (String hostname) public static InetAddress getByName (String hostname)
throws UnknownHostException throws UnknownHostException
{ {
SecurityManager sm = System.getSecurityManager(); SecurityManager s = System.getSecurityManager ();
if (sm != null) if (s != null)
sm.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)
@ -571,9 +595,9 @@ public class InetAddress implements Serializable
public static InetAddress[] getAllByName (String hostname) public static InetAddress[] getAllByName (String hostname)
throws UnknownHostException throws UnknownHostException
{ {
SecurityManager sm = System.getSecurityManager(); SecurityManager s = System.getSecurityManager ();
if (sm != null) if (s != null)
sm.checkConnect(hostname, -1); s.checkConnect (hostname, -1);
// Check if hostname is an IP address // Check if hostname is an IP address
byte[] address = aton (hostname); byte[] address = aton (hostname);
@ -608,12 +632,14 @@ public class InetAddress implements Serializable
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
// is other than "localhost", we need to check again. // is other than "localhost", we need to check again.
if (localhost == null if (localhost == null
|| (s != null && localhost.addr != localhostAddress)) || (s != null && localhost.addr != localhostAddress))
getLocalHost(s); getLocalHost(s);
return localhost; return localhost;
} }
@ -623,7 +649,9 @@ public class InetAddress implements Serializable
// Check the localhost cache again, now that we've synchronized. // Check the localhost cache again, now that we've synchronized.
if (s == null && localhost != null) if (s == null && localhost != null)
return; return;
String hostname = getLocalHostname(); String hostname = getLocalHostname();
if (s != null) if (s != null)
{ {
// "The Java Class Libraries" suggests that if the security // "The Java Class Libraries" suggests that if the security
@ -643,6 +671,7 @@ public class InetAddress implements Serializable
hostname = null; hostname = null;
} }
} }
if (hostname != null) if (hostname != null)
{ {
try try
@ -654,6 +683,7 @@ public class InetAddress implements Serializable
{ {
} }
} }
if (localhost == null) if (localhost == null)
localhost = new InetAddress (localhostAddress, "localhost"); localhost = new InetAddress (localhostAddress, "localhost");
} }

View file

@ -423,9 +423,7 @@ public final class URL implements Serializable
if (obj == null || ! (obj instanceof URL)) if (obj == null || ! (obj instanceof URL))
return false; return false;
URL uObj = (URL) obj; return handler.equals (this, (URL) obj);
return handler.equals (this, uObj);
} }
/** /**

View file

@ -509,7 +509,8 @@ public abstract class URLConnection
* to be done for this connection. This default to true unless the * to be done for this connection. This default to true unless the
* doOutput flag is set to false, in which case this defaults to false. * doOutput flag is set to false, in which case this defaults to false.
* *
* @param doinput The new value of the doInput field * @param input <code>true</code> if input is to be done,
* <code>false</code> otherwise
* *
* @exception IllegalStateException If already connected * @exception IllegalStateException If already connected
*/ */
@ -671,7 +672,10 @@ public abstract class URLConnection
} }
/** /**
* Returns the default value of the useCaches field * Returns the default value used to determine whether or not caching
* of documents will be done when possible.
*
* @return true if caches will be used, false otherwise
*/ */
public boolean getDefaultUseCaches() public boolean getDefaultUseCaches()
{ {
@ -701,6 +705,8 @@ public abstract class URLConnection
* *
* @see URLConnection#getRequestProperty(String key) * @see URLConnection#getRequestProperty(String key)
* @see URLConnection#addRequestProperty(String key, String value) * @see URLConnection#addRequestProperty(String key, String value)
*
* @since 1.4
*/ */
public void setRequestProperty(String key, String value) public void setRequestProperty(String key, String value)
{ {