Commit f6d49f66 by Michael Koch Committed by Michael Koch

Authenticator.java, [...]: Fixed javadocs, coding style and argument names all over.

2004-04-20  Michael Koch  <konqueror@gmx.de>

	* java/net/Authenticator.java,
	java/net/BindException.java,
	java/net/ConnectException.java,
	java/net/ContentHandler.java,
	java/net/ContentHandlerFactory.java,
	java/net/DatagramPacket.java,
	java/net/DatagramSocket.java,
	java/net/DatagramSocketImpl.java,
	java/net/DatagramSocketImplFactory.java,
	java/net/FileNameMap.java,
	java/net/HttpURLConnection.java,
	java/net/Inet4Address.java,
	java/net/Inet6Address.java,
	java/net/InetAddress.java,
	java/net/InetSocketAddress.java,
	java/net/JarURLConnection.java,
	java/net/MalformedURLException.java,
	java/net/MulticastSocket.java,
	java/net/NetPermission.java,
	java/net/NetworkInterface.java,
	java/net/NoRouteToHostException.java,
	java/net/PasswordAuthentication.java,
	java/net/PortUnreachableException.java,
	java/net/ProtocolException.java,
	java/net/ServerSocket.java,
	java/net/Socket.java,
	java/net/SocketAddress.java,
	java/net/SocketException.java,
	java/net/SocketImpl.java,
	java/net/SocketImplFactory.java,
	java/net/SocketOptions.java,
	java/net/SocketPermission.java,
	java/net/SocketTimeoutException.java,
	java/net/URI.java,
	java/net/URISyntaxException.java,
	java/net/URL.java,
	java/net/URLClassLoader.java,
	java/net/URLConnection.java,
	java/net/URLDecoder.java,
	java/net/URLEncoder.java,
	java/net/URLStreamHandler.java,
	java/net/URLStreamHandlerFactory.java,
	java/net/UnknownHostException.java,
	java/net/UnknownServiceException.java:
	Fixed javadocs, coding style and argument names all over.

From-SVN: r80900
parent cf6f7d55
2004-04-20 Michael Koch <konqueror@gmx.de> 2004-04-20 Michael Koch <konqueror@gmx.de>
* java/net/Authenticator.java,
java/net/BindException.java,
java/net/ConnectException.java,
java/net/ContentHandler.java,
java/net/ContentHandlerFactory.java,
java/net/DatagramPacket.java,
java/net/DatagramSocket.java,
java/net/DatagramSocketImpl.java,
java/net/DatagramSocketImplFactory.java,
java/net/FileNameMap.java,
java/net/HttpURLConnection.java,
java/net/Inet4Address.java,
java/net/Inet6Address.java,
java/net/InetAddress.java,
java/net/InetSocketAddress.java,
java/net/JarURLConnection.java,
java/net/MalformedURLException.java,
java/net/MulticastSocket.java,
java/net/NetPermission.java,
java/net/NetworkInterface.java,
java/net/NoRouteToHostException.java,
java/net/PasswordAuthentication.java,
java/net/PortUnreachableException.java,
java/net/ProtocolException.java,
java/net/ServerSocket.java,
java/net/Socket.java,
java/net/SocketAddress.java,
java/net/SocketException.java,
java/net/SocketImpl.java,
java/net/SocketImplFactory.java,
java/net/SocketOptions.java,
java/net/SocketPermission.java,
java/net/SocketTimeoutException.java,
java/net/URI.java,
java/net/URISyntaxException.java,
java/net/URL.java,
java/net/URLClassLoader.java,
java/net/URLConnection.java,
java/net/URLDecoder.java,
java/net/URLEncoder.java,
java/net/URLStreamHandler.java,
java/net/URLStreamHandlerFactory.java,
java/net/UnknownHostException.java,
java/net/UnknownServiceException.java:
Fixed javadocs, coding style and argument names all over.
2004-04-20 Michael Koch <konqueror@gmx.de>
* java/lang/Byte.java, * java/lang/Byte.java,
java/lang/CharSequence.java, java/lang/CharSequence.java,
java/lang/ClassLoader.java, java/lang/ClassLoader.java,
......
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.net; package java.net;
/** /**
* This abstract class provides a model for obtaining authentication * This abstract class provides a model for obtaining authentication
* information (in the form of a username and password) required by * information (in the form of a username and password) required by
...@@ -150,13 +151,15 @@ public abstract class Authenticator ...@@ -150,13 +151,15 @@ public abstract class Authenticator
* @exception SecurityException If the caller does not have permission to * @exception SecurityException If the caller does not have permission to
* perform this operation * perform this operation
*/ */
public static PasswordAuthentication public static PasswordAuthentication requestPasswordAuthentication(InetAddress addr,
requestPasswordAuthentication(InetAddress addr, int port, String protocol, int port,
String prompt, String scheme) String protocol,
String prompt,
String scheme)
throws SecurityException throws SecurityException
{ {
return(requestPasswordAuthentication (null, addr, port, protocol, return requestPasswordAuthentication(null, addr, port, protocol, prompt,
prompt, scheme)); scheme);
} }
/** /**
...@@ -187,9 +190,12 @@ public abstract class Authenticator ...@@ -187,9 +190,12 @@ public abstract class Authenticator
* *
* @since 1.4 * @since 1.4
*/ */
public static PasswordAuthentication public static PasswordAuthentication requestPasswordAuthentication(String host,
requestPasswordAuthentication(String host, InetAddress addr, int port, InetAddress addr,
String protocol, String prompt, String scheme) int port,
String protocol,
String prompt,
String scheme)
throws SecurityException throws SecurityException
{ {
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
...@@ -197,7 +203,7 @@ public abstract class Authenticator ...@@ -197,7 +203,7 @@ public abstract class Authenticator
sm.checkPermission(new NetPermission("requestPasswordAuthentication")); sm.checkPermission(new NetPermission("requestPasswordAuthentication"));
if (defaultAuthenticator == null) if (defaultAuthenticator == null)
return(null); return null;
defaultAuthenticator.host = host; defaultAuthenticator.host = host;
defaultAuthenticator.addr = addr; defaultAuthenticator.addr = addr;
...@@ -206,7 +212,7 @@ public abstract class Authenticator ...@@ -206,7 +212,7 @@ public abstract class Authenticator
defaultAuthenticator.prompt = prompt; defaultAuthenticator.prompt = prompt;
defaultAuthenticator.scheme = scheme; defaultAuthenticator.scheme = scheme;
return(defaultAuthenticator.getPasswordAuthentication()); return defaultAuthenticator.getPasswordAuthentication();
} }
/* /*
...@@ -232,7 +238,7 @@ public abstract class Authenticator ...@@ -232,7 +238,7 @@ public abstract class Authenticator
*/ */
protected final InetAddress getRequestingSite() protected final InetAddress getRequestingSite()
{ {
return(addr); return addr;
} }
/** /**
...@@ -240,13 +246,13 @@ public abstract class Authenticator ...@@ -240,13 +246,13 @@ public abstract class Authenticator
* or <code>null</code> if not available. * or <code>null</code> if not available.
* *
* @return The name of the host requesting authentication, or * @return The name of the host requesting authentication, or
* </code>null</code> if it is not available. * <code>null</code> if it is not available.
* *
* @since 1.4 * @since 1.4
*/ */
protected final String getRequestingHost() protected final String getRequestingHost()
{ {
return(host); return host;
} }
/** /**
...@@ -257,7 +263,7 @@ public abstract class Authenticator ...@@ -257,7 +263,7 @@ public abstract class Authenticator
*/ */
protected final int getRequestingPort() protected final int getRequestingPort()
{ {
return(port); return port;
} }
/** /**
...@@ -268,7 +274,7 @@ public abstract class Authenticator ...@@ -268,7 +274,7 @@ public abstract class Authenticator
*/ */
protected final String getRequestingProtocol() protected final String getRequestingProtocol()
{ {
return(protocol); return protocol;
} }
/** /**
...@@ -279,7 +285,7 @@ public abstract class Authenticator ...@@ -279,7 +285,7 @@ public abstract class Authenticator
*/ */
protected final String getRequestingPrompt() protected final String getRequestingPrompt()
{ {
return(prompt); return prompt;
} }
/** /**
...@@ -289,7 +295,7 @@ public abstract class Authenticator ...@@ -289,7 +295,7 @@ public abstract class Authenticator
*/ */
protected final String getRequestingScheme() protected final String getRequestingScheme()
{ {
return(scheme); return scheme;
} }
/** /**
...@@ -302,8 +308,6 @@ public abstract class Authenticator ...@@ -302,8 +308,6 @@ public abstract class Authenticator
*/ */
protected PasswordAuthentication getPasswordAuthentication() protected PasswordAuthentication getPasswordAuthentication()
{ {
return(null); return null;
} }
} // class Authenticator } // class Authenticator
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.net; package java.net;
/** /**
* This exception indicates that an error occurred while attempting to bind * This exception indicates that an error occurred while attempting to bind
* socket to a particular port. * socket to a particular port.
......
...@@ -35,9 +35,9 @@ this exception to your version of the library, but you are not ...@@ -35,9 +35,9 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
/** /**
* This exception indicates that an error occurred while attempting to * This exception indicates that an error occurred while attempting to
* connect to a remote host. Often this indicates that the remote host * connect to a remote host. Often this indicates that the remote host
......
...@@ -113,15 +113,14 @@ public abstract class ContentHandler ...@@ -113,15 +113,14 @@ public abstract class ContentHandler
public Object getContent(URLConnection urlc, Class[] classes) public Object getContent(URLConnection urlc, Class[] classes)
throws IOException throws IOException
{ {
Object obj = getContent (urlc); Object obj = getContent(urlc);
for (int i = 0; i < classes.length; i++) for (int i = 0; i < classes.length; i++)
{ {
if (classes [i].isInstance (obj)) if (classes[i].isInstance(obj))
return obj; return obj;
} }
return null; return null;
} }
} // class ContentHandler } // class ContentHandler
...@@ -35,15 +35,14 @@ this exception to your version of the library, but you are not ...@@ -35,15 +35,14 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
/** /**
* Written using on-line Java Platform 1.2 API Specification, as well * Written using on-line Java Platform 1.2 API Specification, as well
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
* Status: Believed complete and correct. * Status: Believed complete and correct.
*/ */
/** /**
* This interface maps MIME types to <code>ContentHandler</code> objects. * This interface maps MIME types to <code>ContentHandler</code> objects.
* It consists of one method that, when passed a MIME type, returns a * It consists of one method that, when passed a MIME type, returns a
...@@ -63,6 +62,4 @@ public interface ContentHandlerFactory ...@@ -63,6 +62,4 @@ public interface ContentHandlerFactory
* @return The <code>ContentHandler</code> for the passed in MIME type * @return The <code>ContentHandler</code> for the passed in MIME type
*/ */
ContentHandler createContentHandler(String mimeType); ContentHandler createContentHandler(String mimeType);
} // interface ContentHandlerFactory } // interface ContentHandlerFactory
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.net; package java.net;
/* /*
* Written using on-line Java Platform 1.2 API Specification, as well * Written using on-line Java Platform 1.2 API Specification, as well
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
...@@ -134,8 +135,8 @@ public final class DatagramPacket ...@@ -134,8 +135,8 @@ public final class DatagramPacket
* *
* @param buf A buffer containing the data to send * @param buf A buffer containing the data to send
* @param offset The offset into the buffer to start writing from. * @param offset The offset into the buffer to start writing from.
* @param len The length of the buffer (must be &lt;= buf.length) * @param length The length of the buffer (must be &lt;= buf.length)
* @param addr The address to send to * @param address The address to send to
* @param port The port to send to * @param port The port to send to
* *
* @since 1.2 * @since 1.2
...@@ -177,8 +178,7 @@ public final class DatagramPacket ...@@ -177,8 +178,7 @@ public final class DatagramPacket
* @since 1.4 * @since 1.4
*/ */
public DatagramPacket(byte[] buf, int offset, int length, public DatagramPacket(byte[] buf, int offset, int length,
SocketAddress address) SocketAddress address) throws SocketException
throws SocketException
{ {
if (! (address instanceof InetSocketAddress)) if (! (address instanceof InetSocketAddress))
throw new IllegalArgumentException("unsupported address type"); throw new IllegalArgumentException("unsupported address type");
...@@ -272,16 +272,16 @@ public final class DatagramPacket ...@@ -272,16 +272,16 @@ public final class DatagramPacket
/** /**
* This sets the address to which the data packet will be transmitted. * This sets the address to which the data packet will be transmitted.
* *
* @param addr The destination address * @param address The destination address
* *
* @since 1.1 * @since 1.1
*/ */
public synchronized void setAddress(InetAddress iaddr) public synchronized void setAddress(InetAddress address)
{ {
if (iaddr == null) if (address == null)
throw new NullPointerException("Null address"); throw new NullPointerException("Null address");
address = iaddr; this.address = address;
} }
/** /**
...@@ -291,12 +291,12 @@ public final class DatagramPacket ...@@ -291,12 +291,12 @@ public final class DatagramPacket
* *
* @since 1.1 * @since 1.1
*/ */
public synchronized void setPort(int iport) public synchronized void setPort(int port)
{ {
if (iport < 0 || iport > 65535) if (port < 0 || port > 65535)
throw new IllegalArgumentException("Invalid port: " + iport); throw new IllegalArgumentException("Invalid port: " + port);
port = iport; this.port = port;
} }
/** /**
...@@ -329,7 +329,7 @@ public final class DatagramPacket ...@@ -329,7 +329,7 @@ public final class DatagramPacket
*/ */
public SocketAddress getSocketAddress() public SocketAddress getSocketAddress()
{ {
return new InetSocketAddress (address, port); return new InetSocketAddress(address, port);
} }
/** /**
...@@ -360,7 +360,6 @@ public final class DatagramPacket ...@@ -360,7 +360,6 @@ public final class DatagramPacket
public synchronized void setData(byte[] buf, int offset, int length) public synchronized void setData(byte[] buf, int offset, int length)
{ {
// This form of setData must be used if offset is to be changed. // This form of setData must be used if offset is to be changed.
if (buf == null) if (buf == null)
throw new NullPointerException("Null buffer"); throw new NullPointerException("Null buffer");
if (offset < 0) if (offset < 0)
......
...@@ -35,7 +35,6 @@ this exception to your version of the library, but you are not ...@@ -35,7 +35,6 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
import gnu.java.net.PlainDatagramSocketImpl; import gnu.java.net.PlainDatagramSocketImpl;
...@@ -44,12 +43,12 @@ import java.io.IOException; ...@@ -44,12 +43,12 @@ import java.io.IOException;
import java.nio.channels.DatagramChannel; import java.nio.channels.DatagramChannel;
import java.nio.channels.IllegalBlockingModeException; import java.nio.channels.IllegalBlockingModeException;
/** /**
* Written using on-line Java Platform 1.2 API Specification, as well * Written using on-line Java Platform 1.2 API Specification, as well
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
* Status: Believed complete and correct. * Status: Believed complete and correct.
*/ */
/** /**
* This class models a connectionless datagram socket that sends * This class models a connectionless datagram socket that sends
* individual packets of data across the network. In the TCP/IP world, * individual packets of data across the network. In the TCP/IP world,
...@@ -61,7 +60,6 @@ import java.nio.channels.IllegalBlockingModeException; ...@@ -61,7 +60,6 @@ import java.nio.channels.IllegalBlockingModeException;
* @author Warren Levy (warrenl@cygnus.com) * @author Warren Levy (warrenl@cygnus.com)
* @date May 3, 1999. * @date May 3, 1999.
*/ */
public class DatagramSocket public class DatagramSocket
{ {
/** /**
...@@ -104,7 +102,7 @@ public class DatagramSocket ...@@ -104,7 +102,7 @@ public class DatagramSocket
* *
* @since 1.4 * @since 1.4
*/ */
protected DatagramSocket (DatagramSocketImpl impl) protected DatagramSocket(DatagramSocketImpl impl)
{ {
if (impl == null) if (impl == null)
throw new NullPointerException("impl may not be null"); throw new NullPointerException("impl may not be null");
...@@ -170,7 +168,7 @@ public class DatagramSocket ...@@ -170,7 +168,7 @@ public class DatagramSocket
* *
* @since 1.4 * @since 1.4
*/ */
public DatagramSocket (SocketAddress address) throws SocketException public DatagramSocket(SocketAddress address) throws SocketException
{ {
String propVal = System.getProperty("impl.prefix"); String propVal = System.getProperty("impl.prefix");
if (propVal == null || propVal.equals("")) if (propVal == null || propVal.equals(""))
...@@ -178,13 +176,15 @@ public class DatagramSocket ...@@ -178,13 +176,15 @@ public class DatagramSocket
else else
try try
{ {
impl = (DatagramSocketImpl) Class.forName impl =
("java.net." + propVal + "DatagramSocketImpl").newInstance(); (DatagramSocketImpl) Class.forName("java.net." + propVal
+ "DatagramSocketImpl")
.newInstance();
} }
catch (Exception e) catch (Exception e)
{ {
System.err.println("Could not instantiate class: java.net." + System.err.println("Could not instantiate class: java.net."
propVal + "DatagramSocketImpl"); + propVal + "DatagramSocketImpl");
impl = new PlainDatagramSocketImpl(); impl = new PlainDatagramSocketImpl();
} }
...@@ -193,12 +193,11 @@ public class DatagramSocket ...@@ -193,12 +193,11 @@ public class DatagramSocket
} }
// This needs to be accessible from java.net.MulticastSocket // This needs to be accessible from java.net.MulticastSocket
DatagramSocketImpl getImpl() DatagramSocketImpl getImpl() throws SocketException
throws SocketException
{ {
try try
{ {
if (!implCreated) if (! implCreated)
{ {
impl.create(); impl.create();
implCreated = true; implCreated = true;
...@@ -290,11 +289,12 @@ public class DatagramSocket ...@@ -290,11 +289,12 @@ public class DatagramSocket
try try
{ {
localAddr = (InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR); localAddr =
(InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR);
SecurityManager s = System.getSecurityManager(); SecurityManager s = System.getSecurityManager();
if (s != null) if (s != null)
s.checkConnect (localAddr.getHostName(), -1); s.checkConnect(localAddr.getHostName(), -1);
} }
catch (SecurityException e) catch (SecurityException e)
{ {
...@@ -488,10 +488,10 @@ public class DatagramSocket ...@@ -488,10 +488,10 @@ public class DatagramSocket
public void connect(InetAddress address, int port) public void connect(InetAddress address, int port)
{ {
if (address == null) if (address == null)
throw new IllegalArgumentException ("Connect address may not be null"); throw new IllegalArgumentException("Connect address may not be null");
if ((port < 1) || (port > 65535)) if ((port < 1) || (port > 65535))
throw new IllegalArgumentException ("Port number is illegal: " + port); throw new IllegalArgumentException("Port number is illegal: " + port);
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (sm != null) if (sm != null)
...@@ -499,7 +499,7 @@ public class DatagramSocket ...@@ -499,7 +499,7 @@ public class DatagramSocket
try try
{ {
getImpl().connect (address, port); getImpl().connect(address, port);
remoteAddress = address; remoteAddress = address;
remotePort = port; remotePort = port;
} }
...@@ -518,7 +518,7 @@ public class DatagramSocket ...@@ -518,7 +518,7 @@ public class DatagramSocket
*/ */
public void disconnect() public void disconnect()
{ {
if (!isConnected()) if (! isConnected())
return; return;
try try
...@@ -560,21 +560,19 @@ public class DatagramSocket ...@@ -560,21 +560,19 @@ public class DatagramSocket
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
if (remoteAddress != null if (remoteAddress != null && remoteAddress.isMulticastAddress())
&& remoteAddress.isMulticastAddress())
throw new IOException throw new IOException
("Socket connected to a multicast address my not receive"); ("Socket connected to a multicast address my not receive");
if (getChannel() != null if (getChannel() != null && ! getChannel().isBlocking()
&& !getChannel().isBlocking () && ! ((DatagramChannelImpl) getChannel()).isInChannelOperation())
&& !((DatagramChannelImpl) getChannel()).isInChannelOperation()) throw new IllegalBlockingModeException();
throw new IllegalBlockingModeException ();
getImpl().receive(p); getImpl().receive(p);
SecurityManager s = System.getSecurityManager(); SecurityManager s = System.getSecurityManager();
if (s != null && isConnected ()) if (s != null && isConnected())
s.checkAccept (p.getAddress().getHostName (), p.getPort ()); s.checkAccept(p.getAddress().getHostName(), p.getPort());
} }
/** /**
...@@ -599,7 +597,7 @@ public class DatagramSocket ...@@ -599,7 +597,7 @@ public class DatagramSocket
// JDK1.2: Don't do security checks if socket is connected; see jdk1.2 api. // JDK1.2: Don't do security checks if socket is connected; see jdk1.2 api.
SecurityManager s = System.getSecurityManager(); SecurityManager s = System.getSecurityManager();
if (s != null && !isConnected ()) if (s != null && ! isConnected())
{ {
InetAddress addr = p.getAddress(); InetAddress addr = p.getAddress();
if (addr.isMulticastAddress()) if (addr.isMulticastAddress())
...@@ -608,21 +606,19 @@ public class DatagramSocket ...@@ -608,21 +606,19 @@ public class DatagramSocket
s.checkConnect(addr.getHostAddress(), p.getPort()); s.checkConnect(addr.getHostAddress(), p.getPort());
} }
if (isConnected ()) if (isConnected())
{ {
if (p.getAddress () != null && (remoteAddress != p.getAddress () || if (p.getAddress() != null
remotePort != p.getPort ())) && (remoteAddress != p.getAddress() || remotePort != p.getPort()))
throw new IllegalArgumentException ( throw new IllegalArgumentException
"DatagramPacket address does not match remote address" ); ("DatagramPacket address does not match remote address");
} }
// FIXME: if this is a subclass of MulticastSocket, // FIXME: if this is a subclass of MulticastSocket,
// use getTimeToLive for TTL val. // use getTimeToLive for TTL val.
if (getChannel() != null && ! getChannel().isBlocking()
if (getChannel() != null && ! ((DatagramChannelImpl) getChannel()).isInChannelOperation())
&& !getChannel().isBlocking () throw new IllegalBlockingModeException();
&& !((DatagramChannelImpl) getChannel()).isInChannelOperation())
throw new IllegalBlockingModeException ();
getImpl().send(p); getImpl().send(p);
} }
...@@ -639,8 +635,7 @@ public class DatagramSocket ...@@ -639,8 +635,7 @@ public class DatagramSocket
* *
* @since 1.4 * @since 1.4
*/ */
public void bind (SocketAddress address) public void bind(SocketAddress address) throws SocketException
throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
...@@ -654,7 +649,7 @@ public class DatagramSocket ...@@ -654,7 +649,7 @@ public class DatagramSocket
if (port < 0 || port > 65535) if (port < 0 || port > 65535)
throw new IllegalArgumentException("Invalid port: " + port); throw new IllegalArgumentException("Invalid port: " + port);
SecurityManager s = System.getSecurityManager (); SecurityManager s = System.getSecurityManager();
if (s != null) if (s != null)
s.checkListen(port); s.checkListen(port);
...@@ -717,12 +712,12 @@ public class DatagramSocket ...@@ -717,12 +712,12 @@ public class DatagramSocket
* *
* @since 1.4 * @since 1.4
*/ */
public void connect (SocketAddress address) throws SocketException public void connect(SocketAddress address) throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
if ( !(address instanceof InetSocketAddress) ) if (! (address instanceof InetSocketAddress))
throw new IllegalArgumentException("unsupported address type"); throw new IllegalArgumentException("unsupported address type");
InetSocketAddress tmp = (InetSocketAddress) address; InetSocketAddress tmp = (InetSocketAddress) address;
...@@ -763,10 +758,10 @@ public class DatagramSocket ...@@ -763,10 +758,10 @@ public class DatagramSocket
*/ */
public SocketAddress getRemoteSocketAddress() public SocketAddress getRemoteSocketAddress()
{ {
if (!isConnected ()) if (! isConnected())
return null; return null;
return new InetSocketAddress (remoteAddress, remotePort); return new InetSocketAddress(remoteAddress, remotePort);
} }
/** /**
...@@ -778,10 +773,10 @@ public class DatagramSocket ...@@ -778,10 +773,10 @@ public class DatagramSocket
*/ */
public SocketAddress getLocalSocketAddress() public SocketAddress getLocalSocketAddress()
{ {
if (!isBound()) if (! isBound())
return null; return null;
return new InetSocketAddress (getLocalAddress(), getLocalPort()); return new InetSocketAddress(getLocalAddress(), getLocalPort());
} }
/** /**
...@@ -798,7 +793,7 @@ public class DatagramSocket ...@@ -798,7 +793,7 @@ public class DatagramSocket
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
getImpl().setOption (SocketOptions.SO_REUSEADDR, Boolean.valueOf(on)); getImpl().setOption(SocketOptions.SO_REUSEADDR, Boolean.valueOf(on));
} }
/** /**
...@@ -815,7 +810,7 @@ public class DatagramSocket ...@@ -815,7 +810,7 @@ public class DatagramSocket
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
Object buf = getImpl().getOption (SocketOptions.SO_REUSEADDR); Object buf = getImpl().getOption(SocketOptions.SO_REUSEADDR);
if (buf instanceof Boolean) if (buf instanceof Boolean)
return ((Boolean) buf).booleanValue(); return ((Boolean) buf).booleanValue();
...@@ -874,8 +869,7 @@ public class DatagramSocket ...@@ -874,8 +869,7 @@ public class DatagramSocket
* *
* @since 1.4 * @since 1.4
*/ */
public void setTrafficClass(int tc) public void setTrafficClass(int tc) throws SocketException
throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
...@@ -883,7 +877,7 @@ public class DatagramSocket ...@@ -883,7 +877,7 @@ public class DatagramSocket
if (tc < 0 || tc > 255) if (tc < 0 || tc > 255)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
getImpl().setOption (SocketOptions.IP_TOS, new Integer (tc)); getImpl().setOption(SocketOptions.IP_TOS, new Integer(tc));
} }
/** /**
...@@ -920,11 +914,11 @@ public class DatagramSocket ...@@ -920,11 +914,11 @@ public class DatagramSocket
* @exception SecurityException If a security manager exists and its * @exception SecurityException If a security manager exists and its
* checkSetFactory method doesn't allow the operation * checkSetFactory method doesn't allow the operation
*/ */
public static void setDatagramSocketImplFactory public static void setDatagramSocketImplFactory(DatagramSocketImplFactory fac)
(DatagramSocketImplFactory fac) throws IOException throws IOException
{ {
if (factory != null) if (factory != null)
throw new SocketException ("DatagramSocketImplFactory already defined"); throw new SocketException("DatagramSocketImplFactory already defined");
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (sm != null) if (sm != null)
......
...@@ -36,11 +36,11 @@ this exception to your version of the library, but you are not ...@@ -36,11 +36,11 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
import java.io.IOException;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.IOException;
/** /**
* This abstract class models a datagram socket implementation. An * This abstract class models a datagram socket implementation. An
...@@ -58,7 +58,6 @@ import java.io.FileDescriptor; ...@@ -58,7 +58,6 @@ import java.io.FileDescriptor;
*/ */
public abstract class DatagramSocketImpl implements SocketOptions public abstract class DatagramSocketImpl implements SocketOptions
{ {
/** /**
* The local port to which this socket is bound * The local port to which this socket is bound
*/ */
...@@ -130,7 +129,7 @@ public abstract class DatagramSocketImpl implements SocketOptions ...@@ -130,7 +129,7 @@ public abstract class DatagramSocketImpl implements SocketOptions
* *
* @since 1.4 * @since 1.4
*/ */
protected abstract int peekData (DatagramPacket p) throws IOException; protected abstract int peekData(DatagramPacket p) throws IOException;
/** /**
* Transmits the specified packet of data to the network. The destination * Transmits the specified packet of data to the network. The destination
...@@ -169,7 +168,8 @@ public abstract class DatagramSocketImpl implements SocketOptions ...@@ -169,7 +168,8 @@ public abstract class DatagramSocketImpl implements SocketOptions
* *
* @since 1.4 * @since 1.4
*/ */
protected void connect (InetAddress address, int port) throws SocketException protected void connect(InetAddress address, int port)
throws SocketException
{ {
// This method has to be overwritten by real implementations // This method has to be overwritten by real implementations
} }
...@@ -179,7 +179,7 @@ public abstract class DatagramSocketImpl implements SocketOptions ...@@ -179,7 +179,7 @@ public abstract class DatagramSocketImpl implements SocketOptions
* *
* @since 1.4 * @since 1.4
*/ */
protected void disconnect () protected void disconnect()
{ {
// This method has to be overwritten by real implementations // This method has to be overwritten by real implementations
} }
...@@ -199,8 +199,11 @@ public abstract class DatagramSocketImpl implements SocketOptions ...@@ -199,8 +199,11 @@ public abstract class DatagramSocketImpl implements SocketOptions
* This method returns the current Time to Live (TTL) setting on this * This method returns the current Time to Live (TTL) setting on this
* socket. <b>Use <code>getTimeToLive()</code></b> instead. * socket. <b>Use <code>getTimeToLive()</code></b> instead.
* *
* @return the current time-to-live
*
* @exception IOException If an error occurs * @exception IOException If an error occurs
* @deprecated *
* @deprecated // FIXME: when ?
*/ */
protected abstract byte getTTL() throws IOException; protected abstract byte getTTL() throws IOException;
...@@ -218,6 +221,8 @@ public abstract class DatagramSocketImpl implements SocketOptions ...@@ -218,6 +221,8 @@ public abstract class DatagramSocketImpl implements SocketOptions
* This method returns the current Time to Live (TTL) setting on this * This method returns the current Time to Live (TTL) setting on this
* socket. * socket.
* *
* @return the current time-to-live
*
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
protected abstract int getTimeToLive() throws IOException; protected abstract int getTimeToLive() throws IOException;
...@@ -251,7 +256,7 @@ public abstract class DatagramSocketImpl implements SocketOptions ...@@ -251,7 +256,7 @@ public abstract class DatagramSocketImpl implements SocketOptions
* *
* @since 1.4 * @since 1.4
*/ */
protected abstract void joinGroup (SocketAddress mcastaddr, protected abstract void joinGroup(SocketAddress mcastaddr,
NetworkInterface netIf) NetworkInterface netIf)
throws IOException; throws IOException;
...@@ -265,12 +270,14 @@ public abstract class DatagramSocketImpl implements SocketOptions ...@@ -265,12 +270,14 @@ public abstract class DatagramSocketImpl implements SocketOptions
* *
* @since 1.4 * @since 1.4
*/ */
protected abstract void leaveGroup (SocketAddress mcastaddr, protected abstract void leaveGroup(SocketAddress mcastaddr,
NetworkInterface netIf) NetworkInterface netIf)
throws IOException; throws IOException;
/** /**
* Returns the FileDescriptor for this socket * Returns the FileDescriptor for this socket
*
* @return the file descriptor associated with this socket
*/ */
protected FileDescriptor getFileDescriptor() protected FileDescriptor getFileDescriptor()
{ {
...@@ -279,6 +286,8 @@ public abstract class DatagramSocketImpl implements SocketOptions ...@@ -279,6 +286,8 @@ public abstract class DatagramSocketImpl implements SocketOptions
/** /**
* Returns the local port this socket is bound to * Returns the local port this socket is bound to
*
* @return the local port
*/ */
protected int getLocalPort() protected int getLocalPort()
{ {
......
...@@ -37,10 +37,10 @@ exception statement from your version. */ ...@@ -37,10 +37,10 @@ exception statement from your version. */
package java.net; package java.net;
/** Written using on-line Java Platform 1.4 API Specification. /** Written using on-line Java Platform 1.4 API Specification.
* Status: Believed complete and correct. * Status: Believed complete and correct.
*/ */
/** /**
* This interface defines one method which returns a * This interface defines one method which returns a
* <code>DatagramSocketImpl</code> object. * <code>DatagramSocketImpl</code> object.
...@@ -57,5 +57,4 @@ public interface DatagramSocketImplFactory ...@@ -57,5 +57,4 @@ public interface DatagramSocketImplFactory
* @return A DatagramSocketImpl object * @return A DatagramSocketImpl object
*/ */
DatagramSocketImpl createDatagramSocketImpl(); DatagramSocketImpl createDatagramSocketImpl();
} // interface DatagramSocketImplFactory } // interface DatagramSocketImplFactory
...@@ -35,15 +35,14 @@ this exception to your version of the library, but you are not ...@@ -35,15 +35,14 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
/** /**
* Written using on-line Java Platform 1.2 API Specification, as well * Written using on-line Java Platform 1.2 API Specification, as well
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
* Status: Believed complete and correct. * Status: Believed complete and correct.
*/ */
/** /**
* This interface has one method which, when passed a filename, returns * This interface has one method which, when passed a filename, returns
* the MIME type associated with that filename. * the MIME type associated with that filename.
...@@ -63,6 +62,4 @@ public interface FileNameMap ...@@ -63,6 +62,4 @@ public interface FileNameMap
* @return The MIME type for the filename passed in. * @return The MIME type for the filename passed in.
*/ */
String getContentTypeFor(String filename); String getContentTypeFor(String filename);
} // interface FileNameMap } // interface FileNameMap
...@@ -36,14 +36,14 @@ this exception to your version of the library, but you are not ...@@ -36,14 +36,14 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream; import java.io.PushbackInputStream;
import java.security.Permission; import java.security.Permission;
/* /*
* Written using on-line Java Platform 1.2 API Specification, as well * Written using on-line Java Platform 1.2 API Specification, as well
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
...@@ -116,7 +116,6 @@ public abstract class HttpURLConnection extends URLConnection ...@@ -116,7 +116,6 @@ public abstract class HttpURLConnection extends URLConnection
*/ */
public static final int HTTP_PARTIAL = 206; public static final int HTTP_PARTIAL = 206;
/* HTTP Redirection Response Codes */ /* HTTP Redirection Response Codes */
/** /**
...@@ -150,7 +149,6 @@ public abstract class HttpURLConnection extends URLConnection ...@@ -150,7 +149,6 @@ public abstract class HttpURLConnection extends URLConnection
*/ */
public static final int HTTP_USE_PROXY = 305; public static final int HTTP_USE_PROXY = 305;
/* HTTP Client Error Response Codes */ /* HTTP Client Error Response Codes */
/** /**
...@@ -239,7 +237,6 @@ public abstract class HttpURLConnection extends URLConnection ...@@ -239,7 +237,6 @@ public abstract class HttpURLConnection extends URLConnection
*/ */
public static final int HTTP_UNSUPPORTED_TYPE = 415; public static final int HTTP_UNSUPPORTED_TYPE = 415;
/* HTTP Server Error Response Codes */ /* HTTP Server Error Response Codes */
/** /**
...@@ -294,8 +291,8 @@ public abstract class HttpURLConnection extends URLConnection ...@@ -294,8 +291,8 @@ public abstract class HttpURLConnection extends URLConnection
/** /**
* This is a list of valid request methods, separated by "|" characters. * This is a list of valid request methods, separated by "|" characters.
*/ */
private static String valid_methods private static String valid_methods =
= "|GET|POST|HEAD|OPTIONS|PUT|DELETE|TRACE|"; "|GET|POST|HEAD|OPTIONS|PUT|DELETE|TRACE|";
// Instance Variables // Instance Variables
...@@ -312,7 +309,7 @@ public abstract class HttpURLConnection extends URLConnection ...@@ -312,7 +309,7 @@ public abstract class HttpURLConnection extends URLConnection
/** /**
* The response message string received from the server. * The response message string received from the server.
*/ */
protected String responseMessage = null; protected String responseMessage;
/** /**
* If this instance should follow redirect requests. * If this instance should follow redirect requests.
...@@ -324,7 +321,7 @@ public abstract class HttpURLConnection extends URLConnection ...@@ -324,7 +321,7 @@ public abstract class HttpURLConnection extends URLConnection
* Used by <code>getResponseCode()</code> and * Used by <code>getResponseCode()</code> and
* <code>getResponseMessage()</code>. * <code>getResponseMessage()</code>.
*/ */
private boolean gotResponseVals = false; private boolean gotResponseVals;
/** /**
* Create an HttpURLConnection for the specified URL * Create an HttpURLConnection for the specified URL
...@@ -383,16 +380,20 @@ public abstract class HttpURLConnection extends URLConnection ...@@ -383,16 +380,20 @@ public abstract class HttpURLConnection extends URLConnection
/** /**
* Returns the value of this HttpURLConnection's instanceFollowRedirects * Returns the value of this HttpURLConnection's instanceFollowRedirects
* field * field
*
* @return true if following redirects is enabled, false otherwise
*/ */
public boolean getInstanceFollowRedirects () public boolean getInstanceFollowRedirects()
{ {
return instanceFollowRedirects; return instanceFollowRedirects;
} }
/** /**
* Sets the value of this HttpURLConnection's instanceFollowRedirects field * Sets the value of this HttpURLConnection's instanceFollowRedirects field
*
* @param follow true to enable following redirects, false otherwise
*/ */
public void setInstanceFollowRedirects (boolean follow) public void setInstanceFollowRedirects(boolean follow)
{ {
instanceFollowRedirects = follow; instanceFollowRedirects = follow;
} }
...@@ -401,6 +402,8 @@ public abstract class HttpURLConnection extends URLConnection ...@@ -401,6 +402,8 @@ public abstract class HttpURLConnection extends URLConnection
* Set the method for the URL request, one of: * Set the method for the URL request, one of:
* GET POST HEAD OPTIONS PUT DELETE TRACE are legal * GET POST HEAD OPTIONS PUT DELETE TRACE are legal
* *
* @param method the method to use
*
* @exception ProtocolException If the method cannot be reset or if the * @exception ProtocolException If the method cannot be reset or if the
* requested method isn't valid for HTTP * requested method isn't valid for HTTP
*/ */
...@@ -414,7 +417,6 @@ public abstract class HttpURLConnection extends URLConnection ...@@ -414,7 +417,6 @@ public abstract class HttpURLConnection extends URLConnection
this.method = method; this.method = method;
else else
throw new ProtocolException("Invalid HTTP request method: " + method); throw new ProtocolException("Invalid HTTP request method: " + method);
} }
/** /**
...@@ -439,7 +441,7 @@ public abstract class HttpURLConnection extends URLConnection ...@@ -439,7 +441,7 @@ public abstract class HttpURLConnection extends URLConnection
*/ */
public int getResponseCode() throws IOException public int getResponseCode() throws IOException
{ {
if (!gotResponseVals) if (! gotResponseVals)
getResponseVals(); getResponseVals();
return responseCode; return responseCode;
} }
...@@ -455,7 +457,7 @@ public abstract class HttpURLConnection extends URLConnection ...@@ -455,7 +457,7 @@ public abstract class HttpURLConnection extends URLConnection
*/ */
public String getResponseMessage() throws IOException public String getResponseMessage() throws IOException
{ {
if (!gotResponseVals) if (! gotResponseVals)
getResponseVals(); getResponseVals();
return responseMessage; return responseMessage;
} }
...@@ -464,7 +466,7 @@ public abstract class HttpURLConnection extends URLConnection ...@@ -464,7 +466,7 @@ public abstract class HttpURLConnection extends URLConnection
{ {
// getHeaderField() will connect for us, but do it here first in // getHeaderField() will connect for us, but do it here first in
// order to pick up IOExceptions. // order to pick up IOExceptions.
if (!connected) if (! connected)
connect(); connect();
gotResponseVals = true; gotResponseVals = true;
...@@ -483,7 +485,8 @@ public abstract class HttpURLConnection extends URLConnection ...@@ -483,7 +485,8 @@ public abstract class HttpURLConnection extends URLConnection
return; return;
} }
int firstSpc, nextSpc; int firstSpc;
int nextSpc;
firstSpc = respField.indexOf(' '); firstSpc = respField.indexOf(' ');
nextSpc = respField.indexOf(' ', firstSpc + 1); nextSpc = respField.indexOf(' ', firstSpc + 1);
responseMessage = respField.substring(nextSpc + 1); responseMessage = respField.substring(nextSpc + 1);
...@@ -505,6 +508,8 @@ public abstract class HttpURLConnection extends URLConnection ...@@ -505,6 +508,8 @@ public abstract class HttpURLConnection extends URLConnection
* Returns a permission object representing the permission necessary to make * Returns a permission object representing the permission necessary to make
* the connection represented by this object * the connection represented by this object
* *
* @return the permission necessary for this connection
*
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public Permission getPermission() throws IOException public Permission getPermission() throws IOException
...@@ -529,26 +534,26 @@ public abstract class HttpURLConnection extends URLConnection ...@@ -529,26 +534,26 @@ public abstract class HttpURLConnection extends URLConnection
* *
* @return An <code>InputStream</code> for reading error data. * @return An <code>InputStream</code> for reading error data.
*/ */
public InputStream getErrorStream () public InputStream getErrorStream()
{ {
if (!connected) if (! connected)
return(null); return (null);
int code; int code;
try try
{ {
code = getResponseCode(); code = getResponseCode();
} }
catch(IOException e) catch (IOException e)
{ {
code = -1; code = -1;
} }
if (code == -1) if (code == -1)
return(null); return (null);
if (((code/100) != 4) || ((code/100) != 5)) if (((code / 100) != 4) || ((code / 100) != 5))
return(null); return (null);
try try
{ {
...@@ -556,25 +561,29 @@ public abstract class HttpURLConnection extends URLConnection ...@@ -556,25 +561,29 @@ public abstract class HttpURLConnection extends URLConnection
int i = pbis.read(); int i = pbis.read();
if (i == -1) if (i == -1)
return(null); return (null);
pbis.unread(i); pbis.unread(i);
return(pbis); return (pbis);
} }
catch(IOException e) catch (IOException e)
{ {
return(null); return (null);
} }
} }
/** /**
* Returns the value of the named field parsed as date * Returns the value of the named field parsed as date
*
* @param key the key of the header field
* @param value the default value if the header field is not present
*
* @return the value of the header field
*/ */
public long getHeaderFieldDate (String key, long value) public long getHeaderFieldDate(String key, long value)
{ {
// FIXME: implement this correctly // FIXME: implement this correctly
// http://www.w3.org/Protocols/HTTP-NG/ng-notes.txt // http://www.w3.org/Protocols/HTTP-NG/ng-notes.txt
return super.getHeaderFieldDate(key, value);
return super.getHeaderFieldDate (key, value);
} }
} }
...@@ -35,12 +35,12 @@ this exception to your version of the library, but you are not ...@@ -35,12 +35,12 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.util.Arrays; import java.util.Arrays;
/** /**
* @author Michael Koch * @author Michael Koch
* @date August 3, 2002. * @date August 3, 2002.
...@@ -53,7 +53,6 @@ import java.util.Arrays; ...@@ -53,7 +53,6 @@ import java.util.Arrays;
* RFC 2365 (http://www.ietf.org/rfc/rfc2365.txt) * RFC 2365 (http://www.ietf.org/rfc/rfc2365.txt)
* Status: Believed complete and correct. * Status: Believed complete and correct.
*/ */
public final class Inet4Address extends InetAddress public final class Inet4Address extends InetAddress
{ {
static final long serialVersionUID = 3286316764910316507L; static final long serialVersionUID = 3286316764910316507L;
...@@ -61,9 +60,9 @@ public final class Inet4Address extends InetAddress ...@@ -61,9 +60,9 @@ public final class Inet4Address extends InetAddress
/** /**
* needed for serialization * needed for serialization
*/ */
private Object writeReplace () throws ObjectStreamException private Object writeReplace() throws ObjectStreamException
{ {
return new InetAddress (addr, hostName); return new InetAddress(addr, hostName);
} }
/** /**
...@@ -74,7 +73,7 @@ public final class Inet4Address extends InetAddress ...@@ -74,7 +73,7 @@ public final class Inet4Address extends InetAddress
*/ */
Inet4Address(byte[] addr, String host) Inet4Address(byte[] addr, String host)
{ {
super (addr, host); super(addr, host);
} }
/** /**
...@@ -82,17 +81,17 @@ public final class Inet4Address extends InetAddress ...@@ -82,17 +81,17 @@ public final class Inet4Address extends InetAddress
* *
* @since 1.1 * @since 1.1
*/ */
public boolean isMulticastAddress () public boolean isMulticastAddress()
{ {
return (addr [0] & 0xF0) == 0xE0; return (addr[0] & 0xF0) == 0xE0;
} }
/** /**
* Checks if this address is a loopback address * Checks if this address is a loopback address
*/ */
public boolean isLoopbackAddress () public boolean isLoopbackAddress()
{ {
return addr [0] == 0x7F; return addr[0] == 0x7F;
} }
/** /**
...@@ -100,7 +99,7 @@ public final class Inet4Address extends InetAddress ...@@ -100,7 +99,7 @@ public final class Inet4Address extends InetAddress
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isAnyLocalAddress () public boolean isAnyLocalAddress()
{ {
byte[] anylocal = { 0, 0, 0, 0 }; byte[] anylocal = { 0, 0, 0, 0 };
...@@ -112,7 +111,7 @@ public final class Inet4Address extends InetAddress ...@@ -112,7 +111,7 @@ public final class Inet4Address extends InetAddress
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isLinkLocalAddress () public boolean isLinkLocalAddress()
{ {
// XXX: This seems to not exist with IPv4 addresses // XXX: This seems to not exist with IPv4 addresses
return false; return false;
...@@ -123,21 +122,21 @@ public final class Inet4Address extends InetAddress ...@@ -123,21 +122,21 @@ public final class Inet4Address extends InetAddress
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isSiteLocalAddress () public boolean isSiteLocalAddress()
{ {
// 10.0.0.0/8 // 10.0.0.0/8
if (addr [0] == 0x0A) if (addr[0] == 0x0A)
return true; return true;
// XXX: Suns JDK 1.4.1 (on Linux) seems to have a bug here: // XXX: Suns JDK 1.4.1 (on Linux) seems to have a bug here:
// 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 ?
...@@ -149,7 +148,7 @@ public final class Inet4Address extends InetAddress ...@@ -149,7 +148,7 @@ public final class Inet4Address extends InetAddress
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isMCGlobal () public boolean isMCGlobal()
{ {
// XXX: This seems to net exist with IPv4 addresses // XXX: This seems to net exist with IPv4 addresses
return false; return false;
...@@ -160,7 +159,7 @@ public final class Inet4Address extends InetAddress ...@@ -160,7 +159,7 @@ public final class Inet4Address extends InetAddress
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isMCNodeLocal () public boolean isMCNodeLocal()
{ {
// XXX: This seems to net exist with IPv4 addresses // XXX: This seems to net exist with IPv4 addresses
return false; return false;
...@@ -171,14 +170,12 @@ public final class Inet4Address extends InetAddress ...@@ -171,14 +170,12 @@ public final class Inet4Address extends InetAddress
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isMCLinkLocal () public boolean isMCLinkLocal()
{ {
if (!isMulticastAddress ()) if (! isMulticastAddress())
return false; return false;
return (addr [0] == 0xE0) return (addr[0] == 0xE0) && (addr[1] == 0x00) && (addr[2] == 0x00);
&& (addr [1] == 0x00)
&& (addr [2] == 0x00);
} }
/** /**
...@@ -186,7 +183,7 @@ public final class Inet4Address extends InetAddress ...@@ -186,7 +183,7 @@ public final class Inet4Address extends InetAddress
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isMCSiteLocal () public boolean isMCSiteLocal()
{ {
// XXX: This seems to net exist with IPv4 addresses // XXX: This seems to net exist with IPv4 addresses
return false; return false;
...@@ -197,7 +194,7 @@ public final class Inet4Address extends InetAddress ...@@ -197,7 +194,7 @@ public final class Inet4Address extends InetAddress
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isMCOrgLocal () public boolean isMCOrgLocal()
{ {
// XXX: This seems to net exist with IPv4 addresses // XXX: This seems to net exist with IPv4 addresses
return false; return false;
...@@ -206,7 +203,7 @@ public final class Inet4Address extends InetAddress ...@@ -206,7 +203,7 @@ public final class Inet4Address extends InetAddress
/** /**
* Returns the address of the current instance * Returns the address of the current instance
*/ */
public byte[] getAddress () public byte[] getAddress()
{ {
return addr; return addr;
} }
...@@ -216,37 +213,37 @@ public final class Inet4Address extends InetAddress ...@@ -216,37 +213,37 @@ public final class Inet4Address extends InetAddress
* *
* @since 1.0.2 * @since 1.0.2
*/ */
public String getHostAddress () public String getHostAddress()
{ {
StringBuffer sbuf = new StringBuffer (40); StringBuffer sbuf = new StringBuffer(40);
int len = addr.length; int len = addr.length;
int i = 0; int i = 0;
for ( ; ; ) for (;;)
{ {
sbuf.append (addr [i] & 0xFF); sbuf.append(addr[i] & 0xFF);
i++; i++;
if (i == len) if (i == len)
break; break;
sbuf.append ('.'); sbuf.append('.');
} }
return sbuf.toString (); return sbuf.toString();
} }
/** /**
* Computes the hashcode of the instance * Computes the hashcode of the instance
*/ */
public int hashCode () public int hashCode()
{ {
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;
} }
...@@ -256,7 +253,7 @@ public final class Inet4Address extends InetAddress ...@@ -256,7 +253,7 @@ public final class Inet4Address extends InetAddress
* *
* @param obj Object to compare with * @param obj Object to compare with
*/ */
public boolean equals (Object obj) public boolean equals(Object obj)
{ {
if (! (obj instanceof InetAddress)) if (! (obj instanceof InetAddress))
return false; return false;
...@@ -267,8 +264,8 @@ public final class Inet4Address extends InetAddress ...@@ -267,8 +264,8 @@ public final class Inet4Address extends InetAddress
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;
......
...@@ -35,11 +35,11 @@ this exception to your version of the library, but you are not ...@@ -35,11 +35,11 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
import java.util.Arrays; import java.util.Arrays;
/** /**
* @author Michael Koch * @author Michael Koch
* @date August 3, 2002. * @date August 3, 2002.
...@@ -50,7 +50,6 @@ import java.util.Arrays; ...@@ -50,7 +50,6 @@ import java.util.Arrays;
* RFC 1884 (http://www.ietf.org/rfc/rfc1884.txt) * RFC 1884 (http://www.ietf.org/rfc/rfc1884.txt)
* Status: Believed complete and correct. * Status: Believed complete and correct.
*/ */
public final class Inet6Address extends InetAddress public final class Inet6Address extends InetAddress
{ {
static final long serialVersionUID = 6880410070516793377L; static final long serialVersionUID = 6880410070516793377L;
...@@ -66,9 +65,9 @@ public final class Inet6Address extends InetAddress ...@@ -66,9 +65,9 @@ public final class Inet6Address extends InetAddress
* @param addr The IP address * @param addr The IP address
* @param host The hostname * @param host The hostname
*/ */
Inet6Address (byte[] addr, String host) Inet6Address(byte[] addr, String host)
{ {
super (addr, host); super(addr, host);
this.ipaddress = addr; this.ipaddress = addr;
} }
...@@ -77,9 +76,9 @@ public final class Inet6Address extends InetAddress ...@@ -77,9 +76,9 @@ public final class Inet6Address extends InetAddress
* *
* @since 1.1 * @since 1.1
*/ */
public boolean isMulticastAddress () public boolean isMulticastAddress()
{ {
return ipaddress [0] == 0xFF; return ipaddress[0] == 0xFF;
} }
/** /**
...@@ -87,10 +86,9 @@ public final class Inet6Address extends InetAddress ...@@ -87,10 +86,9 @@ public final class Inet6Address extends InetAddress
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isAnyLocalAddress () public boolean isAnyLocalAddress()
{ {
byte[] anylocal = { 0, 0, 0, 0, 0, 0, 0, 0, byte[] anylocal = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
0, 0, 0, 0, 0, 0, 0, 0 };
return Arrays.equals(ipaddress, anylocal); return Arrays.equals(ipaddress, anylocal);
} }
...@@ -100,10 +98,9 @@ public final class Inet6Address extends InetAddress ...@@ -100,10 +98,9 @@ public final class Inet6Address extends InetAddress
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isLoopbackAddress () public boolean isLoopbackAddress()
{ {
byte[] loopback = { 0, 0, 0, 0, 0, 0, 0, 0, byte[] loopback = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
0, 0, 0, 0, 0, 0, 0, 1 };
return Arrays.equals(ipaddress, loopback); return Arrays.equals(ipaddress, loopback);
} }
...@@ -113,9 +110,9 @@ public final class Inet6Address extends InetAddress ...@@ -113,9 +110,9 @@ public final class Inet6Address extends InetAddress
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isLinkLocalAddress () public boolean isLinkLocalAddress()
{ {
return ipaddress [0] == 0xFA; return ipaddress[0] == 0xFA;
} }
/** /**
...@@ -123,9 +120,9 @@ public final class Inet6Address extends InetAddress ...@@ -123,9 +120,9 @@ public final class Inet6Address extends InetAddress
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isSiteLocalAddress () public boolean isSiteLocalAddress()
{ {
return ipaddress [0] == 0xFB; return ipaddress[0] == 0xFB;
} }
/** /**
...@@ -133,12 +130,12 @@ public final class Inet6Address extends InetAddress ...@@ -133,12 +130,12 @@ public final class Inet6Address extends InetAddress
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isMCGlobal () public boolean isMCGlobal()
{ {
if (!isMulticastAddress ()) if (! isMulticastAddress())
return false; return false;
return (ipaddress [1] & 0x0F) == 0xE; return (ipaddress[1] & 0x0F) == 0xE;
} }
/** /**
...@@ -146,12 +143,12 @@ public final class Inet6Address extends InetAddress ...@@ -146,12 +143,12 @@ public final class Inet6Address extends InetAddress
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isMCNodeLocal () public boolean isMCNodeLocal()
{ {
if (!isMulticastAddress ()) if (! isMulticastAddress())
return false; return false;
return (ipaddress [1] & 0x0F) == 0x1; return (ipaddress[1] & 0x0F) == 0x1;
} }
/** /**
...@@ -159,12 +156,12 @@ public final class Inet6Address extends InetAddress ...@@ -159,12 +156,12 @@ public final class Inet6Address extends InetAddress
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isMCLinkLocal () public boolean isMCLinkLocal()
{ {
if (!isMulticastAddress ()) if (! isMulticastAddress())
return false; return false;
return (ipaddress [1] & 0x0F) == 0x2; return (ipaddress[1] & 0x0F) == 0x2;
} }
/** /**
...@@ -172,12 +169,12 @@ public final class Inet6Address extends InetAddress ...@@ -172,12 +169,12 @@ public final class Inet6Address extends InetAddress
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isMCSiteLocal () public boolean isMCSiteLocal()
{ {
if (!isMulticastAddress ()) if (! isMulticastAddress())
return false; return false;
return (ipaddress [1] & 0x0F) == 0x5; return (ipaddress[1] & 0x0F) == 0x5;
} }
/** /**
...@@ -185,12 +182,12 @@ public final class Inet6Address extends InetAddress ...@@ -185,12 +182,12 @@ public final class Inet6Address extends InetAddress
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isMCOrgLocal () public boolean isMCOrgLocal()
{ {
if (!isMulticastAddress ()) if (! isMulticastAddress())
return false; return false;
return (ipaddress [1] & 0x0F) == 0x8; return (ipaddress[1] & 0x0F) == 0x8;
} }
/** /**
...@@ -198,7 +195,7 @@ public final class Inet6Address extends InetAddress ...@@ -198,7 +195,7 @@ public final class Inet6Address extends InetAddress
* network byte order: the highest order byte of the address is i * network byte order: the highest order byte of the address is i
* n getAddress()[0] * n getAddress()[0]
*/ */
public byte[] getAddress () public byte[] getAddress()
{ {
return ipaddress; return ipaddress;
} }
...@@ -206,50 +203,49 @@ public final class Inet6Address extends InetAddress ...@@ -206,50 +203,49 @@ public final class Inet6Address extends InetAddress
/** /**
* Returns the IP address string in textual presentation * Returns the IP address string in textual presentation
*/ */
public String getHostAddress () public String getHostAddress()
{ {
StringBuffer sbuf = new StringBuffer (40); StringBuffer sbuf = new StringBuffer(40);
for (int i = 0; i < 16; i += 2) for (int i = 0; i < 16; i += 2)
{ {
int x = ((ipaddress [i] & 0xFF) << 8) | (ipaddress [i + 1] & 0xFF); int x = ((ipaddress[i] & 0xFF) << 8) | (ipaddress[i + 1] & 0xFF);
boolean empty = sbuf.length () == 0; boolean empty = sbuf.length() == 0;
if (empty) if (empty)
{ {
if (i > 0) if (i > 0)
sbuf.append ("::"); sbuf.append("::");
} }
else else
sbuf.append (':'); sbuf.append(':');
if (x != 0 || i >= 14) if (x != 0 || i >= 14)
sbuf.append (Integer.toHexString (x)); sbuf.append(Integer.toHexString(x));
} }
return sbuf.toString (); return sbuf.toString();
} }
/** /**
* Returns a hashcode for this IP address * Returns a hashcode for this IP address
*/ */
public int hashCode () public int hashCode()
{ {
return super.hashCode (); return super.hashCode();
} }
/** /**
* Compares this object against the specified object * Compares this object against the specified object
*/ */
public boolean equals (Object obj) public boolean equals(Object obj)
{ {
if (! (obj instanceof Inet6Address)) if (! (obj instanceof Inet6Address))
return false; return false;
Inet6Address tmp = (Inet6Address) obj; Inet6Address tmp = (Inet6Address) obj;
return super.equals (tmp) return super.equals(tmp) && this.ipaddress == tmp.ipaddress;
&& this.ipaddress == tmp.ipaddress;
} }
/** /**
...@@ -258,14 +254,14 @@ public final class Inet6Address extends InetAddress ...@@ -258,14 +254,14 @@ public final class Inet6Address extends InetAddress
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isIPv4CompatibleAddress () public boolean isIPv4CompatibleAddress()
{ {
if (ipaddress [0] != 0x00 || ipaddress [1] != 0x00 || if (ipaddress[0] != 0x00 || ipaddress[1] != 0x00 || ipaddress[2] != 0x00
ipaddress [2] != 0x00 || ipaddress [3] != 0x00 || || ipaddress[3] != 0x00 || ipaddress[4] != 0x00
ipaddress [4] != 0x00 || ipaddress [5] != 0x00 || || ipaddress[5] != 0x00 || ipaddress[6] != 0x00
ipaddress [6] != 0x00 || ipaddress [7] != 0x00 || || ipaddress[7] != 0x00 || ipaddress[8] != 0x00
ipaddress [8] != 0x00 || ipaddress [9] != 0x00 || || ipaddress[9] != 0x00 || ipaddress[10] != 0x00
ipaddress [10] != 0x00 || ipaddress [11] != 0x00) || ipaddress[11] != 0x00)
return false; return false;
return true; return true;
......
...@@ -35,7 +35,6 @@ this exception to your version of the library, but you are not ...@@ -35,7 +35,6 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
import gnu.classpath.Configuration; import gnu.classpath.Configuration;
...@@ -118,7 +117,7 @@ public class InetAddress implements Serializable ...@@ -118,7 +117,7 @@ public class InetAddress implements Serializable
* *
* @param ipaddr The IP number of this address as an array of bytes * @param ipaddr The IP number of this address as an array of bytes
*/ */
InetAddress (byte[] address) InetAddress(byte[] address)
{ {
this (address, null); this (address, null);
} }
...@@ -131,7 +130,7 @@ public class InetAddress implements Serializable ...@@ -131,7 +130,7 @@ public class InetAddress implements Serializable
* @param ipaddr The IP number of this address as an array of bytes * @param ipaddr The IP number of this address as an array of bytes
* @param hostname The hostname of this IP address. * @param hostname The hostname of this IP address.
*/ */
InetAddress (byte[] address, String hostname) InetAddress(byte[] address, String hostname)
{ {
addr = address; addr = address;
hostName = hostname; hostName = hostname;
...@@ -153,7 +152,7 @@ public class InetAddress implements Serializable ...@@ -153,7 +152,7 @@ public class InetAddress implements Serializable
{ {
// Mask against high order bits of 1110 // Mask against high order bits of 1110
if (addr.length == 4) if (addr.length == 4)
return (addr [0] & 0xF0) == 0xE0; return (addr[0] & 0xF0) == 0xE0;
// Mask against high order bits of 11111111 // Mask against high order bits of 11111111
if (addr.length == 16) if (addr.length == 16)
...@@ -171,7 +170,7 @@ public class InetAddress implements Serializable ...@@ -171,7 +170,7 @@ public class InetAddress implements Serializable
{ {
// 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.
return equals (ANY_IF); return equals(ANY_IF);
} }
/** /**
...@@ -183,8 +182,7 @@ public class InetAddress implements Serializable ...@@ -183,8 +182,7 @@ public class InetAddress implements Serializable
{ {
// 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.
return addr[0] == 0x7F;
return addr [0] == 0x7F;
} }
/** /**
...@@ -196,7 +194,6 @@ public class InetAddress implements Serializable ...@@ -196,7 +194,6 @@ public class InetAddress implements Serializable
{ {
// 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.
// XXX: This seems to not exist with IPv4 addresses // XXX: This seems to not exist with IPv4 addresses
return false; return false;
} }
...@@ -210,22 +207,18 @@ public class InetAddress implements Serializable ...@@ -210,22 +207,18 @@ public class InetAddress implements Serializable
{ {
// 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.
// 10.0.0.0/8 // 10.0.0.0/8
if (addr [0] == 0x0A) if (addr[0] == 0x0A)
return true; return true;
// XXX: Suns JDK 1.4.1 (on Linux) seems to have a bug here: // XXX: Suns JDK 1.4.1 (on Linux) seems to have a bug here:
// 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 if (addr[0] == 0xAC && (addr[1] & 0xF0) == 0x01)
&& (addr [1] & 0xF0) == 0x01)
return true; return true;
// 192.168.0.0/16 // 192.168.0.0/16
if (addr [0] == 0xC0 if (addr[0] == 0xC0 && addr[1] == 0xA8)
&& 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 ?
...@@ -241,7 +234,6 @@ public class InetAddress implements Serializable ...@@ -241,7 +234,6 @@ public class InetAddress implements Serializable
{ {
// 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.
// XXX: This seems to not exist with IPv4 addresses // XXX: This seems to not exist with IPv4 addresses
return false; return false;
} }
...@@ -255,7 +247,6 @@ public class InetAddress implements Serializable ...@@ -255,7 +247,6 @@ public class InetAddress implements Serializable
{ {
// 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.
// XXX: This seems to not exist with IPv4 addresses // XXX: This seems to not exist with IPv4 addresses
return false; return false;
} }
...@@ -269,13 +260,10 @@ public class InetAddress implements Serializable ...@@ -269,13 +260,10 @@ public class InetAddress implements Serializable
{ {
// 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 && addr[1] == 0x00 && addr[2] == 0x00);
&& addr [1] == 0x00
&& addr [2] == 0x00);
} }
/** /**
...@@ -287,7 +275,6 @@ public class InetAddress implements Serializable ...@@ -287,7 +275,6 @@ public class InetAddress implements Serializable
{ {
// 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.
// XXX: This seems to not exist with IPv4 addresses // XXX: This seems to not exist with IPv4 addresses
return false; return false;
} }
...@@ -302,7 +289,6 @@ public class InetAddress implements Serializable ...@@ -302,7 +289,6 @@ public class InetAddress implements Serializable
{ {
// 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.
// XXX: This seems to not exist with IPv4 addresses // XXX: This seems to not exist with IPv4 addresses
return false; return false;
} }
...@@ -393,7 +379,8 @@ public class InetAddress implements Serializable ...@@ -393,7 +379,8 @@ public class InetAddress implements Serializable
*/ */
public String getHostAddress() public String getHostAddress()
{ {
StringBuffer sb = new StringBuffer (40); StringBuffer sb = new StringBuffer(40);
int len = addr.length; int len = addr.length;
int i = 0; int i = 0;
...@@ -458,7 +445,7 @@ public class InetAddress implements Serializable ...@@ -458,7 +445,7 @@ public class InetAddress implements Serializable
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;
...@@ -474,7 +461,7 @@ public class InetAddress implements Serializable ...@@ -474,7 +461,7 @@ public class InetAddress implements Serializable
* @return true if the passed in object's address is equal to this one's, * @return true if the passed in object's address is equal to this one's,
* false otherwise * false otherwise
*/ */
public boolean equals (Object obj) public boolean equals(Object obj)
{ {
if (! (obj instanceof InetAddress)) if (! (obj instanceof InetAddress))
return false; return false;
...@@ -491,7 +478,7 @@ public class InetAddress implements Serializable ...@@ -491,7 +478,7 @@ public class InetAddress implements Serializable
return false; return false;
for (int i = 0; i < addr.length; i++) for (int i = 0; i < addr.length; i++)
if (addr [i] != addr2 [i]) if (addr[i] != addr2[i])
return false; return false;
return true; return true;
...@@ -529,10 +516,10 @@ public class InetAddress implements Serializable ...@@ -529,10 +516,10 @@ public class InetAddress implements Serializable
* *
* @since 1.4 * @since 1.4
*/ */
public static InetAddress getByAddress (byte[] addr) public static InetAddress getByAddress(byte[] addr)
throws UnknownHostException throws UnknownHostException
{ {
return getByAddress (null, addr); return getByAddress(null, addr);
} }
/** /**
...@@ -546,16 +533,16 @@ public class InetAddress implements Serializable ...@@ -546,16 +533,16 @@ public class InetAddress implements Serializable
* *
* @since 1.4 * @since 1.4
*/ */
public static InetAddress getByAddress (String host, byte[] addr) public static InetAddress getByAddress(String host, byte[] addr)
throws UnknownHostException throws UnknownHostException
{ {
if (addr.length == 4) if (addr.length == 4)
return new Inet4Address (addr, host); return new Inet4Address(addr, host);
if (addr.length == 16) if (addr.length == 16)
return new Inet6Address (addr, host); return new Inet6Address(addr, host);
throw new UnknownHostException ("IP address has illegal length"); throw new UnknownHostException("IP address has illegal length");
} }
/** /**
...@@ -586,19 +573,19 @@ public class InetAddress implements Serializable ...@@ -586,19 +573,19 @@ public class InetAddress implements Serializable
* @exception SecurityException If a security manager exists and its * @exception SecurityException If a security manager exists and its
* checkConnect method doesn't allow the operation * checkConnect method doesn't allow the operation
*/ */
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 || hostname.length() == 0) if (hostname == null || hostname.length() == 0)
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);
if (address != null) if (address != null)
{ {
if (address.length == 4) if (address.length == 4)
...@@ -621,8 +608,8 @@ public class InetAddress implements Serializable ...@@ -621,8 +608,8 @@ public class InetAddress implements Serializable
} }
// Try to resolve the host by DNS // Try to resolve the host by DNS
InetAddress[] addresses = getAllByName (hostname); InetAddress[] addresses = getAllByName(hostname);
return addresses [0]; return addresses[0];
} }
/** /**
...@@ -632,7 +619,7 @@ public class InetAddress implements Serializable ...@@ -632,7 +619,7 @@ public class InetAddress implements Serializable
* dotted decimal format such as "127.0.0.1". If the value is null, the * dotted decimal format such as "127.0.0.1". If the value is null, the
* hostname of the local machine is supplied by default. * hostname of the local machine is supplied by default.
* *
* @param @param hostname The name of the desired host, or null for the * @param hostname The name of the desired host, or null for the
* local machine. * local machine.
* *
* @return All addresses of the host as an array of InetAddress objects. * @return All addresses of the host as an array of InetAddress objects.
...@@ -642,12 +629,12 @@ public class InetAddress implements Serializable ...@@ -642,12 +629,12 @@ public class InetAddress implements Serializable
* @exception SecurityException If a security manager exists and its * @exception SecurityException If a security manager exists and its
* checkConnect method doesn't allow the operation * checkConnect method doesn't allow the operation
*/ */
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);
// Check if hostname is an IP address // Check if hostname is an IP address
byte[] address = aton (hostname); byte[] address = aton (hostname);
...@@ -748,15 +735,15 @@ public class InetAddress implements Serializable ...@@ -748,15 +735,15 @@ public class InetAddress implements Serializable
// FIXME: implement this // FIXME: implement this
} }
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;
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.
...@@ -766,7 +753,7 @@ public class InetAddress implements Serializable ...@@ -766,7 +753,7 @@ public class InetAddress implements Serializable
family = getFamily (addr); family = getFamily (addr);
} }
private void writeObject (ObjectOutputStream oos) throws IOException private void writeObject(ObjectOutputStream oos) throws IOException
{ {
// Build a 32 bit address from the last 4 bytes of a 4 byte IPv4 address // Build a 32 bit address from the last 4 bytes of a 4 byte IPv4 address
// or a 16 byte IPv6 address. // or a 16 byte IPv6 address.
...@@ -774,7 +761,7 @@ public class InetAddress implements Serializable ...@@ -774,7 +761,7 @@ public class InetAddress implements Serializable
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();
} }
......
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.net; package java.net;
/** /**
* InetSocketAddress instances represent socket addresses * InetSocketAddress instances represent socket addresses
* in the java.nio package. They encapsulate a InetAddress and * in the java.nio package. They encapsulate a InetAddress and
...@@ -44,7 +45,6 @@ package java.net; ...@@ -44,7 +45,6 @@ package java.net;
* *
* @since 1.4 * @since 1.4
*/ */
public class InetSocketAddress extends SocketAddress public class InetSocketAddress extends SocketAddress
{ {
/** /**
...@@ -79,14 +79,14 @@ public class InetSocketAddress extends SocketAddress ...@@ -79,14 +79,14 @@ public class InetSocketAddress extends SocketAddress
throws IllegalArgumentException throws IllegalArgumentException
{ {
if (port < 0 || port > 65535) if (port < 0 || port > 65535)
throw new IllegalArgumentException ("Bad port number: " + port); throw new IllegalArgumentException("Bad port number: " + port);
if (addr == null) if (addr == null)
addr = InetAddress.ANY_IF; addr = InetAddress.ANY_IF;
this.addr = addr; this.addr = addr;
this.port = port; this.port = port;
this.hostname = addr.getHostName (); this.hostname = addr.getHostName();
} }
/** /**
...@@ -96,17 +96,16 @@ public class InetSocketAddress extends SocketAddress ...@@ -96,17 +96,16 @@ public class InetSocketAddress extends SocketAddress
* *
* @exception IllegalArgumentException If the port number is illegal * @exception IllegalArgumentException If the port number is illegal
*/ */
public InetSocketAddress(int port) public InetSocketAddress(int port) throws IllegalArgumentException
throws IllegalArgumentException
{ {
this ((InetAddress) null, port); this((InetAddress) null, port);
} }
/** /**
* Constructs an InetSocketAddress instance. * Constructs an InetSocketAddress instance.
* *
* @param addr Address of the socket * @param hostname The hostname for the socket address
* @param port Port if the socket * @param port The port for the socket address
* *
* @exception IllegalArgumentException If the port number is illegal * @exception IllegalArgumentException If the port number is illegal
*/ */
...@@ -114,10 +113,10 @@ public class InetSocketAddress extends SocketAddress ...@@ -114,10 +113,10 @@ public class InetSocketAddress extends SocketAddress
throws IllegalArgumentException throws IllegalArgumentException
{ {
if (hostname == null) if (hostname == null)
throw new IllegalArgumentException ("Null host name value"); throw new IllegalArgumentException("Null host name value");
if (port < 0 || port > 65535) if (port < 0 || port > 65535)
throw new IllegalArgumentException ("Bad port number: " + port); throw new IllegalArgumentException("Bad port number: " + port);
this.port = port; this.port = port;
this.hostname = hostname; this.hostname = hostname;
...@@ -140,11 +139,10 @@ public class InetSocketAddress extends SocketAddress ...@@ -140,11 +139,10 @@ public class InetSocketAddress extends SocketAddress
* *
* @return True if obj is equal. * @return True if obj is equal.
*/ */
public final boolean equals (Object obj) public final boolean equals(Object obj)
{ {
// InetSocketAddress objects are equal when addr and port are equal. // InetSocketAddress objects are equal when addr and port are equal.
// The hostname may differ. // The hostname may differ.
if (obj instanceof InetSocketAddress) if (obj instanceof InetSocketAddress)
{ {
InetSocketAddress sa = (InetSocketAddress) obj; InetSocketAddress sa = (InetSocketAddress) obj;
...@@ -152,9 +150,9 @@ public class InetSocketAddress extends SocketAddress ...@@ -152,9 +150,9 @@ public class InetSocketAddress extends SocketAddress
if (addr == null && sa.addr != null) if (addr == null && sa.addr != null)
return false; return false;
else if (addr == null && sa.addr == null) else if (addr == null && sa.addr == null)
return hostname.equals (sa.hostname) && sa.port == port; return hostname.equals(sa.hostname) && sa.port == port;
else else
return addr.equals (sa.addr) && sa.port == port; return addr.equals(sa.addr) && sa.port == port;
} }
return false; return false;
......
...@@ -35,24 +35,24 @@ this exception to your version of the library, but you are not ...@@ -35,24 +35,24 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
import java.io.IOException; import java.io.IOException;
import java.security.cert.Certificate;
import java.util.jar.Attributes; import java.util.jar.Attributes;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.jar.JarInputStream; import java.util.jar.JarInputStream;
import java.util.jar.Manifest; import java.util.jar.Manifest;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.security.cert.Certificate;
/** /**
* This abstract class represents a common superclass for implementations * This abstract class represents a common superclass for implementations
* of jar URL's. A jar URL is a special type of URL that allows JAR * of jar URL's. A jar URL is a special type of URL that allows JAR
* files on remote systems to be accessed. It has the form: * files on remote systems to be accessed. It has the form:
* <p> * <p>
* jar:<standard URL pointing to jar file>!/file/within/jarfile * jar:&lt;standard URL pointing to jar filei&gt;!/file/within/jarfile
* <p> for example: * <p> for example:
* <p> * <p>
* jar:http://www.urbanophile.com/java/foo.jar!/com/urbanophile/bar.class * jar:http://www.urbanophile.com/java/foo.jar!/com/urbanophile/bar.class
...@@ -96,30 +96,29 @@ public abstract class JarURLConnection extends URLConnection ...@@ -96,30 +96,29 @@ public abstract class JarURLConnection extends URLConnection
/** /**
* Creates a JarURLConnection from an URL object * Creates a JarURLConnection from an URL object
* *
* @param URL url The URL object for this connection. * @param url The URL object for this connection.
* *
* @exception MalformedURLException If url is invalid * @exception MalformedURLException If url is invalid
* *
* @specnote This constructor is protected since JDK 1.4 * @specnote This constructor is protected since JDK 1.4
*/ */
protected JarURLConnection (URL url) protected JarURLConnection(URL url) throws MalformedURLException
throws MalformedURLException
{ {
super (url); super(url);
if (!url.getProtocol().equals ("jar")) if (! url.getProtocol().equals("jar"))
throw new MalformedURLException (url + ": Not jar protocol."); throw new MalformedURLException(url + ": Not jar protocol.");
String spec = url.getFile(); String spec = url.getFile();
int bang = spec.indexOf ("!/"); int bang = spec.indexOf("!/");
if (bang == -1) if (bang == -1)
throw new MalformedURLException (url + ": No `!/' in spec."); throw new MalformedURLException(url + ": No `!/' in spec.");
// Extract the url for the jar itself. // Extract the url for the jar itself.
jarFileURL = new URL (spec.substring (0, bang)); jarFileURL = new URL(spec.substring(0, bang));
// Get the name of the entry, if any. // Get the name of the entry, if any.
entryName = spec.length() == (bang + 2) ? null : spec.substring (bang + 2); entryName = spec.length() == (bang + 2) ? null : spec.substring(bang + 2);
} }
/** /**
...@@ -128,7 +127,7 @@ public abstract class JarURLConnection extends URLConnection ...@@ -128,7 +127,7 @@ public abstract class JarURLConnection extends URLConnection
* *
* @return The remote URL * @return The remote URL
*/ */
public URL getJarFileURL () public URL getJarFileURL()
{ {
return jarFileURL; return jarFileURL;
} }
...@@ -140,7 +139,7 @@ public abstract class JarURLConnection extends URLConnection ...@@ -140,7 +139,7 @@ public abstract class JarURLConnection extends URLConnection
* *
* @return The entry name. * @return The entry name.
*/ */
public String getEntryName () public String getEntryName()
{ {
return entryName; return entryName;
} }
...@@ -152,7 +151,7 @@ public abstract class JarURLConnection extends URLConnection ...@@ -152,7 +151,7 @@ public abstract class JarURLConnection extends URLConnection
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public JarEntry getJarEntry () throws IOException public JarEntry getJarEntry() throws IOException
{ {
JarFile jarfile = null; JarFile jarfile = null;
...@@ -203,7 +202,7 @@ public abstract class JarURLConnection extends URLConnection ...@@ -203,7 +202,7 @@ public abstract class JarURLConnection extends URLConnection
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public abstract JarFile getJarFile () throws IOException; public abstract JarFile getJarFile() throws IOException;
/** /**
* Returns an array of Certificate objects for the jar file entry specified * Returns an array of Certificate objects for the jar file entry specified
...@@ -213,7 +212,7 @@ public abstract class JarURLConnection extends URLConnection ...@@ -213,7 +212,7 @@ public abstract class JarURLConnection extends URLConnection
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public Certificate[] getCertificates () throws IOException public Certificate[] getCertificates() throws IOException
{ {
JarEntry entry = getJarEntry(); JarEntry entry = getJarEntry();
...@@ -228,7 +227,7 @@ public abstract class JarURLConnection extends URLConnection ...@@ -228,7 +227,7 @@ public abstract class JarURLConnection extends URLConnection
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public Attributes getMainAttributes () throws IOException public Attributes getMainAttributes() throws IOException
{ {
Manifest manifest = getManifest(); Manifest manifest = getManifest();
...@@ -244,7 +243,7 @@ public abstract class JarURLConnection extends URLConnection ...@@ -244,7 +243,7 @@ public abstract class JarURLConnection extends URLConnection
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public Attributes getAttributes () throws IOException public Attributes getAttributes() throws IOException
{ {
JarEntry entry = getJarEntry(); JarEntry entry = getJarEntry();
...@@ -259,7 +258,7 @@ public abstract class JarURLConnection extends URLConnection ...@@ -259,7 +258,7 @@ public abstract class JarURLConnection extends URLConnection
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public Manifest getManifest () throws IOException public Manifest getManifest() throws IOException
{ {
JarFile file = getJarFile(); JarFile file = getJarFile();
......
...@@ -39,6 +39,7 @@ package java.net; ...@@ -39,6 +39,7 @@ package java.net;
import java.io.IOException; import java.io.IOException;
/** /**
* This exception indicates that a URL passed to an object was not in a * This exception indicates that a URL passed to an object was not in a
* valid format. * valid format.
......
...@@ -41,12 +41,12 @@ package java.net; ...@@ -41,12 +41,12 @@ package java.net;
import java.io.IOException; import java.io.IOException;
import java.util.Enumeration; import java.util.Enumeration;
/** /**
* Written using on-line Java Platform 1.2 API Specification, as well * Written using on-line Java Platform 1.2 API Specification, as well
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
* Status: Believed complete and correct. * Status: Believed complete and correct.
*/ */
/** /**
* This class models a multicast UDP socket. A multicast address is a * This class models a multicast UDP socket. A multicast address is a
* class D internet address (one whose most significant bits are 1110). * class D internet address (one whose most significant bits are 1110).
...@@ -189,7 +189,7 @@ public class MulticastSocket extends DatagramSocket ...@@ -189,7 +189,7 @@ public class MulticastSocket extends DatagramSocket
/** /**
* Sets the local network interface used to send multicast messages * Sets the local network interface used to send multicast messages
* *
* @param netIF The local network interface used to send multicast messages * @param netIf The local network interface used to send multicast messages
* *
* @exception SocketException If an error occurs * @exception SocketException If an error occurs
* *
...@@ -203,13 +203,13 @@ public class MulticastSocket extends DatagramSocket ...@@ -203,13 +203,13 @@ public class MulticastSocket extends DatagramSocket
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
Enumeration e = netIf.getInetAddresses (); Enumeration e = netIf.getInetAddresses();
if (!e.hasMoreElements ()) if (! e.hasMoreElements())
throw new SocketException("no network devices found"); throw new SocketException("no network devices found");
InetAddress address = (InetAddress) e.nextElement (); InetAddress address = (InetAddress) e.nextElement();
getImpl().setOption (SocketOptions.IP_MULTICAST_IF, address); getImpl().setOption(SocketOptions.IP_MULTICAST_IF, address);
} }
/** /**
...@@ -223,15 +223,14 @@ public class MulticastSocket extends DatagramSocket ...@@ -223,15 +223,14 @@ public class MulticastSocket extends DatagramSocket
* *
* @since 1.4 * @since 1.4
*/ */
public NetworkInterface getNetworkInterface() public NetworkInterface getNetworkInterface() throws SocketException
throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
InetAddress address = InetAddress address =
(InetAddress) getImpl().getOption (SocketOptions.IP_MULTICAST_IF); (InetAddress) getImpl().getOption(SocketOptions.IP_MULTICAST_IF);
NetworkInterface netIf = NetworkInterface.getByInetAddress (address); NetworkInterface netIf = NetworkInterface.getByInetAddress(address);
return netIf; return netIf;
} }
...@@ -255,11 +254,14 @@ public class MulticastSocket extends DatagramSocket ...@@ -255,11 +254,14 @@ public class MulticastSocket extends DatagramSocket
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
getImpl().setOption (SocketOptions.IP_MULTICAST_LOOP, Boolean.valueOf(disable)); getImpl().setOption(SocketOptions.IP_MULTICAST_LOOP,
Boolean.valueOf(disable));
} }
/** /**
* Checks if local loopback mode is enabled or not * Checks if local loopback mode is enabled
*
* @return true if loopback mode is enabled, false otherwise
* *
* @exception SocketException If an error occurs * @exception SocketException If an error occurs
* *
...@@ -270,7 +272,7 @@ public class MulticastSocket extends DatagramSocket ...@@ -270,7 +272,7 @@ public class MulticastSocket extends DatagramSocket
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
Object buf = getImpl().getOption (SocketOptions.IP_MULTICAST_LOOP); Object buf = getImpl().getOption(SocketOptions.IP_MULTICAST_LOOP);
if (buf instanceof Boolean) if (buf instanceof Boolean)
return ((Boolean) buf).booleanValue(); return ((Boolean) buf).booleanValue();
...@@ -323,9 +325,9 @@ public class MulticastSocket extends DatagramSocket ...@@ -323,9 +325,9 @@ public class MulticastSocket extends DatagramSocket
} }
/** /**
* Joins the specified mulitcast group. * Joins the specified multicast group.
* *
* @param addr The address of the group to join * @param mcastaddr The address of the group to join
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
* @exception SecurityException If a security manager exists and its * @exception SecurityException If a security manager exists and its
...@@ -349,7 +351,7 @@ public class MulticastSocket extends DatagramSocket ...@@ -349,7 +351,7 @@ public class MulticastSocket extends DatagramSocket
/** /**
* Leaves the specified multicast group * Leaves the specified multicast group
* *
* @param addr The address of the group to leave * @param mcastaddr The address of the group to leave
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
* @exception SecurityException If a security manager exists and its * @exception SecurityException If a security manager exists and its
...@@ -395,18 +397,18 @@ public class MulticastSocket extends DatagramSocket ...@@ -395,18 +397,18 @@ public class MulticastSocket extends DatagramSocket
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
if (! (mcastaddr instanceof InetSocketAddress)) if (! (mcastaddr instanceof InetSocketAddress))
throw new IllegalArgumentException ("SocketAddress type not supported"); throw new IllegalArgumentException("SocketAddress type not supported");
InetSocketAddress tmp = (InetSocketAddress) mcastaddr; InetSocketAddress tmp = (InetSocketAddress) mcastaddr;
if (! tmp.getAddress ().isMulticastAddress ()) if (! tmp.getAddress().isMulticastAddress())
throw new IOException ("Not a Multicast address"); throw new IOException("Not a Multicast address");
SecurityManager s = System.getSecurityManager (); SecurityManager s = System.getSecurityManager();
if (s != null) if (s != null)
s.checkMulticast (tmp.getAddress ()); s.checkMulticast(tmp.getAddress());
getImpl().joinGroup (mcastaddr, netIf); getImpl().joinGroup(mcastaddr, netIf);
} }
/** /**
...@@ -434,14 +436,14 @@ public class MulticastSocket extends DatagramSocket ...@@ -434,14 +436,14 @@ public class MulticastSocket extends DatagramSocket
InetSocketAddress tmp = (InetSocketAddress) mcastaddr; InetSocketAddress tmp = (InetSocketAddress) mcastaddr;
if (! tmp.getAddress ().isMulticastAddress ()) if (! tmp.getAddress().isMulticastAddress())
throw new IOException ("Not a Multicast address"); throw new IOException("Not a Multicast address");
SecurityManager s = System.getSecurityManager (); SecurityManager s = System.getSecurityManager();
if (s != null) if (s != null)
s.checkMulticast (tmp.getAddress ()); s.checkMulticast(tmp.getAddress());
getImpl().leaveGroup (mcastaddr, netIf); getImpl().leaveGroup(mcastaddr, netIf);
} }
/** /**
...@@ -458,7 +460,8 @@ public class MulticastSocket extends DatagramSocket ...@@ -458,7 +460,8 @@ public class MulticastSocket extends DatagramSocket
* *
* @deprecated * @deprecated
*/ */
public synchronized void send(DatagramPacket p, byte ttl) throws IOException public synchronized void send(DatagramPacket packet, byte ttl)
throws IOException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
...@@ -466,18 +469,18 @@ public class MulticastSocket extends DatagramSocket ...@@ -466,18 +469,18 @@ public class MulticastSocket extends DatagramSocket
SecurityManager s = System.getSecurityManager(); SecurityManager s = System.getSecurityManager();
if (s != null) if (s != null)
{ {
InetAddress addr = p.getAddress(); InetAddress addr = packet.getAddress();
if (addr.isMulticastAddress()) if (addr.isMulticastAddress())
s.checkPermission (new SocketPermission s.checkPermission(new SocketPermission(addr.getHostName()
(addr.getHostName () + p.getPort (), + packet.getPort(),
"accept,connect")); "accept,connect"));
else else
s.checkConnect(addr.getHostAddress(), p.getPort()); s.checkConnect(addr.getHostAddress(), packet.getPort());
} }
int oldttl = getImpl().getTimeToLive(); int oldttl = getImpl().getTimeToLive();
getImpl().setTimeToLive(((int) ttl) & 0xFF); getImpl().setTimeToLive(((int) ttl) & 0xFF);
getImpl().send(p); getImpl().send(packet);
getImpl().setTimeToLive(oldttl); getImpl().setTimeToLive(oldttl);
} }
} // class MulticastSocket }
...@@ -39,6 +39,7 @@ package java.net; ...@@ -39,6 +39,7 @@ package java.net;
import java.security.BasicPermission; import java.security.BasicPermission;
/** /**
* This class is used to model miscellaneous network permissions. It is * This class is used to model miscellaneous network permissions. It is
* a subclass of <code>BasicPermission</code>. This means that it models a * a subclass of <code>BasicPermission</code>. This means that it models a
...@@ -50,11 +51,11 @@ import java.security.BasicPermission; ...@@ -50,11 +51,11 @@ import java.security.BasicPermission;
* <ul> * <ul>
* <li>setDefaultAuthenticator - Grants the ability to install a facility * <li>setDefaultAuthenticator - Grants the ability to install a facility
* to collect username and password information when requested by a * to collect username and password information when requested by a
* web site or proxy server. * web site or proxy server.</li>
* <li>requestPasswordAuthentication - Grants the ability to ask the * <li>requestPasswordAuthentication - Grants the ability to ask the
* authentication facility for the user's password. * authentication facility for the user's password.</li>
* <li>specifyStreamHandler - Grants the permission to specify the * <li>specifyStreamHandler - Grants the permission to specify the
* stream handler class used when loading from a URL. * stream handler class used when loading from a URL.</li>
* </ul> * </ul>
* *
* @author Aaron M. Renn (arenn@urbanophile.com) * @author Aaron M. Renn (arenn@urbanophile.com)
......
...@@ -41,6 +41,7 @@ import gnu.classpath.Configuration; ...@@ -41,6 +41,7 @@ import gnu.classpath.Configuration;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Vector; import java.util.Vector;
/** /**
* This class models a network interface on the host computer. A network * This class models a network interface on the host computer. A network
* interface contains a name (typically associated with a specific * interface contains a name (typically associated with a specific
...@@ -56,23 +57,20 @@ public final class NetworkInterface ...@@ -56,23 +57,20 @@ public final class NetworkInterface
static static
{ {
if (Configuration.INIT_LOAD_LIBRARY) if (Configuration.INIT_LOAD_LIBRARY)
{ System.loadLibrary("javanet");
System.loadLibrary ("javanet");
}
} }
private String name; private String name;
private Vector inetAddresses; private Vector inetAddresses;
private NetworkInterface (String name, InetAddress address) private NetworkInterface(String name, InetAddress address)
{ {
this.name = name; this.name = name;
this.inetAddresses = new Vector (1, 1); this.inetAddresses = new Vector(1, 1);
this.inetAddresses.add (address); this.inetAddresses.add(address);
} }
private native static Vector getRealNetworkInterfaces () private static native Vector getRealNetworkInterfaces()
throws SocketException; throws SocketException;
/** /**
...@@ -80,7 +78,7 @@ public final class NetworkInterface ...@@ -80,7 +78,7 @@ public final class NetworkInterface
* *
* @return The name of the interface. * @return The name of the interface.
*/ */
public String getName () public String getName()
{ {
return name; return name;
} }
...@@ -95,30 +93,30 @@ public final class NetworkInterface ...@@ -95,30 +93,30 @@ public final class NetworkInterface
* *
* @return An enumeration of all addresses. * @return An enumeration of all addresses.
*/ */
public Enumeration getInetAddresses () public Enumeration getInetAddresses()
{ {
SecurityManager s = System.getSecurityManager (); SecurityManager s = System.getSecurityManager();
if (s == null) if (s == null)
return inetAddresses.elements (); return inetAddresses.elements();
Vector tmpInetAddresses = new Vector (1, 1); Vector tmpInetAddresses = new Vector(1, 1);
for (Enumeration addresses = inetAddresses.elements (); for (Enumeration addresses = inetAddresses.elements();
addresses.hasMoreElements (); ) addresses.hasMoreElements();)
{ {
InetAddress addr = (InetAddress) addresses.nextElement (); InetAddress addr = (InetAddress) addresses.nextElement();
try try
{ {
s.checkConnect (addr.getHostAddress (), 58000); s.checkConnect(addr.getHostAddress(), 58000);
tmpInetAddresses.add (addr); tmpInetAddresses.add(addr);
} }
catch (SecurityException e) catch (SecurityException e)
{ {
} }
} }
return tmpInetAddresses.elements (); return tmpInetAddresses.elements();
} }
/** /**
...@@ -126,7 +124,7 @@ public final class NetworkInterface ...@@ -126,7 +124,7 @@ public final class NetworkInterface
* *
* @return The display name of the interface * @return The display name of the interface
*/ */
public String getDisplayName () public String getDisplayName()
{ {
return name; return name;
} }
...@@ -139,21 +137,20 @@ public final class NetworkInterface ...@@ -139,21 +137,20 @@ public final class NetworkInterface
* @exception SocketException If an error occurs * @exception SocketException If an error occurs
* @exception NullPointerException If the specified name is null * @exception NullPointerException If the specified name is null
*/ */
public static NetworkInterface getByName (String name) public static NetworkInterface getByName(String name)
throws SocketException throws SocketException
{ {
Vector networkInterfaces = getRealNetworkInterfaces (); Vector networkInterfaces = getRealNetworkInterfaces();
for (Enumeration e = networkInterfaces.elements (); for (Enumeration e = networkInterfaces.elements(); e.hasMoreElements();)
e.hasMoreElements (); )
{ {
NetworkInterface tmp = (NetworkInterface) e.nextElement (); NetworkInterface tmp = (NetworkInterface) e.nextElement();
if (name.equals (tmp.getName ())) if (name.equals(tmp.getName()))
return tmp; return tmp;
} }
throw new SocketException ("no network interface with this name exists"); throw new SocketException("no network interface with this name exists");
} }
/** /**
...@@ -164,26 +161,25 @@ public final class NetworkInterface ...@@ -164,26 +161,25 @@ public final class NetworkInterface
* @exception SocketException If an error occurs * @exception SocketException If an error occurs
* @exception NullPointerException If the specified addess is null * @exception NullPointerException If the specified addess is null
*/ */
public static NetworkInterface getByInetAddress (InetAddress addr) public static NetworkInterface getByInetAddress(InetAddress addr)
throws SocketException throws SocketException
{ {
Vector networkInterfaces = getRealNetworkInterfaces (); Vector networkInterfaces = getRealNetworkInterfaces();
for (Enumeration interfaces = networkInterfaces.elements (); for (Enumeration interfaces = networkInterfaces.elements();
interfaces.hasMoreElements (); ) interfaces.hasMoreElements();)
{ {
NetworkInterface tmp = (NetworkInterface) interfaces.nextElement (); NetworkInterface tmp = (NetworkInterface) interfaces.nextElement();
for (Enumeration addresses = tmp.inetAddresses.elements (); for (Enumeration addresses = tmp.inetAddresses.elements();
addresses.hasMoreElements (); ) addresses.hasMoreElements();)
{ {
if (addr.equals ((InetAddress) addresses.nextElement ())) if (addr.equals((InetAddress) addresses.nextElement()))
return tmp; return tmp;
} }
} }
throw new SocketException ( throw new SocketException("no network interface is bound to such an IP address");
"no network interface is bound to such an IP address");
} }
/** /**
...@@ -191,8 +187,7 @@ public final class NetworkInterface ...@@ -191,8 +187,7 @@ public final class NetworkInterface
* *
* @exception SocketException If an error occurs * @exception SocketException If an error occurs
*/ */
public static Enumeration getNetworkInterfaces () public static Enumeration getNetworkInterfaces() throws SocketException
throws SocketException
{ {
Vector networkInterfaces = getRealNetworkInterfaces(); Vector networkInterfaces = getRealNetworkInterfaces();
...@@ -207,43 +202,42 @@ public final class NetworkInterface ...@@ -207,43 +202,42 @@ public final class NetworkInterface
* *
* @param obj The object to compare with * @param obj The object to compare with
*/ */
public boolean equals (Object obj) public boolean equals(Object obj)
{ {
if (!(obj instanceof NetworkInterface)) if (! (obj instanceof NetworkInterface))
return false; return false;
NetworkInterface tmp = (NetworkInterface) obj; NetworkInterface tmp = (NetworkInterface) obj;
return (name.equals (tmp.name) return (name.equals(tmp.name) && inetAddresses.equals(tmp.inetAddresses));
&& inetAddresses.equals (tmp.inetAddresses));
} }
/** /**
* Returns the hashcode of the current instance * Returns the hashcode of the current instance
*/ */
public int hashCode () public int hashCode()
{ {
// FIXME: hash correctly // FIXME: hash correctly
return name.hashCode () + inetAddresses.hashCode (); return name.hashCode() + inetAddresses.hashCode();
} }
/** /**
* Returns a string representation of the interface * Returns a string representation of the interface
*/ */
public String toString () public String toString()
{ {
// FIXME: check if this is correct // FIXME: check if this is correct
String result; String result;
String separator = System.getProperty ("line.separator"); String separator = System.getProperty("line.separator");
result = "name: " + getDisplayName () + " (" + getName () + result =
") addresses:" + separator; "name: " + getDisplayName() + " (" + getName() + ") addresses:"
+ separator;
for (Enumeration e = inetAddresses.elements (); for (Enumeration e = inetAddresses.elements(); e.hasMoreElements();)
e.hasMoreElements (); )
{ {
InetAddress address = (InetAddress) e.nextElement (); InetAddress address = (InetAddress) e.nextElement();
result += address.toString () + ";" + separator; result += address.toString() + ";" + separator;
} }
return result; return result;
......
...@@ -35,9 +35,9 @@ this exception to your version of the library, but you are not ...@@ -35,9 +35,9 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
/** /**
* This exception indicates that there is no TCP/IP route to the requested * This exception indicates that there is no TCP/IP route to the requested
* host. This is often due to a misconfigured routing table. * host. This is often due to a misconfigured routing table.
......
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.net; package java.net;
/** /**
* This class serves a container for username/password pairs. * This class serves a container for username/password pairs.
* *
...@@ -91,7 +92,7 @@ public final class PasswordAuthentication ...@@ -91,7 +92,7 @@ public final class PasswordAuthentication
*/ */
public String getUserName() public String getUserName()
{ {
return(username); return (username);
} }
/** /**
...@@ -101,8 +102,6 @@ public final class PasswordAuthentication ...@@ -101,8 +102,6 @@ public final class PasswordAuthentication
*/ */
public char[] getPassword() public char[] getPassword()
{ {
return(password); return (password);
} }
} // class PasswordAuthentication } // class PasswordAuthentication
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.net; package java.net;
/** /**
* This exception signals that an ICMP port unreachable datagram has been * This exception signals that an ICMP port unreachable datagram has been
* received. * received.
...@@ -69,4 +70,3 @@ public class PortUnreachableException extends SocketException ...@@ -69,4 +70,3 @@ public class PortUnreachableException extends SocketException
super(message); super(message);
} }
} // class PortUnreachableException } // class PortUnreachableException
...@@ -39,6 +39,7 @@ package java.net; ...@@ -39,6 +39,7 @@ package java.net;
import java.io.IOException; import java.io.IOException;
/** /**
* This exception indicates that some sort of low level protocol * This exception indicates that some sort of low level protocol
* exception occurred. Look in the descriptive message (if any) for * exception occurred. Look in the descriptive message (if any) for
......
...@@ -36,7 +36,6 @@ this exception to your version of the library, but you are not ...@@ -36,7 +36,6 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
import gnu.java.net.PlainSocketImpl; import gnu.java.net.PlainSocketImpl;
...@@ -44,6 +43,7 @@ import java.io.IOException; ...@@ -44,6 +43,7 @@ import java.io.IOException;
import java.nio.channels.IllegalBlockingModeException; import java.nio.channels.IllegalBlockingModeException;
import java.nio.channels.ServerSocketChannel; import java.nio.channels.ServerSocketChannel;
/* Written using on-line Java Platform 1.2 API Specification. /* Written using on-line Java Platform 1.2 API Specification.
* Status: I believe all methods are implemented. * Status: I believe all methods are implemented.
*/ */
...@@ -82,9 +82,10 @@ public class ServerSocket ...@@ -82,9 +82,10 @@ public class ServerSocket
/* /*
* This constructor is only used by java.nio. * This constructor is only used by java.nio.
*/ */
// FIXME: Workaround a bug in gcj. // FIXME: Workaround a bug in gcj.
//ServerSocket (PlainSocketImpl impl) throws IOException //ServerSocket (PlainSocketImpl impl) throws IOException
ServerSocket (SocketImpl impl) throws IOException ServerSocket(SocketImpl impl) throws IOException
{ {
if (impl == null) if (impl == null)
throw new NullPointerException("impl may not be null"); throw new NullPointerException("impl may not be null");
...@@ -96,6 +97,7 @@ public class ServerSocket ...@@ -96,6 +97,7 @@ public class ServerSocket
/* /*
* This method is only used by java.nio. * This method is only used by java.nio.
*/ */
// FIXME: Workaround a bug in gcj. // FIXME: Workaround a bug in gcj.
//PlainSocketImpl getImpl() //PlainSocketImpl getImpl()
SocketImpl getImpl() SocketImpl getImpl()
...@@ -131,8 +133,7 @@ public class ServerSocket ...@@ -131,8 +133,7 @@ public class ServerSocket
* @exception SecurityException If a security manager exists and its * @exception SecurityException If a security manager exists and its
* checkListen method doesn't allow the operation * checkListen method doesn't allow the operation
*/ */
public ServerSocket (int port) public ServerSocket(int port) throws IOException
throws IOException
{ {
this(port, 50); this(port, 50);
} }
...@@ -150,8 +151,7 @@ public class ServerSocket ...@@ -150,8 +151,7 @@ public class ServerSocket
* @exception SecurityException If a security manager exists and its * @exception SecurityException If a security manager exists and its
* checkListen method doesn't allow the operation * checkListen method doesn't allow the operation
*/ */
public ServerSocket (int port, int backlog) public ServerSocket(int port, int backlog) throws IOException
throws IOException
{ {
this(port, backlog, null); this(port, backlog, null);
} }
...@@ -173,13 +173,13 @@ public class ServerSocket ...@@ -173,13 +173,13 @@ public class ServerSocket
* *
* @since 1.1 * @since 1.1
*/ */
public ServerSocket (int port, int backlog, InetAddress bindAddr) public ServerSocket(int port, int backlog, InetAddress bindAddr)
throws IOException throws IOException
{ {
this(); this();
// bind/listen socket // bind/listen socket
bind (new InetSocketAddress (bindAddr, port), backlog); bind(new InetSocketAddress(bindAddr, port), backlog);
} }
/** /**
...@@ -194,10 +194,9 @@ public class ServerSocket ...@@ -194,10 +194,9 @@ public class ServerSocket
* *
* @since 1.4 * @since 1.4
*/ */
public void bind (SocketAddress endpoint) public void bind(SocketAddress endpoint) throws IOException
throws IOException
{ {
bind (endpoint, 50); bind(endpoint, 50);
} }
/** /**
...@@ -213,19 +212,20 @@ public class ServerSocket ...@@ -213,19 +212,20 @@ public class ServerSocket
* *
* @since 1.4 * @since 1.4
*/ */
public void bind (SocketAddress endpoint, int backlog) throws IOException public void bind(SocketAddress endpoint, int backlog)
throws IOException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("ServerSocket is closed"); throw new SocketException("ServerSocket is closed");
if (! (endpoint instanceof InetSocketAddress)) if (! (endpoint instanceof InetSocketAddress))
throw new IllegalArgumentException ("Address type not supported"); throw new IllegalArgumentException("Address type not supported");
InetSocketAddress tmp = (InetSocketAddress) endpoint; InetSocketAddress tmp = (InetSocketAddress) endpoint;
SecurityManager s = System.getSecurityManager (); SecurityManager s = System.getSecurityManager();
if (s != null) if (s != null)
s.checkListen (tmp.getPort ()); s.checkListen(tmp.getPort());
InetAddress addr = tmp.getAddress(); InetAddress addr = tmp.getAddress();
...@@ -263,12 +263,12 @@ public class ServerSocket ...@@ -263,12 +263,12 @@ public class ServerSocket
*/ */
public InetAddress getInetAddress() public InetAddress getInetAddress()
{ {
if (!isBound()) if (! isBound())
return null; return null;
try try
{ {
return (InetAddress) impl.getOption (SocketOptions.SO_BINDADDR); return (InetAddress) impl.getOption(SocketOptions.SO_BINDADDR);
} }
catch (SocketException e) catch (SocketException e)
{ {
...@@ -284,7 +284,7 @@ public class ServerSocket ...@@ -284,7 +284,7 @@ public class ServerSocket
*/ */
public int getLocalPort() public int getLocalPort()
{ {
if (!isBound()) if (! isBound())
return -1; return -1;
return impl.getLocalPort(); return impl.getLocalPort();
...@@ -293,11 +293,13 @@ public class ServerSocket ...@@ -293,11 +293,13 @@ public class ServerSocket
/** /**
* Returns the local socket address * Returns the local socket address
* *
* @return the local socket address, null if not bound
*
* @since 1.4 * @since 1.4
*/ */
public SocketAddress getLocalSocketAddress() public SocketAddress getLocalSocketAddress()
{ {
if (!isBound()) if (! isBound())
return null; return null;
return new InetSocketAddress(getInetAddress(), getLocalPort()); return new InetSocketAddress(getInetAddress(), getLocalPort());
...@@ -308,6 +310,8 @@ public class ServerSocket ...@@ -308,6 +310,8 @@ public class ServerSocket
* instance representing that connection. This method will block until a * instance representing that connection. This method will block until a
* connection is available. * connection is available.
* *
* @return socket object for the just accepted connection
*
* @exception IOException If an error occurs * @exception IOException If an error occurs
* @exception SecurityException If a security manager exists and its * @exception SecurityException If a security manager exists and its
* checkListen method doesn't allow the operation * checkListen method doesn't allow the operation
...@@ -316,11 +320,11 @@ public class ServerSocket ...@@ -316,11 +320,11 @@ public class ServerSocket
* @exception SocketTimeoutException If a timeout was previously set with * @exception SocketTimeoutException If a timeout was previously set with
* setSoTimeout and the timeout has been reached * setSoTimeout and the timeout has been reached
*/ */
public Socket accept () throws IOException public Socket accept() throws IOException
{ {
SecurityManager sm = System.getSecurityManager (); SecurityManager sm = System.getSecurityManager();
if (sm != null) if (sm != null)
sm.checkListen (impl.getLocalPort ()); sm.checkListen(impl.getLocalPort());
Socket socket = new Socket(); Socket socket = new Socket();
...@@ -357,8 +361,7 @@ public class ServerSocket ...@@ -357,8 +361,7 @@ public class ServerSocket
* *
* @since 1.1 * @since 1.1
*/ */
protected final void implAccept (Socket socket) protected final void implAccept(Socket socket) throws IOException
throws IOException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("ServerSocket is closed"); throw new SocketException("ServerSocket is closed");
...@@ -380,7 +383,7 @@ public class ServerSocket ...@@ -380,7 +383,7 @@ public class ServerSocket
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public void close () throws IOException public void close() throws IOException
{ {
if (isClosed()) if (isClosed())
return; return;
...@@ -400,6 +403,8 @@ public class ServerSocket ...@@ -400,6 +403,8 @@ public class ServerSocket
* The socket only has a ServerSocketChannel if its created * The socket only has a ServerSocketChannel if its created
* by ServerSocketChannel.open. * by ServerSocketChannel.open.
* *
* @return the associated socket channel, null if none exists
*
* @since 1.4 * @since 1.4
*/ */
public ServerSocketChannel getChannel() public ServerSocketChannel getChannel()
...@@ -410,6 +415,8 @@ public class ServerSocket ...@@ -410,6 +415,8 @@ public class ServerSocket
/** /**
* Returns true when the socket is bound, otherwise false * Returns true when the socket is bound, otherwise false
* *
* @return true if socket is bound, false otherwise
*
* @since 1.4 * @since 1.4
*/ */
public boolean isBound() public boolean isBound()
...@@ -420,6 +427,8 @@ public class ServerSocket ...@@ -420,6 +427,8 @@ public class ServerSocket
/** /**
* Returns true if the socket is closed, otherwise false * Returns true if the socket is closed, otherwise false
* *
* @return true if socket is closed, false otherwise
*
* @since 1.4 * @since 1.4
*/ */
public boolean isClosed() public boolean isClosed()
...@@ -439,7 +448,7 @@ public class ServerSocket ...@@ -439,7 +448,7 @@ public class ServerSocket
* *
* @since 1.1 * @since 1.1
*/ */
public void setSoTimeout (int timeout) throws SocketException public void setSoTimeout(int timeout) throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("ServerSocket is closed"); throw new SocketException("ServerSocket is closed");
...@@ -462,54 +471,56 @@ public class ServerSocket ...@@ -462,54 +471,56 @@ public class ServerSocket
* *
* @since 1.1 * @since 1.1
*/ */
public int getSoTimeout () throws IOException public int getSoTimeout() throws IOException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("ServerSocket is closed"); throw new SocketException("ServerSocket is closed");
Object timeout = impl.getOption(SocketOptions.SO_TIMEOUT); Object timeout = impl.getOption(SocketOptions.SO_TIMEOUT);
if (!(timeout instanceof Integer)) if (! (timeout instanceof Integer))
throw new IOException("Internal Error"); throw new IOException("Internal Error");
return ((Integer)timeout).intValue(); return ((Integer) timeout).intValue();
} }
/** /**
* Enables/Disables the SO_REUSEADDR option * Enables/Disables the SO_REUSEADDR option
* *
* @param on true if SO_REUSEADDR should be enabled, false otherwise
*
* @exception SocketException If an error occurs * @exception SocketException If an error occurs
* *
* @since 1.4 * @since 1.4
*/ */
public void setReuseAddress (boolean on) public void setReuseAddress(boolean on) throws SocketException
throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("ServerSocket is closed"); throw new SocketException("ServerSocket is closed");
impl.setOption (SocketOptions.SO_REUSEADDR, Boolean.valueOf(on)); impl.setOption(SocketOptions.SO_REUSEADDR, Boolean.valueOf(on));
} }
/** /**
* Checks if the SO_REUSEADDR option is enabled * Checks if the SO_REUSEADDR option is enabled
* *
* @return true if SO_REUSEADDR is set, false otherwise
*
* @exception SocketException If an error occurs * @exception SocketException If an error occurs
* *
* @since 1.4 * @since 1.4
*/ */
public boolean getReuseAddress() public boolean getReuseAddress() throws SocketException
throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("ServerSocket is closed"); throw new SocketException("ServerSocket is closed");
Object reuseaddr = impl.getOption (SocketOptions.SO_REUSEADDR); Object reuseaddr = impl.getOption(SocketOptions.SO_REUSEADDR);
if (!(reuseaddr instanceof Boolean)) if (! (reuseaddr instanceof Boolean))
throw new SocketException ("Internal Error"); throw new SocketException("Internal Error");
return ((Boolean) reuseaddr).booleanValue (); return ((Boolean) reuseaddr).booleanValue();
} }
/** /**
...@@ -524,16 +535,15 @@ public class ServerSocket ...@@ -524,16 +535,15 @@ public class ServerSocket
* *
* @since 1.4 * @since 1.4
*/ */
public void setReceiveBufferSize (int size) public void setReceiveBufferSize(int size) throws SocketException
throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("ServerSocket is closed"); throw new SocketException("ServerSocket is closed");
if (size <= 0) if (size <= 0)
throw new IllegalArgumentException ("SO_RCVBUF value must be > 0"); throw new IllegalArgumentException("SO_RCVBUF value must be > 0");
impl.setOption (SocketOptions.SO_RCVBUF, new Integer (size)); impl.setOption(SocketOptions.SO_RCVBUF, new Integer(size));
} }
/** /**
...@@ -547,18 +557,17 @@ public class ServerSocket ...@@ -547,18 +557,17 @@ public class ServerSocket
* *
* @since 1.4 * @since 1.4
*/ */
public int getReceiveBufferSize () public int getReceiveBufferSize() throws SocketException
throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("ServerSocket is closed"); throw new SocketException("ServerSocket is closed");
Object buf = impl.getOption (SocketOptions.SO_RCVBUF); Object buf = impl.getOption(SocketOptions.SO_RCVBUF);
if (!(buf instanceof Integer)) if (! (buf instanceof Integer))
throw new SocketException ("Internal Error: Unexpected type"); throw new SocketException("Internal Error: Unexpected type");
return ((Integer) buf).intValue (); return ((Integer) buf).intValue();
} }
/** /**
...@@ -566,9 +575,9 @@ public class ServerSocket ...@@ -566,9 +575,9 @@ public class ServerSocket
* *
* @return This socket represented as a <code>String</code>. * @return This socket represented as a <code>String</code>.
*/ */
public String toString () public String toString()
{ {
if (!isBound()) if (! isBound())
return "ServerSocket[unbound]"; return "ServerSocket[unbound]";
return ("ServerSocket[addr=" + getInetAddress() return ("ServerSocket[addr=" + getInetAddress()
...@@ -585,12 +594,14 @@ public class ServerSocket ...@@ -585,12 +594,14 @@ public class ServerSocket
* to setting the factory. If insufficient privileges exist to set the * to setting the factory. If insufficient privileges exist to set the
* factory, an exception will be thrown * factory, an exception will be thrown
* *
* @param fac the factory to set
*
* @exception SecurityException If this operation is not allowed by the * @exception SecurityException If this operation is not allowed by the
* <code>SecurityManager</code>. * <code>SecurityManager</code>.
* @exception SocketException If the factory object is already defined * @exception SocketException If the factory object is already defined
* @exception IOException If any other error occurs * @exception IOException If any other error occurs
*/ */
public static synchronized void setSocketFactory (SocketImplFactory fac) public static synchronized void setSocketFactory(SocketImplFactory fac)
throws IOException throws IOException
{ {
factory = fac; factory = fac;
......
...@@ -36,15 +36,15 @@ this exception to your version of the library, but you are not ...@@ -36,15 +36,15 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
import gnu.java.net.PlainSocketImpl; import gnu.java.net.PlainSocketImpl;
import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.channels.SocketChannel;
import java.nio.channels.IllegalBlockingModeException; import java.nio.channels.IllegalBlockingModeException;
import java.nio.channels.SocketChannel;
/* Written using on-line Java Platform 1.2 API Specification. /* Written using on-line Java Platform 1.2 API Specification.
* Status: I believe all methods are implemented. * Status: I believe all methods are implemented.
...@@ -81,7 +81,8 @@ public class Socket ...@@ -81,7 +81,8 @@ public class Socket
private SocketImpl impl; private SocketImpl impl;
/** /**
* True if socket implementation was created by calling their create() method. * True if socket implementation was created by calling their
* create() method.
*/ */
private boolean implCreated; private boolean implCreated;
...@@ -108,7 +109,7 @@ public class Socket ...@@ -108,7 +109,7 @@ public class Socket
* @specnote This constructor is public since JDK 1.4 * @specnote This constructor is public since JDK 1.4
* @since 1.1 * @since 1.1
*/ */
public Socket () public Socket()
{ {
if (factory != null) if (factory != null)
impl = factory.createSocketImpl(); impl = factory.createSocketImpl();
...@@ -133,7 +134,7 @@ public class Socket ...@@ -133,7 +134,7 @@ public class Socket
* *
* @since 1.1 * @since 1.1
*/ */
protected Socket (SocketImpl impl) throws SocketException protected Socket(SocketImpl impl) throws SocketException
{ {
if (impl == null) if (impl == null)
this.impl = new PlainSocketImpl(); this.impl = new PlainSocketImpl();
...@@ -154,7 +155,7 @@ public class Socket ...@@ -154,7 +155,7 @@ public class Socket
* @exception SecurityException If a security manager exists and its * @exception SecurityException If a security manager exists and its
* checkConnect method doesn't allow the operation * checkConnect method doesn't allow the operation
*/ */
public Socket (String host, int port) public Socket(String host, int port)
throws UnknownHostException, IOException throws UnknownHostException, IOException
{ {
this(InetAddress.getByName(host), port, null, 0, true); this(InetAddress.getByName(host), port, null, 0, true);
...@@ -171,8 +172,7 @@ public class Socket ...@@ -171,8 +172,7 @@ public class Socket
* @exception SecurityException If a security manager exists and its * @exception SecurityException If a security manager exists and its
* checkConnect method doesn't allow the operation * checkConnect method doesn't allow the operation
*/ */
public Socket (InetAddress address, int port) public Socket(InetAddress address, int port) throws IOException
throws IOException
{ {
this(address, port, null, 0, true); this(address, port, null, 0, true);
} }
...@@ -194,8 +194,8 @@ public class Socket ...@@ -194,8 +194,8 @@ public class Socket
* *
* @since 1.1 * @since 1.1
*/ */
public Socket (String host, int port, public Socket(String host, int port, InetAddress localAddr, int localPort)
InetAddress localAddr, int localPort) throws IOException throws IOException
{ {
this(InetAddress.getByName(host), port, localAddr, localPort, true); this(InetAddress.getByName(host), port, localAddr, localPort, true);
} }
...@@ -216,8 +216,8 @@ public class Socket ...@@ -216,8 +216,8 @@ public class Socket
* *
* @since 1.1 * @since 1.1
*/ */
public Socket (InetAddress address, int port, public Socket(InetAddress address, int port, InetAddress localAddr,
InetAddress localAddr, int localPort) throws IOException int localPort) throws IOException
{ {
this(address, port, localAddr, localPort, true); this(address, port, localAddr, localPort, true);
} }
...@@ -240,7 +240,8 @@ public class Socket ...@@ -240,7 +240,8 @@ public class Socket
* @deprecated Use the <code>DatagramSocket</code> class to create * @deprecated Use the <code>DatagramSocket</code> class to create
* datagram oriented sockets. * datagram oriented sockets.
*/ */
public Socket (String host, int port, boolean stream) throws IOException public Socket(String host, int port, boolean stream)
throws IOException
{ {
this(InetAddress.getByName(host), port, null, 0, stream); this(InetAddress.getByName(host), port, null, 0, stream);
} }
...@@ -263,7 +264,8 @@ public class Socket ...@@ -263,7 +264,8 @@ public class Socket
* @deprecated Use the <code>DatagramSocket</code> class to create * @deprecated Use the <code>DatagramSocket</code> class to create
* datagram oriented sockets. * datagram oriented sockets.
*/ */
public Socket (InetAddress host, int port, boolean stream) throws IOException public Socket(InetAddress host, int port, boolean stream)
throws IOException
{ {
this(host, port, null, 0, stream); this(host, port, null, 0, stream);
} }
...@@ -296,11 +298,11 @@ public class Socket ...@@ -296,11 +298,11 @@ public class Socket
// bind socket // bind socket
SocketAddress bindaddr = SocketAddress bindaddr =
laddr == null ? null : new InetSocketAddress (laddr, lport); laddr == null ? null : new InetSocketAddress(laddr, lport);
bind (bindaddr); bind(bindaddr);
// connect socket // connect socket
connect (new InetSocketAddress (raddr, rport)); connect(new InetSocketAddress(raddr, rport));
// FIXME: JCL p. 1586 says if localPort is unspecified, bind to any port, // FIXME: JCL p. 1586 says if localPort is unspecified, bind to any port,
// i.e. '0' and if localAddr is unspecified, use getLocalAddress() as // i.e. '0' and if localAddr is unspecified, use getLocalAddress() as
...@@ -308,12 +310,11 @@ public class Socket ...@@ -308,12 +310,11 @@ public class Socket
} }
// This has to be accessible from java.net.ServerSocket. // This has to be accessible from java.net.ServerSocket.
SocketImpl getImpl() SocketImpl getImpl() throws SocketException
throws SocketException
{ {
try try
{ {
if (!implCreated) if (! implCreated)
{ {
impl.create(true); impl.create(true);
implCreated = true; implCreated = true;
...@@ -339,7 +340,7 @@ public class Socket ...@@ -339,7 +340,7 @@ public class Socket
* *
* @since 1.4 * @since 1.4
*/ */
public void bind (SocketAddress bindpoint) throws IOException public void bind(SocketAddress bindpoint) throws IOException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
...@@ -347,32 +348,32 @@ public class Socket ...@@ -347,32 +348,32 @@ public class Socket
// XXX: JDK 1.4.1 API documentation says that if bindpoint is null the // XXX: JDK 1.4.1 API documentation says that if bindpoint is null the
// socket will be bound to an ephemeral port and a valid local address. // socket will be bound to an ephemeral port and a valid local address.
if (bindpoint == null) if (bindpoint == null)
bindpoint = new InetSocketAddress (InetAddress.ANY_IF, 0); bindpoint = new InetSocketAddress(InetAddress.ANY_IF, 0);
if ( !(bindpoint instanceof InetSocketAddress)) if (! (bindpoint instanceof InetSocketAddress))
throw new IllegalArgumentException (); throw new IllegalArgumentException();
InetSocketAddress tmp = (InetSocketAddress) bindpoint; InetSocketAddress tmp = (InetSocketAddress) bindpoint;
// bind to address/port // bind to address/port
try try
{ {
getImpl().bind (tmp.getAddress(), tmp.getPort()); getImpl().bind(tmp.getAddress(), tmp.getPort());
bound = true; bound = true;
} }
catch (IOException exception) catch (IOException exception)
{ {
close (); close();
throw exception; throw exception;
} }
catch (RuntimeException exception) catch (RuntimeException exception)
{ {
close (); close();
throw exception; throw exception;
} }
catch (Error error) catch (Error error)
{ {
close (); close();
throw error; throw error;
} }
} }
...@@ -389,10 +390,9 @@ public class Socket ...@@ -389,10 +390,9 @@ public class Socket
* *
* @since 1.4 * @since 1.4
*/ */
public void connect (SocketAddress endpoint) public void connect(SocketAddress endpoint) throws IOException
throws IOException
{ {
connect (endpoint, 0); connect(endpoint, 0);
} }
/** /**
...@@ -412,7 +412,7 @@ public class Socket ...@@ -412,7 +412,7 @@ public class Socket
* *
* @since 1.4 * @since 1.4
*/ */
public void connect (SocketAddress endpoint, int timeout) public void connect(SocketAddress endpoint, int timeout)
throws IOException throws IOException
{ {
if (isClosed()) if (isClosed())
...@@ -425,31 +425,30 @@ public class Socket ...@@ -425,31 +425,30 @@ public class Socket
// it is in non-blocking mode, we throw an IllegalBlockingModeException. // it is in non-blocking mode, we throw an IllegalBlockingModeException.
// However, in our implementation if the channel itself initiated this // However, in our implementation if the channel itself initiated this
// operation, then we must honor it regardless of its blocking mode. // operation, then we must honor it regardless of its blocking mode.
if (getChannel() != null if (getChannel() != null && ! getChannel().isBlocking()
&& !getChannel().isBlocking () && ! ((PlainSocketImpl) getImpl()).isInChannelOperation())
&& !((PlainSocketImpl) getImpl()).isInChannelOperation()) throw new IllegalBlockingModeException();
throw new IllegalBlockingModeException ();
if (!isBound ()) if (! isBound())
bind (null); bind(null);
try try
{ {
getImpl().connect (endpoint, timeout); getImpl().connect(endpoint, timeout);
} }
catch (IOException exception) catch (IOException exception)
{ {
close (); close();
throw exception; throw exception;
} }
catch (RuntimeException exception) catch (RuntimeException exception)
{ {
close (); close();
throw exception; throw exception;
} }
catch (Error error) catch (Error error)
{ {
close (); close();
throw error; throw error;
} }
} }
...@@ -460,9 +459,9 @@ public class Socket ...@@ -460,9 +459,9 @@ public class Socket
* *
* @return The remote address this socket is connected to * @return The remote address this socket is connected to
*/ */
public InetAddress getInetAddress () public InetAddress getInetAddress()
{ {
if (!isConnected()) if (! isConnected())
return null; return null;
try try
...@@ -485,7 +484,7 @@ public class Socket ...@@ -485,7 +484,7 @@ public class Socket
* *
* @since 1.1 * @since 1.1
*/ */
public InetAddress getLocalAddress () public InetAddress getLocalAddress()
{ {
InetAddress addr = null; InetAddress addr = null;
...@@ -493,7 +492,7 @@ public class Socket ...@@ -493,7 +492,7 @@ public class Socket
{ {
addr = (InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR); addr = (InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR);
} }
catch(SocketException e) catch (SocketException e)
{ {
// (hopefully) shouldn't happen // (hopefully) shouldn't happen
// throw new java.lang.InternalError // throw new java.lang.InternalError
...@@ -519,9 +518,9 @@ public class Socket ...@@ -519,9 +518,9 @@ public class Socket
* *
* @return The remote port this socket is connected to * @return The remote port this socket is connected to
*/ */
public int getPort () public int getPort()
{ {
if (!isConnected()) if (! isConnected())
return 0; return 0;
try try
...@@ -543,9 +542,9 @@ public class Socket ...@@ -543,9 +542,9 @@ public class Socket
* *
* @return The local port * @return The local port
*/ */
public int getLocalPort () public int getLocalPort()
{ {
if (!isBound()) if (! isBound())
return -1; return -1;
try try
...@@ -562,21 +561,22 @@ public class Socket ...@@ -562,21 +561,22 @@ public class Socket
} }
/** /**
* If the socket is already bound this returns the local SocketAddress, * Returns local socket address.
* otherwise null *
* @return the local socket address, null if not bound
* *
* @since 1.4 * @since 1.4
*/ */
public SocketAddress getLocalSocketAddress() public SocketAddress getLocalSocketAddress()
{ {
if (!isBound()) if (! isBound())
return null; return null;
InetAddress addr = getLocalAddress (); InetAddress addr = getLocalAddress();
try try
{ {
return new InetSocketAddress (addr, getImpl().getLocalPort()); return new InetSocketAddress(addr, getImpl().getLocalPort());
} }
catch (SocketException e) catch (SocketException e)
{ {
...@@ -586,19 +586,21 @@ public class Socket ...@@ -586,19 +586,21 @@ public class Socket
} }
/** /**
* If the socket is already connected this returns the remote SocketAddress, * Returns the remote socket address.
* otherwise null *
* @return the remote socket address, null of not connected
* *
* @since 1.4 * @since 1.4
*/ */
public SocketAddress getRemoteSocketAddress() public SocketAddress getRemoteSocketAddress()
{ {
if (!isConnected ()) if (! isConnected())
return null; return null;
try try
{ {
return new InetSocketAddress (getImpl().getInetAddress (), getImpl().getPort ()); return new InetSocketAddress(getImpl().getInetAddress(),
getImpl().getPort());
} }
catch (SocketException e) catch (SocketException e)
{ {
...@@ -614,12 +616,12 @@ public class Socket ...@@ -614,12 +616,12 @@ public class Socket
* *
* @exception IOException If an error occurs or Socket is not connected * @exception IOException If an error occurs or Socket is not connected
*/ */
public InputStream getInputStream () throws IOException public InputStream getInputStream() throws IOException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
if (!isConnected()) if (! isConnected())
throw new IOException("not connected"); throw new IOException("not connected");
return getImpl().getInputStream(); return getImpl().getInputStream();
...@@ -632,12 +634,12 @@ public class Socket ...@@ -632,12 +634,12 @@ public class Socket
* *
* @exception IOException If an error occurs or Socket is not connected * @exception IOException If an error occurs or Socket is not connected
*/ */
public OutputStream getOutputStream () throws IOException public OutputStream getOutputStream() throws IOException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
if (!isConnected()) if (! isConnected())
throw new IOException("not connected"); throw new IOException("not connected");
return getImpl().getOutputStream(); return getImpl().getOutputStream();
...@@ -652,7 +654,7 @@ public class Socket ...@@ -652,7 +654,7 @@ public class Socket
* *
* @since 1.1 * @since 1.1
*/ */
public void setTcpNoDelay (boolean on) throws SocketException public void setTcpNoDelay(boolean on) throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
...@@ -680,7 +682,7 @@ public class Socket ...@@ -680,7 +682,7 @@ public class Socket
Object on = getImpl().getOption(SocketOptions.TCP_NODELAY); Object on = getImpl().getOption(SocketOptions.TCP_NODELAY);
if (on instanceof Boolean) if (on instanceof Boolean)
return(((Boolean)on).booleanValue()); return (((Boolean) on).booleanValue());
else else
throw new SocketException("Internal Error"); throw new SocketException("Internal Error");
} }
...@@ -707,7 +709,7 @@ public class Socket ...@@ -707,7 +709,7 @@ public class Socket
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
if (on == true) if (on)
{ {
if (linger < 0) if (linger < 0)
throw new IllegalArgumentException("SO_LINGER must be >= 0"); throw new IllegalArgumentException("SO_LINGER must be >= 0");
...@@ -718,10 +720,8 @@ public class Socket ...@@ -718,10 +720,8 @@ public class Socket
getImpl().setOption(SocketOptions.SO_LINGER, new Integer(linger)); getImpl().setOption(SocketOptions.SO_LINGER, new Integer(linger));
} }
else else
{
getImpl().setOption(SocketOptions.SO_LINGER, Boolean.valueOf(false)); getImpl().setOption(SocketOptions.SO_LINGER, Boolean.valueOf(false));
} }
}
/** /**
* Returns the value of the SO_LINGER option on the socket. If the * Returns the value of the SO_LINGER option on the socket. If the
...@@ -747,7 +747,7 @@ public class Socket ...@@ -747,7 +747,7 @@ public class Socket
Object linger = getImpl().getOption(SocketOptions.SO_LINGER); Object linger = getImpl().getOption(SocketOptions.SO_LINGER);
if (linger instanceof Integer) if (linger instanceof Integer)
return(((Integer)linger).intValue()); return (((Integer) linger).intValue());
else else
return -1; return -1;
} }
...@@ -762,12 +762,12 @@ public class Socket ...@@ -762,12 +762,12 @@ public class Socket
* *
* @since 1.4 * @since 1.4
*/ */
public void sendUrgentData (int data) throws IOException public void sendUrgentData(int data) throws IOException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
getImpl().sendUrgentData (data); getImpl().sendUrgentData(data);
} }
/** /**
...@@ -779,7 +779,7 @@ public class Socket ...@@ -779,7 +779,7 @@ public class Socket
* *
* @since 1.4 * @since 1.4
*/ */
public void setOOBInline (boolean on) throws SocketException public void setOOBInline(boolean on) throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
...@@ -796,7 +796,7 @@ public class Socket ...@@ -796,7 +796,7 @@ public class Socket
* *
* @since 1.4 * @since 1.4
*/ */
public boolean getOOBInline () throws SocketException public boolean getOOBInline() throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
...@@ -804,7 +804,7 @@ public class Socket ...@@ -804,7 +804,7 @@ public class Socket
Object buf = getImpl().getOption(SocketOptions.SO_OOBINLINE); Object buf = getImpl().getOption(SocketOptions.SO_OOBINLINE);
if (buf instanceof Boolean) if (buf instanceof Boolean)
return(((Boolean)buf).booleanValue()); return (((Boolean) buf).booleanValue());
else else
throw new SocketException("Internal Error: Unexpected type"); throw new SocketException("Internal Error: Unexpected type");
} }
...@@ -826,7 +826,7 @@ public class Socket ...@@ -826,7 +826,7 @@ public class Socket
* *
* @since 1.1 * @since 1.1
*/ */
public synchronized void setSoTimeout (int timeout) throws SocketException public synchronized void setSoTimeout(int timeout) throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
...@@ -854,14 +854,14 @@ public class Socket ...@@ -854,14 +854,14 @@ public class Socket
* *
* @since 1.1 * @since 1.1
*/ */
public synchronized int getSoTimeout () throws SocketException public synchronized int getSoTimeout() throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
Object timeout = getImpl().getOption(SocketOptions.SO_TIMEOUT); Object timeout = getImpl().getOption(SocketOptions.SO_TIMEOUT);
if (timeout instanceof Integer) if (timeout instanceof Integer)
return(((Integer)timeout).intValue()); return (((Integer) timeout).intValue());
else else
return 0; return 0;
} }
...@@ -878,7 +878,7 @@ public class Socket ...@@ -878,7 +878,7 @@ public class Socket
* *
* @since 1.2 * @since 1.2
*/ */
public void setSendBufferSize (int size) throws SocketException public void setSendBufferSize(int size) throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
...@@ -900,7 +900,7 @@ public class Socket ...@@ -900,7 +900,7 @@ public class Socket
* *
* @since 1.2 * @since 1.2
*/ */
public int getSendBufferSize () throws SocketException public int getSendBufferSize() throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
...@@ -908,7 +908,7 @@ public class Socket ...@@ -908,7 +908,7 @@ public class Socket
Object buf = getImpl().getOption(SocketOptions.SO_SNDBUF); Object buf = getImpl().getOption(SocketOptions.SO_SNDBUF);
if (buf instanceof Integer) if (buf instanceof Integer)
return(((Integer)buf).intValue()); return (((Integer) buf).intValue());
else else
throw new SocketException("Internal Error: Unexpected type"); throw new SocketException("Internal Error: Unexpected type");
} }
...@@ -925,7 +925,7 @@ public class Socket ...@@ -925,7 +925,7 @@ public class Socket
* *
* @since 1.2 * @since 1.2
*/ */
public void setReceiveBufferSize (int size) throws SocketException public void setReceiveBufferSize(int size) throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
...@@ -947,7 +947,7 @@ public class Socket ...@@ -947,7 +947,7 @@ public class Socket
* *
* @since 1.2 * @since 1.2
*/ */
public int getReceiveBufferSize () throws SocketException public int getReceiveBufferSize() throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
...@@ -955,7 +955,7 @@ public class Socket ...@@ -955,7 +955,7 @@ public class Socket
Object buf = getImpl().getOption(SocketOptions.SO_RCVBUF); Object buf = getImpl().getOption(SocketOptions.SO_RCVBUF);
if (buf instanceof Integer) if (buf instanceof Integer)
return(((Integer)buf).intValue()); return (((Integer) buf).intValue());
else else
throw new SocketException("Internal Error: Unexpected type"); throw new SocketException("Internal Error: Unexpected type");
} }
...@@ -970,7 +970,7 @@ public class Socket ...@@ -970,7 +970,7 @@ public class Socket
* *
* @since 1.3 * @since 1.3
*/ */
public void setKeepAlive (boolean on) throws SocketException public void setKeepAlive(boolean on) throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
...@@ -988,7 +988,7 @@ public class Socket ...@@ -988,7 +988,7 @@ public class Socket
* *
* @since 1.3 * @since 1.3
*/ */
public boolean getKeepAlive () throws SocketException public boolean getKeepAlive() throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
...@@ -996,7 +996,7 @@ public class Socket ...@@ -996,7 +996,7 @@ public class Socket
Object buf = getImpl().getOption(SocketOptions.SO_KEEPALIVE); Object buf = getImpl().getOption(SocketOptions.SO_KEEPALIVE);
if (buf instanceof Boolean) if (buf instanceof Boolean)
return(((Boolean)buf).booleanValue()); return (((Boolean) buf).booleanValue());
else else
throw new SocketException("Internal Error: Unexpected type"); throw new SocketException("Internal Error: Unexpected type");
} }
...@@ -1006,7 +1006,7 @@ public class Socket ...@@ -1006,7 +1006,7 @@ public class Socket
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public synchronized void close () throws IOException public synchronized void close() throws IOException
{ {
if (isClosed()) if (isClosed())
return; return;
...@@ -1024,15 +1024,14 @@ public class Socket ...@@ -1024,15 +1024,14 @@ public class Socket
* *
* @return The <code>String</code> representation of this <code>Socket</code> * @return The <code>String</code> representation of this <code>Socket</code>
*/ */
public String toString () public String toString()
{ {
try try
{ {
if (isConnected()) if (isConnected())
return ("Socket[addr=" + getImpl().getInetAddress() return ("Socket[addr=" + getImpl().getInetAddress() + ",port="
+ ",port=" + getImpl().getPort() + getImpl().getPort() + ",localport="
+ ",localport=" + getImpl().getLocalPort() + getImpl().getLocalPort() + "]");
+ "]");
} }
catch (SocketException e) catch (SocketException e)
{ {
...@@ -1050,12 +1049,14 @@ public class Socket ...@@ -1050,12 +1049,14 @@ public class Socket
* insufficient privileges exist to set the factory, then an * insufficient privileges exist to set the factory, then an
* <code>IOException</code> will be thrown. * <code>IOException</code> will be thrown.
* *
* @param fac the factory to set
*
* @exception SecurityException If the <code>SecurityManager</code> does * @exception SecurityException If the <code>SecurityManager</code> does
* not allow this operation. * not allow this operation.
* @exception SocketException If the SocketImplFactory is already defined * @exception SocketException If the SocketImplFactory is already defined
* @exception IOException If any other error occurs * @exception IOException If any other error occurs
*/ */
public static synchronized void setSocketImplFactory (SocketImplFactory fac) public static synchronized void setSocketImplFactory(SocketImplFactory fac)
throws IOException throws IOException
{ {
// See if already set // See if already set
...@@ -1108,7 +1109,8 @@ public class Socket ...@@ -1108,7 +1109,8 @@ public class Socket
/** /**
* Returns the socket channel associated with this socket. * Returns the socket channel associated with this socket.
* *
* It returns null if no associated socket exists. * @return the associated socket channel,
* null if no associated channel exists
* *
* @since 1.4 * @since 1.4
*/ */
...@@ -1126,31 +1128,33 @@ public class Socket ...@@ -1126,31 +1128,33 @@ public class Socket
* *
* @since 1.4 * @since 1.4
*/ */
public boolean getReuseAddress () throws SocketException public boolean getReuseAddress() throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
Object reuseaddr = getImpl().getOption (SocketOptions.SO_REUSEADDR); Object reuseaddr = getImpl().getOption(SocketOptions.SO_REUSEADDR);
if (!(reuseaddr instanceof Boolean)) if (! (reuseaddr instanceof Boolean))
throw new SocketException ("Internal Error"); throw new SocketException("Internal Error");
return ((Boolean) reuseaddr).booleanValue (); return ((Boolean) reuseaddr).booleanValue();
} }
/** /**
* Enables/Disables the SO_REUSEADDR option * Enables/Disables the SO_REUSEADDR option
* *
* @param reuseAddress True if SO_REUSEADDR should be set. * @param reuseAddress true if SO_REUSEADDR should be enabled,
* false otherwise
* *
* @exception SocketException If an error occurs * @exception SocketException If an error occurs
* *
* @since 1.4 * @since 1.4
*/ */
public void setReuseAddress (boolean on) throws SocketException public void setReuseAddress(boolean reuseAddress) throws SocketException
{ {
getImpl().setOption (SocketOptions.SO_REUSEADDR, Boolean.valueOf(on)); getImpl().setOption(SocketOptions.SO_REUSEADDR,
Boolean.valueOf(reuseAddress));
} }
/** /**
...@@ -1164,7 +1168,7 @@ public class Socket ...@@ -1164,7 +1168,7 @@ public class Socket
* *
* @since 1.4 * @since 1.4
*/ */
public int getTrafficClass () throws SocketException public int getTrafficClass() throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
...@@ -1172,9 +1176,9 @@ public class Socket ...@@ -1172,9 +1176,9 @@ public class Socket
Object obj = getImpl().getOption(SocketOptions.IP_TOS); Object obj = getImpl().getOption(SocketOptions.IP_TOS);
if (obj instanceof Integer) if (obj instanceof Integer)
return ((Integer) obj).intValue (); return ((Integer) obj).intValue();
else else
throw new SocketException ("Unexpected type"); throw new SocketException("Unexpected type");
} }
/** /**
...@@ -1189,7 +1193,7 @@ public class Socket ...@@ -1189,7 +1193,7 @@ public class Socket
* *
* @since 1.4 * @since 1.4
*/ */
public void setTrafficClass (int tc) throws SocketException public void setTrafficClass(int tc) throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
...@@ -1197,7 +1201,7 @@ public class Socket ...@@ -1197,7 +1201,7 @@ public class Socket
if (tc < 0 || tc > 255) if (tc < 0 || tc > 255)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
getImpl().setOption (SocketOptions.IP_TOS, new Integer (tc)); getImpl().setOption(SocketOptions.IP_TOS, new Integer(tc));
} }
/** /**
...@@ -1207,11 +1211,11 @@ public class Socket ...@@ -1207,11 +1211,11 @@ public class Socket
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isConnected () public boolean isConnected()
{ {
try try
{ {
return getImpl().getInetAddress () != null; return getImpl().getInetAddress() != null;
} }
catch (SocketException e) catch (SocketException e)
{ {
...@@ -1226,7 +1230,7 @@ public class Socket ...@@ -1226,7 +1230,7 @@ public class Socket
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isBound () public boolean isBound()
{ {
return bound; return bound;
} }
...@@ -1238,7 +1242,7 @@ public class Socket ...@@ -1238,7 +1242,7 @@ public class Socket
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isClosed () public boolean isClosed()
{ {
return impl == null; return impl == null;
} }
...@@ -1250,7 +1254,7 @@ public class Socket ...@@ -1250,7 +1254,7 @@ public class Socket
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isInputShutdown () public boolean isInputShutdown()
{ {
return inputShutdown; return inputShutdown;
} }
...@@ -1262,7 +1266,7 @@ public class Socket ...@@ -1262,7 +1266,7 @@ public class Socket
* *
* @since 1.4 * @since 1.4
*/ */
public boolean isOutputShutdown () public boolean isOutputShutdown()
{ {
return outputShutdown; return outputShutdown;
} }
......
...@@ -39,6 +39,7 @@ package java.net; ...@@ -39,6 +39,7 @@ package java.net;
import java.io.Serializable; import java.io.Serializable;
/** /**
* Abstract base class for InetSocketAddress. * Abstract base class for InetSocketAddress.
* InetSocketAddress is to my knowledge the only derived * InetSocketAddress is to my knowledge the only derived
......
...@@ -39,6 +39,7 @@ package java.net; ...@@ -39,6 +39,7 @@ package java.net;
import java.io.IOException; import java.io.IOException;
/** /**
* This exception indicates that a generic error occurred related to an * This exception indicates that a generic error occurred related to an
* operation on a socket. Check the descriptive message (if any) for * operation on a socket. Check the descriptive message (if any) for
......
...@@ -36,14 +36,14 @@ this exception to your version of the library, but you are not ...@@ -36,14 +36,14 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
/* Written using on-line Java Platform 1.2 API Specification. /* Written using on-line Java Platform 1.2 API Specification.
* Believed complete and correct. * Believed complete and correct.
*/ */
...@@ -113,7 +113,8 @@ public abstract class SocketImpl implements SocketOptions ...@@ -113,7 +113,8 @@ public abstract class SocketImpl implements SocketOptions
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
protected abstract void connect(String host, int port) throws IOException; protected abstract void connect(String host, int port)
throws IOException;
/** /**
* Connects to the remote address and port specified as arguments. * Connects to the remote address and port specified as arguments.
...@@ -153,7 +154,8 @@ public abstract class SocketImpl implements SocketOptions ...@@ -153,7 +154,8 @@ public abstract class SocketImpl implements SocketOptions
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
protected abstract void bind(InetAddress host, int port) throws IOException; protected abstract void bind(InetAddress host, int port)
throws IOException;
/** /**
* Starts listening for connections on a socket. The backlog parameter * Starts listening for connections on a socket. The backlog parameter
...@@ -220,26 +222,38 @@ public abstract class SocketImpl implements SocketOptions ...@@ -220,26 +222,38 @@ public abstract class SocketImpl implements SocketOptions
* *
* @return A FileDescriptor for this socket. * @return A FileDescriptor for this socket.
*/ */
protected FileDescriptor getFileDescriptor() { return fd; } protected FileDescriptor getFileDescriptor()
{
return fd;
}
/** /**
* Returns the remote address this socket is connected to * Returns the remote address this socket is connected to
* *
* @return The remote address * @return The remote address
*/ */
protected InetAddress getInetAddress() { return address; } protected InetAddress getInetAddress()
{
return address;
}
/** /**
* Returns the remote port this socket is connected to * Returns the remote port this socket is connected to
* *
* @return The remote port * @return The remote port
*/ */
protected int getPort() { return port; } protected int getPort()
{
return port;
}
/** /**
* Returns true or false when this socket supports sending urgent data * Returns true or false when this socket supports sending urgent data
* or not. * or not.
* *
* @return true if the socket implementation supports sending urgent data,
* false otherwise
*
* @since 1.4 * @since 1.4
*/ */
protected boolean supportsUrgentData() protected boolean supportsUrgentData()
...@@ -258,15 +272,17 @@ public abstract class SocketImpl implements SocketOptions ...@@ -258,15 +272,17 @@ public abstract class SocketImpl implements SocketOptions
* *
* @since 1.4 * @since 1.4
*/ */
protected abstract void sendUrgentData(int data) protected abstract void sendUrgentData(int data) throws IOException;
throws IOException;
/** /**
* Returns the local port this socket is bound to * Returns the local port this socket is bound to
* *
* @return The local port * @return The local port
*/ */
protected int getLocalPort() { return localport; } protected int getLocalPort()
{
return localport;
}
/** /**
* Returns a <code>String</code> representing the remote host and port of * Returns a <code>String</code> representing the remote host and port of
...@@ -276,10 +292,9 @@ public abstract class SocketImpl implements SocketOptions ...@@ -276,10 +292,9 @@ public abstract class SocketImpl implements SocketOptions
*/ */
public String toString() public String toString()
{ {
return "[addr=" + ((address == null) ? "0.0.0.0/0.0.0.0" : return "[addr="
address.toString()) + ((address == null) ? "0.0.0.0/0.0.0.0" : address.toString())
+ ",port=" + port + ",port=" + port + ",localport=" + localport + "]";
+ ",localport=" + localport + "]";
} }
/** /**
...@@ -288,9 +303,9 @@ public abstract class SocketImpl implements SocketOptions ...@@ -288,9 +303,9 @@ public abstract class SocketImpl implements SocketOptions
* *
* @exception IOException if an error occurs * @exception IOException if an error occurs
*/ */
protected void shutdownInput () throws IOException protected void shutdownInput() throws IOException
{ {
throw new IOException ("Not implemented in this socket class"); throw new IOException("Not implemented in this socket class");
} }
/** /**
...@@ -299,8 +314,8 @@ public abstract class SocketImpl implements SocketOptions ...@@ -299,8 +314,8 @@ public abstract class SocketImpl implements SocketOptions
* *
* @exception IOException if an error occurs * @exception IOException if an error occurs
*/ */
protected void shutdownOutput () throws IOException protected void shutdownOutput() throws IOException
{ {
throw new IOException ("Not implemented in this socket class"); throw new IOException("Not implemented in this socket class");
} }
} }
...@@ -35,13 +35,12 @@ this exception to your version of the library, but you are not ...@@ -35,13 +35,12 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
/** Written using on-line Java Platform 1.2 API Specification. /** Written using on-line Java Platform 1.2 API Specification.
* Status: Believed complete and correct. * Status: Believed complete and correct.
*/ */
/** /**
* This interface defines one method which returns a <code>SocketImpl</code> * This interface defines one method which returns a <code>SocketImpl</code>
* object. This should not be needed by ordinary applications. * object. This should not be needed by ordinary applications.
...@@ -57,6 +56,4 @@ public interface SocketImplFactory ...@@ -57,6 +56,4 @@ public interface SocketImplFactory
* @return A <code>SocketImpl</code> object * @return A <code>SocketImpl</code> object
*/ */
SocketImpl createSocketImpl(); SocketImpl createSocketImpl();
} // interface SocketImplFactory } // interface SocketImplFactory
...@@ -38,11 +38,11 @@ exception statement from your version. */ ...@@ -38,11 +38,11 @@ exception statement from your version. */
package java.net; package java.net;
/** /**
* Written using on-line Java Platform 1.2 API Specification. * Written using on-line Java Platform 1.2 API Specification.
* Status: Believed complete and correct. * Status: Believed complete and correct.
*/ */
/** /**
* This interface is used by <code>SocketImpl</code> and * This interface is used by <code>SocketImpl</code> and
* <code>DatagramSocketImpl</code> to implement options * <code>DatagramSocketImpl</code> to implement options
...@@ -163,6 +163,4 @@ public interface SocketOptions ...@@ -163,6 +163,4 @@ public interface SocketOptions
* @exception SocketException If an error occurs * @exception SocketException If an error occurs
*/ */
Object getOption(int optionId) throws SocketException; Object getOption(int optionId) throws SocketException;
} // interface SocketOptions } // interface SocketOptions
/* SocketPermission.java -- Class modeling permissions for socket operations /* SocketPermission.java -- Class modeling permissions for socket operations
Copyright (C) 1998, 2000, 2001, 2002 Free Software Foundation, Inc. Copyright (C) 1998, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -41,6 +41,7 @@ import java.io.Serializable; ...@@ -41,6 +41,7 @@ import java.io.Serializable;
import java.security.Permission; import java.security.Permission;
import java.security.PermissionCollection; import java.security.PermissionCollection;
/** /**
* This class models a specific set of permssions for connecting to a * This class models a specific set of permssions for connecting to a
* host. There are two elements to this, the host/port combination and * host. There are two elements to this, the host/port combination and
...@@ -64,18 +65,20 @@ import java.security.PermissionCollection; ...@@ -64,18 +65,20 @@ import java.security.PermissionCollection;
* value for a port (respectively) is used by default. Here are some * value for a port (respectively) is used by default. Here are some
* examples: * examples:
* <p><ul> * <p><ul>
* <li>8080 - Represents port 8080 only * <li>8080 - Represents port 8080 only</li>
* <li>2000-3000 - Represents ports 2000 through 3000 inclusive * <li>2000-3000 - Represents ports 2000 through 3000 inclusive</li>
* <li>-4000 - Represents ports 0 through 4000 inclusive * <li>-4000 - Represents ports 0 through 4000 inclusive</li>
* <li>1024- - Represents ports 1024 through 65535 inclusive * <li>1024- - Represents ports 1024 through 65535 inclusive</li>
* </ul><p> * </ul><p>
* The permission list is a comma separated list of individual permissions. * The permission list is a comma separated list of individual permissions.
* These individual permissions are: * These individual permissions are:
* <p> * <p>
* accept<br> * <pre>
* connect<br> * accept
* listen<br> * connect
* resolve<br> * listen
* resolve
* </pre>
* <p> * <p>
* The "listen" permission is only relevant if the host is localhost. If * The "listen" permission is only relevant if the host is localhost. If
* any permission at all is specified, then resolve permission is implied to * any permission at all is specified, then resolve permission is implied to
...@@ -103,12 +106,12 @@ import java.security.PermissionCollection; ...@@ -103,12 +106,12 @@ import java.security.PermissionCollection;
* *
* @author Aaron M. Renn (arenn@urbanophile.com) * @author Aaron M. Renn (arenn@urbanophile.com)
*/ */
public final class SocketPermission extends Permission public final class SocketPermission extends Permission implements Serializable
implements Serializable
{ {
static final long serialVersionUID = -7204263841984476862L; static final long serialVersionUID = -7204263841984476862L;
// FIXME: Needs serialization work, including readObject/writeObject methods. // FIXME: Needs serialization work, including readObject/writeObject methods.
/** /**
* A hostname/port combination as described above * A hostname/port combination as described above
*/ */
...@@ -147,7 +150,7 @@ public final class SocketPermission extends Permission ...@@ -147,7 +150,7 @@ public final class SocketPermission extends Permission
*/ */
public boolean equals(Object obj) public boolean equals(Object obj)
{ {
if (!(obj instanceof SocketPermission)) if (! (obj instanceof SocketPermission))
return (false); return (false);
if (((SocketPermission) obj).hostport.equals(hostport)) if (((SocketPermission) obj).hostport.equals(hostport))
...@@ -231,20 +234,22 @@ public final class SocketPermission extends Permission ...@@ -231,20 +234,22 @@ public final class SocketPermission extends Permission
/** /**
* Returns true if the permission object passed it is implied by the * Returns true if the permission object passed it is implied by the
* this permission. This will be true if * this permission. This will be true if:
* <p><ul> *
* <li>The argument is of type <code>SocketPermission</code> * <ul>
* <li>The actions list of the argument are in this object's actions * <li>The argument is of type <code>SocketPermission</code></li>
* <li>The port range of the argument is within this objects port range * <li>The actions list of the argument are in this object's actions</li>
* <li>The hostname is equal to or a subset of this objects hostname * <li>The port range of the argument is within this objects port range</li>
* <li>The hostname is equal to or a subset of this objects hostname</li>
* </ul> * </ul>
* <p> *
* The argument's hostname will be a subset of this object's hostname if: * <p>The argument's hostname will be a subset of this object's hostname if:</p>
* <p><ul> *
* <li>The argument's hostname or IP address is equal to this object's. * <ul>
* <li>The argument's canonical hostname is equal to this object's. * <li>The argument's hostname or IP address is equal to this object's.</li>
* <li>The argument's canonical hostname is equal to this object's.</li>
* <li>The argument's canonical name matches this domains hostname with * <li>The argument's canonical name matches this domains hostname with
* wildcards * wildcards</li>
* </ul> * </ul>
* *
* @param perm The <code>Permission</code> to check against * @param perm The <code>Permission</code> to check against
...@@ -266,12 +271,20 @@ public final class SocketPermission extends Permission ...@@ -266,12 +271,20 @@ public final class SocketPermission extends Permission
String ourlist = getActions(); String ourlist = getActions();
String theirlist = p.getActions(); String theirlist = p.getActions();
if (!ourlist.startsWith(theirlist)) if (! ourlist.startsWith(theirlist))
return (false); return (false);
// Now check ports // Now check ports
int ourfirstport = 0, ourlastport = 0, theirfirstport = 0, theirlastport = int ourfirstport = 0;
0;
// Now check ports
int ourlastport = 0;
// Now check ports
int theirfirstport = 0;
// Now check ports
int theirlastport = 0;
// Get ours // Get ours
if (hostport.indexOf(":") == -1) if (hostport.indexOf(":") == -1)
...@@ -299,8 +312,7 @@ public final class SocketPermission extends Permission ...@@ -299,8 +312,7 @@ public final class SocketPermission extends Permission
ourlastport = Integer.parseInt(range); ourlastport = Integer.parseInt(range);
else else
ourlastport = ourlastport =
Integer.parseInt(range. Integer.parseInt(range.substring(range.indexOf("-") + 1,
substring(range.indexOf("-") + 1,
range.length())); range.length()));
} }
...@@ -329,8 +341,7 @@ public final class SocketPermission extends Permission ...@@ -329,8 +341,7 @@ public final class SocketPermission extends Permission
theirlastport = Integer.parseInt(range); theirlastport = Integer.parseInt(range);
else else
theirlastport = theirlastport =
Integer.parseInt(range. Integer.parseInt(range.substring(range.indexOf("-") + 1,
substring(range.indexOf("-") + 1,
range.length())); range.length()));
} }
...@@ -339,7 +350,10 @@ public final class SocketPermission extends Permission ...@@ -339,7 +350,10 @@ public final class SocketPermission extends Permission
return (false); return (false);
// Finally we can check the hosts // Finally we can check the hosts
String ourhost, theirhost; String ourhost;
// Finally we can check the hosts
String theirhost;
// Get ours // Get ours
if (hostport.indexOf(":") == -1) if (hostport.indexOf(":") == -1)
...@@ -358,7 +372,10 @@ public final class SocketPermission extends Permission ...@@ -358,7 +372,10 @@ public final class SocketPermission extends Permission
return (true); return (true);
// Try the canonical names // Try the canonical names
String ourcanonical = null, theircanonical = null; String ourcanonical = null;
// Try the canonical names
String theircanonical = null;
try try
{ {
ourcanonical = InetAddress.getByName(ourhost).getHostName(); ourcanonical = InetAddress.getByName(ourhost).getHostName();
......
...@@ -39,6 +39,7 @@ package java.net; ...@@ -39,6 +39,7 @@ package java.net;
import java.io.InterruptedIOException; import java.io.InterruptedIOException;
/** /**
* This exception signals that a socket read or accept timed out. * This exception signals that a socket read or accept timed out.
* *
......
...@@ -44,14 +44,14 @@ import java.io.Serializable; ...@@ -44,14 +44,14 @@ import java.io.Serializable;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
* @author Ito Kazumitsu (ito.kazumitsu@hitachi-cable.co.jp) * @author Ito Kazumitsu (ito.kazumitsu@hitachi-cable.co.jp)
* @author Dalibor Topic (robilad@kaffe.org) * @author Dalibor Topic (robilad@kaffe.org)
* @author Michael Koch (konqueror@gmx.de) * @author Michael Koch (konqueror@gmx.de)
* @since 1.4 * @since 1.4
*/ */
public final class URI public final class URI implements Comparable, Serializable
implements Comparable, Serializable
{ {
static final long serialVersionUID = -6052424284110960213L; static final long serialVersionUID = -6052424284110960213L;
...@@ -70,11 +70,14 @@ public final class URI ...@@ -70,11 +70,14 @@ public final class URI
private static final String RFC2396_DIGIT = "0123456789"; private static final String RFC2396_DIGIT = "0123456789";
private static final String RFC2396_LOWALPHA = "abcdefghijklmnopqrstuvwxyz"; private static final String RFC2396_LOWALPHA = "abcdefghijklmnopqrstuvwxyz";
private static final String RFC2396_UPALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; private static final String RFC2396_UPALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private static final String RFC2396_ALPHA = RFC2396_LOWALPHA + RFC2396_UPALPHA; private static final String RFC2396_ALPHA =
RFC2396_LOWALPHA + RFC2396_UPALPHA;
private static final String RFC2396_ALPHANUM = RFC2396_DIGIT + RFC2396_ALPHA; private static final String RFC2396_ALPHANUM = RFC2396_DIGIT + RFC2396_ALPHA;
private static final String RFC2396_MARK = "-_.!~*'()"; private static final String RFC2396_MARK = "-_.!~*'()";
private static final String RFC2396_UNRESERVED = RFC2396_ALPHANUM + RFC2396_MARK; private static final String RFC2396_UNRESERVED =
private static final String RFC2396_REG_NAME = RFC2396_UNRESERVED + "$,;:@&=+"; RFC2396_ALPHANUM + RFC2396_MARK;
private static final String RFC2396_REG_NAME =
RFC2396_UNRESERVED + "$,;:@&=+";
private static final String RFC2396_PCHAR = RFC2396_UNRESERVED + ":@&=+$,"; private static final String RFC2396_PCHAR = RFC2396_UNRESERVED + ":@&=+$,";
private static final String RFC2396_SEGMENT = RFC2396_PCHAR + ";"; private static final String RFC2396_SEGMENT = RFC2396_PCHAR + ";";
private static final String RFC2396_PATH_SEGMENTS = RFC2396_SEGMENT + "/"; private static final String RFC2396_PATH_SEGMENTS = RFC2396_SEGMENT + "/";
...@@ -108,7 +111,6 @@ public final class URI ...@@ -108,7 +111,6 @@ public final class URI
* Index of fragment component in parsed URI. * Index of fragment component in parsed URI.
*/ */
private static final int FRAGMENT_GROUP = 10; private static final int FRAGMENT_GROUP = 10;
private String scheme; private String scheme;
private String rawSchemeSpecificPart; private String rawSchemeSpecificPart;
private String schemeSpecificPart; private String schemeSpecificPart;
...@@ -126,17 +128,17 @@ public final class URI ...@@ -126,17 +128,17 @@ public final class URI
private String rawFragment; private String rawFragment;
private String fragment; private String fragment;
private void readObject (ObjectInputStream is) private void readObject(ObjectInputStream is)
throws ClassNotFoundException, IOException throws ClassNotFoundException, IOException
{ {
} }
private void writeObject (ObjectOutputStream is) private void writeObject(ObjectOutputStream is) throws IOException
throws IOException
{ {
} }
private static String getURIGroup (Matcher match, int group) { private static String getURIGroup(Matcher match, int group)
{
String matched = match.group(group); String matched = match.group(group);
return matched.length() == 0 ? null : matched; return matched.length() == 0 ? null : matched;
} }
...@@ -148,8 +150,7 @@ public final class URI ...@@ -148,8 +150,7 @@ public final class URI
* *
* @exception URISyntaxException If the given string violates RFC 2396 * @exception URISyntaxException If the given string violates RFC 2396
*/ */
private void parseURI (String str) private void parseURI(String str) throws URISyntaxException
throws URISyntaxException
{ {
Pattern pattern = Pattern.compile(URI_REGEXP); Pattern pattern = Pattern.compile(URI_REGEXP);
Matcher matcher = pattern.matcher(str); Matcher matcher = pattern.matcher(str);
...@@ -163,8 +164,8 @@ public final class URI ...@@ -163,8 +164,8 @@ public final class URI
rawFragment = getURIGroup(matcher, FRAGMENT_GROUP); rawFragment = getURIGroup(matcher, FRAGMENT_GROUP);
} }
else else
throw new URISyntaxException(str, throw new URISyntaxException(str, "doesn't match URI regular expression");
"doesn't match URI regular expression");
// We must eagerly unquote the parts, because this is the only time // We must eagerly unquote the parts, because this is the only time
// we may throw an exception. // we may throw an exception.
schemeSpecificPart = unquote(rawSchemeSpecificPart); schemeSpecificPart = unquote(rawSchemeSpecificPart);
...@@ -184,18 +185,19 @@ public final class URI ...@@ -184,18 +185,19 @@ public final class URI
* @exception URISyntaxException If the given string contains invalid * @exception URISyntaxException If the given string contains invalid
* escape sequences. * escape sequences.
*/ */
private static String unquote (String str) private static String unquote(String str) throws URISyntaxException
throws URISyntaxException
{ {
if (str == null) if (str == null)
return null; return null;
byte[] buf = new byte[str.length()]; byte[] buf = new byte[str.length()];
int pos = 0; int pos = 0;
for (int i = 0; i < str.length(); i++) { for (int i = 0; i < str.length(); i++)
{
char c = str.charAt(i); char c = str.charAt(i);
if (c > 127) if (c > 127)
throw new URISyntaxException(str, "Invalid character"); throw new URISyntaxException(str, "Invalid character");
if (c == '%') { if (c == '%')
{
if (i + 2 >= str.length()) if (i + 2 >= str.length())
throw new URISyntaxException(str, "Invalid quoted character"); throw new URISyntaxException(str, "Invalid quoted character");
String hex = "0123456789ABCDEF"; String hex = "0123456789ABCDEF";
...@@ -203,15 +205,18 @@ public final class URI ...@@ -203,15 +205,18 @@ public final class URI
int lo = hex.indexOf(str.charAt(++i)); int lo = hex.indexOf(str.charAt(++i));
if (lo < 0 || hi < 0) if (lo < 0 || hi < 0)
throw new URISyntaxException(str, "Invalid quoted character"); throw new URISyntaxException(str, "Invalid quoted character");
buf[pos++] = (byte)(hi * 16 + lo); buf[pos++] = (byte) (hi * 16 + lo);
} else {
buf[pos++] = (byte)c;
} }
else
buf[pos++] = (byte) c;
} }
try { try
{
return new String(buf, 0, pos, "utf-8"); return new String(buf, 0, pos, "utf-8");
} catch (java.io.UnsupportedEncodingException x2) { }
throw (Error)new InternalError().initCause(x2); catch (java.io.UnsupportedEncodingException x2)
{
throw (Error) new InternalError().initCause(x2);
} }
} }
...@@ -226,7 +231,8 @@ public final class URI ...@@ -226,7 +231,8 @@ public final class URI
* *
* @return The quoted string. * @return The quoted string.
*/ */
private static String quote (String str) { private static String quote(String str)
{
// FIXME: unimplemented. // FIXME: unimplemented.
return str; return str;
} }
...@@ -242,7 +248,8 @@ public final class URI ...@@ -242,7 +248,8 @@ public final class URI
* *
* @return The quoted string. * @return The quoted string.
*/ */
private static String quoteAuthority (String str) { private static String quoteAuthority(String str)
{
// Technically, we should be using RFC2396_AUTHORITY, but // Technically, we should be using RFC2396_AUTHORITY, but
// it contains no additional characters. // it contains no additional characters.
return quote(str, RFC2396_REG_NAME); return quote(str, RFC2396_REG_NAME);
...@@ -260,33 +267,35 @@ public final class URI ...@@ -260,33 +267,35 @@ public final class URI
* *
* @return The quoted string. * @return The quoted string.
*/ */
private static String quote (String str, String legalCharacters) private static String quote(String str, String legalCharacters)
{ {
StringBuffer sb = new StringBuffer(str.length()); StringBuffer sb = new StringBuffer(str.length());
for (int i = 0; i < str.length(); i++) { for (int i = 0; i < str.length(); i++)
{
char c = str.charAt(i); char c = str.charAt(i);
if (legalCharacters.indexOf(c) == -1) { if (legalCharacters.indexOf(c) == -1)
{
String hex = "0123456789ABCDEF"; String hex = "0123456789ABCDEF";
if (c <= 127) { if (c <= 127)
sb.append('%') sb.append('%').append(hex.charAt(c / 16)).append(hex.charAt(c % 16));
.append(hex.charAt(c / 16)) else
.append(hex.charAt(c % 16)); {
} else { try
try { {
// this is far from optimal, but it works // this is far from optimal, but it works
byte[] utf8 = str.substring(i, i + 1).getBytes("utf-8"); byte[] utf8 = str.substring(i, i + 1).getBytes("utf-8");
for (int j = 0; j < utf8.length; j++) { for (int j = 0; j < utf8.length; j++)
sb.append('%') sb.append('%').append(hex.charAt((utf8[j] & 0xff) / 16))
.append(hex.charAt((utf8[j] & 0xff) / 16))
.append(hex.charAt((utf8[j] & 0xff) % 16)); .append(hex.charAt((utf8[j] & 0xff) % 16));
} }
} catch (java.io.UnsupportedEncodingException x) { catch (java.io.UnsupportedEncodingException x)
throw (Error)new InternalError().initCause(x); {
throw (Error) new InternalError().initCause(x);
} }
} }
} else {
sb.append(c);
} }
else
sb.append(c);
} }
return sb.toString(); return sb.toString();
} }
...@@ -302,7 +311,8 @@ public final class URI ...@@ -302,7 +311,8 @@ public final class URI
* *
* @return The quoted string. * @return The quoted string.
*/ */
private static String quoteHost (String str) { private static String quoteHost(String str)
{
// FIXME: unimplemented. // FIXME: unimplemented.
return str; return str;
} }
...@@ -318,7 +328,8 @@ public final class URI ...@@ -318,7 +328,8 @@ public final class URI
* *
* @return The quoted string. * @return The quoted string.
*/ */
private static String quotePath (String str) { private static String quotePath(String str)
{
// Technically, we should be using RFC2396_PATH, but // Technically, we should be using RFC2396_PATH, but
// it contains no additional characters. // it contains no additional characters.
return quote(str, RFC2396_PATH_SEGMENTS); return quote(str, RFC2396_PATH_SEGMENTS);
...@@ -335,7 +346,8 @@ public final class URI ...@@ -335,7 +346,8 @@ public final class URI
* *
* @return The quoted string. * @return The quoted string.
*/ */
private static String quoteUserInfo (String str) { private static String quoteUserInfo(String str)
{
// FIXME: unimplemented. // FIXME: unimplemented.
return str; return str;
} }
...@@ -348,8 +360,7 @@ public final class URI ...@@ -348,8 +360,7 @@ public final class URI
* @exception URISyntaxException If the given string violates RFC 2396 * @exception URISyntaxException If the given string violates RFC 2396
* @exception NullPointerException If str is null * @exception NullPointerException If str is null
*/ */
public URI (String str) public URI(String str) throws URISyntaxException
throws URISyntaxException
{ {
parseURI(str); parseURI(str);
} }
...@@ -367,11 +378,11 @@ public final class URI ...@@ -367,11 +378,11 @@ public final class URI
* *
* @exception URISyntaxException If the given string violates RFC 2396 * @exception URISyntaxException If the given string violates RFC 2396
*/ */
public URI (String scheme, String userInfo, String host, int port, public URI(String scheme, String userInfo, String host, int port,
String path, String query, String fragment) String path, String query, String fragment)
throws URISyntaxException throws URISyntaxException
{ {
this((scheme == null ? "" : scheme + ":" ) this((scheme == null ? "" : scheme + ":")
+ (userInfo == null && host == null && port == -1 ? "" : "//") + (userInfo == null && host == null && port == -1 ? "" : "//")
+ (userInfo == null ? "" : quoteUserInfo(userInfo) + "@") + (userInfo == null ? "" : quoteUserInfo(userInfo) + "@")
+ (host == null ? "" : quoteHost(host)) + (host == null ? "" : quoteHost(host))
...@@ -394,9 +405,8 @@ public final class URI ...@@ -394,9 +405,8 @@ public final class URI
* *
* @exception URISyntaxException If the given string violates RFC 2396 * @exception URISyntaxException If the given string violates RFC 2396
*/ */
public URI (String scheme, String authority, String path, String query, public URI(String scheme, String authority, String path, String query,
String fragment) String fragment) throws URISyntaxException
throws URISyntaxException
{ {
this((scheme == null ? "" : scheme + ":") this((scheme == null ? "" : scheme + ":")
+ (authority == null ? "" : "//" + quoteAuthority(authority)) + (authority == null ? "" : "//" + quoteAuthority(authority))
...@@ -415,7 +425,7 @@ public final class URI ...@@ -415,7 +425,7 @@ public final class URI
* *
* @exception URISyntaxException If the given string violates RFC 2396 * @exception URISyntaxException If the given string violates RFC 2396
*/ */
public URI (String scheme, String host, String path, String fragment) public URI(String scheme, String host, String path, String fragment)
throws URISyntaxException throws URISyntaxException
{ {
this(scheme, null, host, -1, path, null, fragment); this(scheme, null, host, -1, path, null, fragment);
...@@ -430,7 +440,7 @@ public final class URI ...@@ -430,7 +440,7 @@ public final class URI
* *
* @exception URISyntaxException If the given string violates RFC 2396 * @exception URISyntaxException If the given string violates RFC 2396
*/ */
public URI (String scheme, String ssp, String fragment) public URI(String scheme, String ssp, String fragment)
throws URISyntaxException throws URISyntaxException
{ {
this((scheme == null ? "" : scheme + ":") this((scheme == null ? "" : scheme + ":")
...@@ -446,16 +456,16 @@ public final class URI ...@@ -446,16 +456,16 @@ public final class URI
* @exception IllegalArgumentException If the given string violates RFC 2396 * @exception IllegalArgumentException If the given string violates RFC 2396
* @exception NullPointerException If str is null * @exception NullPointerException If str is null
*/ */
public static URI create (String str) public static URI create(String str)
{ {
try try
{ {
return new URI(str); return new URI(str);
} }
catch(URISyntaxException e) catch (URISyntaxException e)
{ {
throw (IllegalArgumentException) throw (IllegalArgumentException) new IllegalArgumentException()
new IllegalArgumentException().initCause(e); .initCause(e);
} }
} }
...@@ -465,8 +475,7 @@ public final class URI ...@@ -465,8 +475,7 @@ public final class URI
* *
* @exception URISyntaxException If the given string violates RFC 2396 * @exception URISyntaxException If the given string violates RFC 2396
*/ */
public URI parseServerAuthority () public URI parseServerAuthority() throws URISyntaxException
throws URISyntaxException
{ {
return null; return null;
} }
...@@ -474,7 +483,7 @@ public final class URI ...@@ -474,7 +483,7 @@ public final class URI
/** /**
* Returns a normalizes versions of the URI * Returns a normalizes versions of the URI
*/ */
public URI normalize () public URI normalize()
{ {
return null; return null;
} }
...@@ -489,7 +498,7 @@ public final class URI ...@@ -489,7 +498,7 @@ public final class URI
* *
* @exception NullPointerException If uri is null * @exception NullPointerException If uri is null
*/ */
public URI resolve (URI uri) public URI resolve(URI uri)
{ {
if (uri.isAbsolute()) if (uri.isAbsolute())
return uri; return uri;
...@@ -505,9 +514,8 @@ public final class URI ...@@ -505,9 +514,8 @@ public final class URI
try try
{ {
if (fragment != null && if (fragment != null && path != null && path.equals("")
path != null && path.equals("") && && scheme == null && authority == null && query == null)
scheme == null && authority == null && query == null)
return new URI(this.scheme, this.schemeSpecificPart, fragment); return new URI(this.scheme, this.schemeSpecificPart, fragment);
if (authority == null) if (authority == null)
...@@ -515,13 +523,13 @@ public final class URI ...@@ -515,13 +523,13 @@ public final class URI
authority = this.authority; authority = this.authority;
if (path == null) if (path == null)
path = ""; path = "";
if (!(path.startsWith("/"))) if (! (path.startsWith("/")))
{ {
StringBuffer basepath = new StringBuffer(this.path); StringBuffer basepath = new StringBuffer(this.path);
int i = this.path.lastIndexOf('/'); int i = this.path.lastIndexOf('/');
if (i >= 0) if (i >= 0)
basepath.delete(i+1, basepath.length()); basepath.delete(i + 1, basepath.length());
basepath.append(path); basepath.append(path);
path = basepath.toString(); path = basepath.toString();
...@@ -548,8 +556,7 @@ public final class URI ...@@ -548,8 +556,7 @@ public final class URI
* violates RFC 2396 * violates RFC 2396
* @exception NullPointerException If uri is null * @exception NullPointerException If uri is null
*/ */
public URI resolve (String str) public URI resolve(String str) throws IllegalArgumentException
throws IllegalArgumentException
{ {
return resolve(create(str)); return resolve(create(str));
} }
...@@ -563,7 +570,7 @@ public final class URI ...@@ -563,7 +570,7 @@ public final class URI
* *
* @exception NullPointerException If uri is null * @exception NullPointerException If uri is null
*/ */
public URI relativize (URI uri) public URI relativize(URI uri)
{ {
return null; return null;
} }
...@@ -575,8 +582,7 @@ public final class URI ...@@ -575,8 +582,7 @@ public final class URI
* not be found, or if some other error occurred while constructing the URL * not be found, or if some other error occurred while constructing the URL
* @exception IllegalArgumentException If the URI is not absolute * @exception IllegalArgumentException If the URI is not absolute
*/ */
public URL toURL () public URL toURL() throws IllegalArgumentException, MalformedURLException
throws IllegalArgumentException, MalformedURLException
{ {
if (isAbsolute()) if (isAbsolute())
return new URL(this.toString()); return new URL(this.toString());
...@@ -587,7 +593,7 @@ public final class URI ...@@ -587,7 +593,7 @@ public final class URI
/** /**
* Returns the scheme of the URI * Returns the scheme of the URI
*/ */
public String getScheme () public String getScheme()
{ {
return scheme; return scheme;
} }
...@@ -595,7 +601,7 @@ public final class URI ...@@ -595,7 +601,7 @@ public final class URI
/** /**
* Tells whether this URI is absolute or not * Tells whether this URI is absolute or not
*/ */
public boolean isAbsolute () public boolean isAbsolute()
{ {
return (scheme != null); return (scheme != null);
} }
...@@ -603,16 +609,16 @@ public final class URI ...@@ -603,16 +609,16 @@ public final class URI
/** /**
* Tell whether this URI is opaque or not * Tell whether this URI is opaque or not
*/ */
public boolean isOpaque () public boolean isOpaque()
{ {
return ((scheme != null) && !(schemeSpecificPart.startsWith("/"))); return ((scheme != null) && ! (schemeSpecificPart.startsWith("/")));
} }
/** /**
* Returns the raw scheme specific part of this URI. * Returns the raw scheme specific part of this URI.
* The scheme-specific part is never undefined, though it may be empty * The scheme-specific part is never undefined, though it may be empty
*/ */
public String getRawSchemeSpecificPart () public String getRawSchemeSpecificPart()
{ {
return rawSchemeSpecificPart; return rawSchemeSpecificPart;
} }
...@@ -620,7 +626,7 @@ public final class URI ...@@ -620,7 +626,7 @@ public final class URI
/** /**
* Returns the decoded scheme specific part of this URI. * Returns the decoded scheme specific part of this URI.
*/ */
public String getSchemeSpecificPart () public String getSchemeSpecificPart()
{ {
return schemeSpecificPart; return schemeSpecificPart;
} }
...@@ -628,7 +634,7 @@ public final class URI ...@@ -628,7 +634,7 @@ public final class URI
/** /**
* Returns the rae authority part of this URI * Returns the rae authority part of this URI
*/ */
public String getRawAuthority () public String getRawAuthority()
{ {
return rawAuthority; return rawAuthority;
} }
...@@ -636,7 +642,7 @@ public final class URI ...@@ -636,7 +642,7 @@ public final class URI
/** /**
* Returns the decoded authority part of this URI * Returns the decoded authority part of this URI
*/ */
public String getAuthority () public String getAuthority()
{ {
return authority; return authority;
} }
...@@ -644,7 +650,7 @@ public final class URI ...@@ -644,7 +650,7 @@ public final class URI
/** /**
* Returns the raw user info part of this URI * Returns the raw user info part of this URI
*/ */
public String getRawUserInfo () public String getRawUserInfo()
{ {
return rawUserInfo; return rawUserInfo;
} }
...@@ -652,7 +658,7 @@ public final class URI ...@@ -652,7 +658,7 @@ public final class URI
/** /**
* Returns the decoded user info part of this URI * Returns the decoded user info part of this URI
*/ */
public String getUserInfo () public String getUserInfo()
{ {
return userInfo; return userInfo;
} }
...@@ -660,7 +666,7 @@ public final class URI ...@@ -660,7 +666,7 @@ public final class URI
/** /**
* Returns the hostname of the URI * Returns the hostname of the URI
*/ */
public String getHost () public String getHost()
{ {
return host; return host;
} }
...@@ -668,7 +674,7 @@ public final class URI ...@@ -668,7 +674,7 @@ public final class URI
/** /**
* Returns the port number of the URI * Returns the port number of the URI
*/ */
public int getPort () public int getPort()
{ {
return port; return port;
} }
...@@ -676,7 +682,7 @@ public final class URI ...@@ -676,7 +682,7 @@ public final class URI
/** /**
* Returns the raw path part of this URI * Returns the raw path part of this URI
*/ */
public String getRawPath () public String getRawPath()
{ {
return rawPath; return rawPath;
} }
...@@ -684,7 +690,7 @@ public final class URI ...@@ -684,7 +690,7 @@ public final class URI
/** /**
* Returns the path of the URI * Returns the path of the URI
*/ */
public String getPath () public String getPath()
{ {
return path; return path;
} }
...@@ -692,7 +698,7 @@ public final class URI ...@@ -692,7 +698,7 @@ public final class URI
/** /**
* Returns the raw query part of this URI * Returns the raw query part of this URI
*/ */
public String getRawQuery () public String getRawQuery()
{ {
return rawQuery; return rawQuery;
} }
...@@ -700,7 +706,7 @@ public final class URI ...@@ -700,7 +706,7 @@ public final class URI
/** /**
* Returns the query of the URI * Returns the query of the URI
*/ */
public String getQuery () public String getQuery()
{ {
return query; return query;
} }
...@@ -708,7 +714,7 @@ public final class URI ...@@ -708,7 +714,7 @@ public final class URI
/** /**
* Return the raw fragment part of this URI * Return the raw fragment part of this URI
*/ */
public String getRawFragment () public String getRawFragment()
{ {
return rawFragment; return rawFragment;
} }
...@@ -716,7 +722,7 @@ public final class URI ...@@ -716,7 +722,7 @@ public final class URI
/** /**
* Returns the fragment of the URI * Returns the fragment of the URI
*/ */
public String getFragment () public String getFragment()
{ {
return fragment; return fragment;
} }
...@@ -734,7 +740,7 @@ public final class URI ...@@ -734,7 +740,7 @@ public final class URI
/** /**
* Computes the hascode of the URI * Computes the hascode of the URI
*/ */
public int hashCode () public int hashCode()
{ {
return 0; return 0;
} }
...@@ -746,8 +752,7 @@ public final class URI ...@@ -746,8 +752,7 @@ public final class URI
* *
* @exception ClassCastException If given object ist not an URI * @exception ClassCastException If given object ist not an URI
*/ */
public int compareTo (Object obj) public int compareTo(Object obj) throws ClassCastException
throws ClassCastException
{ {
return 0; return 0;
} }
...@@ -755,7 +760,7 @@ public final class URI ...@@ -755,7 +760,7 @@ public final class URI
/** /**
* Returns the URI as string * Returns the URI as string
*/ */
public String toString () public String toString()
{ {
return (getScheme() == null ? "" : getScheme() + ":") return (getScheme() == null ? "" : getScheme() + ":")
+ (getRawAuthority() == null ? "" : "//" + getRawAuthority()) + (getRawAuthority() == null ? "" : "//" + getRawAuthority())
...@@ -767,7 +772,7 @@ public final class URI ...@@ -767,7 +772,7 @@ public final class URI
/** /**
* Returns the URI as US-ASCII string * Returns the URI as US-ASCII string
*/ */
public String toASCIIString () public String toASCIIString()
{ {
return ""; return "";
} }
......
...@@ -37,6 +37,7 @@ exception statement from your version. */ ...@@ -37,6 +37,7 @@ exception statement from your version. */
package java.net; package java.net;
/** /**
* This exception is thrown when a String cannot be parsed as a URI. * This exception is thrown when a String cannot be parsed as a URI.
* *
...@@ -137,7 +138,7 @@ public class URISyntaxException extends Exception ...@@ -137,7 +138,7 @@ public class URISyntaxException extends Exception
*/ */
public String getMessage() public String getMessage()
{ {
return super.getMessage() + (index >= 0 ? " at index " + index : "") return (super.getMessage() + (index >= 0 ? " at index " + index : "")
+ ": " + input; + ": " + input);
} }
} }
...@@ -35,18 +35,18 @@ this exception to your version of the library, but you are not ...@@ -35,18 +35,18 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
import gnu.java.net.URLParseError; import gnu.java.net.URLParseError;
import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.InputStream;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.StringTokenizer; import java.util.StringTokenizer;
/* /*
* Written using on-line Java Platform 1.2 API Specification, as well * Written using on-line Java Platform 1.2 API Specification, as well
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
...@@ -171,7 +171,6 @@ public final class URL implements Serializable ...@@ -171,7 +171,6 @@ public final class URL implements Serializable
* where we keep track of it. * where we keep track of it.
*/ */
private static URLStreamHandlerFactory factory; private static URLStreamHandlerFactory factory;
private static final long serialVersionUID = -7627629688361524110L; private static final long serialVersionUID = -7627629688361524110L;
/** /**
...@@ -187,7 +186,7 @@ public final class URL implements Serializable ...@@ -187,7 +186,7 @@ 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;
...@@ -231,7 +230,6 @@ public final class URL implements Serializable ...@@ -231,7 +230,6 @@ public final class URL implements Serializable
this(protocol, host, -1, file, null); this(protocol, host, -1, file, null);
} }
/** /**
* This method initializes a new instance of <code>URL</code> with the * This method initializes a new instance of <code>URL</code> with the
* specified protocol, host, port, and file. Additionally, this method * specified protocol, host, port, and file. Additionally, this method
...@@ -254,9 +252,8 @@ public final class URL implements Serializable ...@@ -254,9 +252,8 @@ public final class URL implements Serializable
* *
* @since 1.2 * @since 1.2
*/ */
public URL (String protocol, String host, int port, String file, public URL(String protocol, String host, int port, String file,
URLStreamHandler ph) URLStreamHandler ph) throws MalformedURLException
throws MalformedURLException
{ {
if (protocol == null) if (protocol == null)
throw new MalformedURLException("null protocol"); throw new MalformedURLException("null protocol");
...@@ -266,7 +263,7 @@ public final class URL implements Serializable ...@@ -266,7 +263,7 @@ public final class URL implements Serializable
{ {
SecurityManager s = System.getSecurityManager(); SecurityManager s = System.getSecurityManager();
if (s != null) if (s != null)
s.checkPermission (new NetPermission ("specifyStreamHandler")); s.checkPermission(new NetPermission("specifyStreamHandler"));
this.ph = ph; this.ph = ph;
} }
...@@ -274,8 +271,8 @@ public final class URL implements Serializable ...@@ -274,8 +271,8 @@ public final class URL implements Serializable
this.ph = getURLStreamHandler(protocol); this.ph = getURLStreamHandler(protocol);
if (this.ph == null) if (this.ph == null)
throw new MalformedURLException ( throw new MalformedURLException("Protocol handler not found: "
"Protocol handler not found: " + protocol); + protocol);
this.host = host; this.host = host;
this.port = port; this.port = port;
...@@ -380,13 +377,13 @@ public final class URL implements Serializable ...@@ -380,13 +377,13 @@ public final class URL implements Serializable
// right after the "://". The second colon is for an optional port value // right after the "://". The second colon is for an optional port value
// and implies that the host from the context is used if available. // and implies that the host from the context is used if available.
int colon; int colon;
if ((colon = spec.indexOf("://", 1)) > 0 && if ((colon = spec.indexOf("://", 1)) > 0
! spec.regionMatches(colon, "://:", 0, 4)) && ! spec.regionMatches(colon, "://:", 0, 4))
context = null; context = null;
int slash; int slash;
if ((colon = spec.indexOf(':')) > 0 && if ((colon = spec.indexOf(':')) > 0
(colon < (slash = spec.indexOf('/')) || slash < 0)) && (colon < (slash = spec.indexOf('/')) || slash < 0))
{ {
// Protocol specified in spec string. // Protocol specified in spec string.
protocol = spec.substring(0, colon).toLowerCase(); protocol = spec.substring(0, colon).toLowerCase();
...@@ -415,14 +412,15 @@ public final class URL implements Serializable ...@@ -415,14 +412,15 @@ public final class URL implements Serializable
authority = context.authority; authority = context.authority;
} }
else // Protocol NOT specified in spec. and no context available. else // Protocol NOT specified in spec. and no context available.
throw new
MalformedURLException("Absolute URL required with null context");
throw new MalformedURLException("Absolute URL required with null context");
if (ph != null) if (ph != null)
{ {
SecurityManager s = System.getSecurityManager (); SecurityManager s = System.getSecurityManager();
if (s != null) if (s != null)
s.checkPermission (new NetPermission ("specifyStreamHandler")); s.checkPermission(new NetPermission("specifyStreamHandler"));
this.ph = ph; this.ph = ph;
} }
...@@ -460,16 +458,16 @@ public final class URL implements Serializable ...@@ -460,16 +458,16 @@ public final class URL implements Serializable
* exactly (ie, protocol, host, port, file, and ref). Overrides * exactly (ie, protocol, host, port, file, and ref). Overrides
* Object.equals(), implemented by calling the equals method of the handler. * Object.equals(), implemented by calling the equals method of the handler.
* *
* @param url The URL to compare with * @param obj The URL to compare with
* *
* @return true if the URL is equal, false otherwise * @return true if the URL is equal, false otherwise
*/ */
public boolean equals (Object obj) public boolean equals(Object obj)
{ {
if (! (obj instanceof URL)) if (! (obj instanceof URL))
return false; return false;
return ph.equals (this, (URL) obj); return ph.equals(this, (URL) obj);
} }
/** /**
...@@ -602,7 +600,7 @@ public final class URL implements Serializable ...@@ -602,7 +600,7 @@ public final class URL implements Serializable
* *
* @return the user at a particular host or null when no user defined. * @return the user at a particular host or null when no user defined.
*/ */
public String getUserInfo () public String getUserInfo()
{ {
int at = (host == null) ? -1 : host.indexOf('@'); int at = (host == null) ? -1 : host.indexOf('@');
return at < 0 ? null : host.substring(0, at); return at < 0 ? null : host.substring(0, at);
...@@ -614,7 +612,7 @@ public final class URL implements Serializable ...@@ -614,7 +612,7 @@ public final class URL implements Serializable
* *
* @return the query part of the file, or null when there is no query part. * @return the query part of the file, or null when there is no query part.
*/ */
public String getQuery () public String getQuery()
{ {
int quest = (file == null) ? -1 : file.indexOf('?'); int quest = (file == null) ? -1 : file.indexOf('?');
return quest < 0 ? null : file.substring(quest + 1, file.length()); return quest < 0 ? null : file.substring(quest + 1, file.length());
...@@ -630,7 +628,7 @@ public final class URL implements Serializable ...@@ -630,7 +628,7 @@ public final class URL implements Serializable
if (hashCode != 0) if (hashCode != 0)
return hashCode; // Use cached value if available. return hashCode; // Use cached value if available.
else else
return ph.hashCode (this); return ph.hashCode(this);
} }
/** /**
...@@ -670,9 +668,9 @@ public final class URL implements Serializable ...@@ -670,9 +668,9 @@ public final class URL implements Serializable
* *
* @return true if URL matches this URL's file, false otherwise * @return true if URL matches this URL's file, false otherwise
*/ */
public boolean sameFile(URL other) public boolean sameFile(URL url)
{ {
return ph.sameFile(this, other); return ph.sameFile(this, url);
} }
/** /**
...@@ -720,9 +718,8 @@ public final class URL implements Serializable ...@@ -720,9 +718,8 @@ public final class URL implements Serializable
* *
* @since 1.3 * @since 1.3
*/ */
protected void set(String protocol, String host, int port, protected void set(String protocol, String host, int port, String authority,
String authority, String userInfo, String userInfo, String path, String query, String ref)
String path, String query, String ref)
{ {
// TBD: Theoretically, a poorly written StreamHandler could pass an // TBD: Theoretically, a poorly written StreamHandler could pass an
// invalid protocol. It will cause the handler to be set to null // invalid protocol. It will cause the handler to be set to null
...@@ -754,8 +751,7 @@ public final class URL implements Serializable ...@@ -754,8 +751,7 @@ public final class URL implements Serializable
* @exception SecurityException If a security manager exists and its * @exception SecurityException If a security manager exists and its
* checkSetFactory method doesn't allow the operation * checkSetFactory method doesn't allow the operation
*/ */
public static synchronized void public static synchronized void setURLStreamHandlerFactory(URLStreamHandlerFactory fac)
setURLStreamHandlerFactory(URLStreamHandlerFactory fac)
{ {
if (factory != null) if (factory != null)
throw new Error("URLStreamHandlerFactory already set"); throw new Error("URLStreamHandlerFactory already set");
...@@ -801,15 +797,14 @@ public final class URL implements Serializable ...@@ -801,15 +797,14 @@ public final class URL implements Serializable
* *
* @return A URLStreamHandler for this protocol, or null when not found. * @return A URLStreamHandler for this protocol, or null when not found.
*/ */
private static synchronized URLStreamHandler private static synchronized URLStreamHandler getURLStreamHandler(String protocol)
getURLStreamHandler (String protocol)
{ {
URLStreamHandler ph = null; URLStreamHandler ph = null;
// 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;
} }
...@@ -855,18 +850,18 @@ public final class URL implements Serializable ...@@ -855,18 +850,18 @@ public final class URL implements Serializable
ph_search_path = DEFAULT_SEARCH_PATH; ph_search_path = DEFAULT_SEARCH_PATH;
// Finally loop through our search path looking for a match. // Finally loop through our search path looking for a match.
StringTokenizer pkgPrefix = new StringTokenizer (ph_search_path, "|"); StringTokenizer pkgPrefix = new StringTokenizer(ph_search_path, "|");
do do
{ {
String clsName = (pkgPrefix.nextToken() + "." String clsName =
+ protocol + ".Handler"); (pkgPrefix.nextToken() + "." + protocol + ".Handler");
try try
{ {
Object obj = Class.forName (clsName).newInstance(); Object obj = Class.forName(clsName).newInstance();
if (!(obj instanceof URLStreamHandler)) if (! (obj instanceof URLStreamHandler))
continue; continue;
else else
ph = (URLStreamHandler) obj; ph = (URLStreamHandler) obj;
...@@ -882,10 +877,9 @@ public final class URL implements Serializable ...@@ -882,10 +877,9 @@ public final class URL implements Serializable
} }
// Update the hashtable with the new protocol handler. // Update the hashtable with the new protocol handler.
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;
......
...@@ -35,7 +35,6 @@ this exception to your version of the library, but you are not ...@@ -35,7 +35,6 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
...@@ -43,24 +42,25 @@ import java.io.EOFException; ...@@ -43,24 +42,25 @@ import java.io.EOFException;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FilePermission; import java.io.FilePermission;
import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
import java.security.AccessController; import java.io.InputStream;
import java.security.AccessControlContext; import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.CodeSource; import java.security.CodeSource;
import java.security.SecureClassLoader;
import java.security.PrivilegedAction;
import java.security.PermissionCollection; import java.security.PermissionCollection;
import java.security.PrivilegedAction;
import java.security.SecureClassLoader;
import java.security.cert.Certificate; import java.security.cert.Certificate;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Vector;
import java.util.HashMap; import java.util.HashMap;
import java.util.Vector;
import java.util.jar.Attributes; import java.util.jar.Attributes;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.jar.Manifest; import java.util.jar.Manifest;
import gnu.gcj.runtime.SharedLibHelper; import gnu.gcj.runtime.SharedLibHelper;
/** /**
* A secure class loader that can load classes and resources from * A secure class loader that can load classes and resources from
* multiple locations. Given an array of <code>URL</code>s this class * multiple locations. Given an array of <code>URL</code>s this class
...@@ -118,7 +118,6 @@ import gnu.gcj.runtime.SharedLibHelper; ...@@ -118,7 +118,6 @@ import gnu.gcj.runtime.SharedLibHelper;
* @author Mark Wielaard (mark@klomp.org) * @author Mark Wielaard (mark@klomp.org)
* @author Wu Gansha (gansha.wu@intel.com) * @author Wu Gansha (gansha.wu@intel.com)
*/ */
public class URLClassLoader extends SecureClassLoader public class URLClassLoader extends SecureClassLoader
{ {
// Class Variables // Class Variables
...@@ -166,7 +165,7 @@ public class URLClassLoader extends SecureClassLoader ...@@ -166,7 +165,7 @@ public class URLClassLoader extends SecureClassLoader
* A <code>URLLoader</code> contains all logic to load resources from a * A <code>URLLoader</code> contains all logic to load resources from a
* given base <code>URL</code>. * given base <code>URL</code>.
*/ */
static abstract class URLLoader abstract static class URLLoader
{ {
/** /**
* Our classloader to get info from if needed. * Our classloader to get info from if needed.
...@@ -230,7 +229,7 @@ public class URLClassLoader extends SecureClassLoader ...@@ -230,7 +229,7 @@ public class URLClassLoader extends SecureClassLoader
* <code>InputStream</code>) that is necessary for loading resources * <code>InputStream</code>) that is necessary for loading resources
* and creating classes from a <code>URL</code>. * and creating classes from a <code>URL</code>.
*/ */
static abstract class Resource abstract static class Resource
{ {
final URLLoader loader; final URLLoader loader;
final String name; final String name;
...@@ -285,7 +284,7 @@ public class URLClassLoader extends SecureClassLoader ...@@ -285,7 +284,7 @@ public class URLClassLoader extends SecureClassLoader
* A <code>JarURLLoader</code> is a type of <code>URLLoader</code> * A <code>JarURLLoader</code> is a type of <code>URLLoader</code>
* only loading from jar url. * only loading from jar url.
*/ */
final static class JarURLLoader extends URLLoader static final class JarURLLoader extends URLLoader
{ {
final JarFile jarfile; // The jar file for this url final JarFile jarfile; // The jar file for this url
final URL baseJarURL; // Base jar: url for all resources loaded from jar final URL baseJarURL; // Base jar: url for all resources loaded from jar
...@@ -306,12 +305,16 @@ public class URLClassLoader extends SecureClassLoader ...@@ -306,12 +305,16 @@ public class URLClassLoader extends SecureClassLoader
JarFile jarfile = null; JarFile jarfile = null;
try try
{ {
baseJarURL baseJarURL =
= new URL(null, jarURL, classloader.getURLStreamHandler("jar")); new URL(null, jarURL, classloader.getURLStreamHandler("jar"));
jarfile
= ((JarURLConnection) baseJarURL.openConnection()).getJarFile(); jarfile =
((JarURLConnection) baseJarURL.openConnection()).getJarFile();
}
catch (IOException ioe)
{
/* ignored */
} }
catch (IOException ioe) { /* ignored */ }
this.baseJarURL = baseJarURL; this.baseJarURL = baseJarURL;
this.jarfile = jarfile; this.jarfile = jarfile;
...@@ -327,7 +330,7 @@ public class URLClassLoader extends SecureClassLoader ...@@ -327,7 +330,7 @@ public class URLClassLoader extends SecureClassLoader
name = name.substring(1); name = name.substring(1);
JarEntry je = jarfile.getJarEntry(name); JarEntry je = jarfile.getJarEntry(name);
if(je != null) if (je != null)
return new JarURLResource(this, name, je); return new JarURLResource(this, name, je);
else else
return null; return null;
...@@ -346,7 +349,7 @@ public class URLClassLoader extends SecureClassLoader ...@@ -346,7 +349,7 @@ public class URLClassLoader extends SecureClassLoader
} }
} }
final static class JarURLResource extends Resource static final class JarURLResource extends Resource
{ {
private final JarEntry entry; private final JarEntry entry;
...@@ -358,12 +361,12 @@ public class URLClassLoader extends SecureClassLoader ...@@ -358,12 +361,12 @@ public class URLClassLoader extends SecureClassLoader
InputStream getInputStream() throws IOException InputStream getInputStream() throws IOException
{ {
return ((JarURLLoader)loader).jarfile.getInputStream(entry); return ((JarURLLoader) loader).jarfile.getInputStream(entry);
} }
int getLength() int getLength()
{ {
return (int)entry.getSize(); return (int) entry.getSize();
} }
Certificate[] getCertificates() Certificate[] getCertificates()
...@@ -375,10 +378,10 @@ public class URLClassLoader extends SecureClassLoader ...@@ -375,10 +378,10 @@ public class URLClassLoader extends SecureClassLoader
{ {
try try
{ {
return new URL(((JarURLLoader)loader).baseJarURL, name, return new URL(((JarURLLoader) loader).baseJarURL, name,
loader.classloader.getURLStreamHandler("jar")); loader.classloader.getURLStreamHandler("jar"));
} }
catch(MalformedURLException e) catch (MalformedURLException e)
{ {
InternalError ie = new InternalError(); InternalError ie = new InternalError();
ie.initCause(e); ie.initCause(e);
...@@ -390,9 +393,9 @@ public class URLClassLoader extends SecureClassLoader ...@@ -390,9 +393,9 @@ public class URLClassLoader extends SecureClassLoader
/** /**
* Loader for remote directories. * Loader for remote directories.
*/ */
final static class RemoteURLLoader extends URLLoader static final class RemoteURLLoader extends URLLoader
{ {
final private String protocol; private final String protocol;
RemoteURLLoader(URLClassLoader classloader, URL url) RemoteURLLoader(URLClassLoader classloader, URL url)
{ {
...@@ -408,8 +411,8 @@ public class URLClassLoader extends SecureClassLoader ...@@ -408,8 +411,8 @@ public class URLClassLoader extends SecureClassLoader
{ {
try try
{ {
URL url = new URL(baseURL, name, URL url =
classloader.getURLStreamHandler(protocol)); new URL(baseURL, name, classloader.getURLStreamHandler(protocol));
URLConnection connection = url.openConnection(); URLConnection connection = url.openConnection();
// Open the connection and check the stream // Open the connection and check the stream
...@@ -420,9 +423,9 @@ public class URLClassLoader extends SecureClassLoader ...@@ -420,9 +423,9 @@ public class URLClassLoader extends SecureClassLoader
// We can do some extra checking if it is a http request // We can do some extra checking if it is a http request
if (connection instanceof HttpURLConnection) if (connection instanceof HttpURLConnection)
{ {
int response int response =
= ((HttpURLConnection)connection).getResponseCode(); ((HttpURLConnection) connection).getResponseCode();
if (response/100 != 2) if (response / 100 != 2)
return null; return null;
} }
...@@ -441,11 +444,11 @@ public class URLClassLoader extends SecureClassLoader ...@@ -441,11 +444,11 @@ public class URLClassLoader extends SecureClassLoader
/** /**
* A resource from some remote location. * A resource from some remote location.
*/ */
final static class RemoteResource extends Resource static final class RemoteResource extends Resource
{ {
final private URL url; private final URL url;
final private InputStream stream; private final InputStream stream;
final private int length; private final int length;
RemoteResource(RemoteURLLoader loader, String name, URL url, RemoteResource(RemoteURLLoader loader, String name, URL url,
InputStream stream, int length) InputStream stream, int length)
...@@ -533,7 +536,7 @@ public class URLClassLoader extends SecureClassLoader ...@@ -533,7 +536,7 @@ public class URLClassLoader extends SecureClassLoader
* A <code>FileURLLoader</code> is a type of <code>URLLoader</code> * A <code>FileURLLoader</code> is a type of <code>URLLoader</code>
* only loading from file url. * only loading from file url.
*/ */
final static class FileURLLoader extends URLLoader static final class FileURLLoader extends URLLoader
{ {
File dir; //the file for this file url File dir; //the file for this file url
...@@ -547,13 +550,13 @@ public class URLClassLoader extends SecureClassLoader ...@@ -547,13 +550,13 @@ public class URLClassLoader extends SecureClassLoader
Resource getResource(String name) Resource getResource(String name)
{ {
File file = new File(dir, name); File file = new File(dir, name);
if (file.exists() && !file.isDirectory()) if (file.exists() && ! file.isDirectory())
return new FileResource(this, name, file); return new FileResource(this, name, file);
return null; return null;
} }
} }
final static class FileResource extends Resource static final class FileResource extends Resource
{ {
final File file; final File file;
...@@ -570,7 +573,7 @@ public class URLClassLoader extends SecureClassLoader ...@@ -570,7 +573,7 @@ public class URLClassLoader extends SecureClassLoader
public int getLength() public int getLength()
{ {
return (int)file.length(); return (int) file.length();
} }
public URL getURL() public URL getURL()
...@@ -580,7 +583,7 @@ public class URLClassLoader extends SecureClassLoader ...@@ -580,7 +583,7 @@ public class URLClassLoader extends SecureClassLoader
return new URL(loader.baseURL, name, return new URL(loader.baseURL, name,
loader.classloader.getURLStreamHandler("file")); loader.classloader.getURLStreamHandler("file"));
} }
catch(MalformedURLException e) catch (MalformedURLException e)
{ {
InternalError ie = new InternalError(); InternalError ie = new InternalError();
ie.initCause(e); ie.initCause(e);
...@@ -698,8 +701,7 @@ public class URLClassLoader extends SecureClassLoader ...@@ -698,8 +701,7 @@ public class URLClassLoader extends SecureClassLoader
* @param factory Used to get the protocol handler for the URLs. * @param factory Used to get the protocol handler for the URLs.
* @see SecureClassLoader * @see SecureClassLoader
*/ */
public URLClassLoader(URL[] urls, public URLClassLoader(URL[] urls, ClassLoader parent,
ClassLoader parent,
URLStreamHandlerFactory factory) URLStreamHandlerFactory factory)
throws SecurityException throws SecurityException
{ {
...@@ -711,7 +713,7 @@ public class URLClassLoader extends SecureClassLoader ...@@ -711,7 +713,7 @@ public class URLClassLoader extends SecureClassLoader
// If this factory is still not in factoryCache, add it, // If this factory is still not in factoryCache, add it,
// since we only support three protocols so far, 5 is enough // since we only support three protocols so far, 5 is enough
// for cache initial size // for cache initial size
synchronized(factoryCache) synchronized (factoryCache)
{ {
if (factory != null && factoryCache.get(factory) == null) if (factory != null && factoryCache.get(factory) == null)
factoryCache.put(factory, new HashMap(5)); factoryCache.put(factory, new HashMap(5));
...@@ -731,14 +733,14 @@ public class URLClassLoader extends SecureClassLoader ...@@ -731,14 +733,14 @@ public class URLClassLoader extends SecureClassLoader
private void addURLImpl(URL newUrl) private void addURLImpl(URL newUrl)
{ {
synchronized(urlloaders) synchronized (urlloaders)
{ {
if (newUrl == null) if (newUrl == null)
return; // Silently ignore... return; // Silently ignore...
// Check global cache to see if there're already url loader // Check global cache to see if there're already url loader
// for this url. // for this url.
URLLoader loader = (URLLoader)urlloaders.get(newUrl); URLLoader loader = (URLLoader) urlloaders.get(newUrl);
if (loader == null) if (loader == null)
{ {
String file = newUrl.getFile(); String file = newUrl.getFile();
...@@ -769,10 +771,8 @@ public class URLClassLoader extends SecureClassLoader ...@@ -769,10 +771,8 @@ public class URLClassLoader extends SecureClassLoader
private void addURLs(URL[] newUrls) private void addURLs(URL[] newUrls)
{ {
for (int i = 0; i < newUrls.length; i++) for (int i = 0; i < newUrls.length; i++)
{
addURLImpl(newUrls[i]); addURLImpl(newUrls[i]);
} }
}
/** /**
* Defines a Package based on the given name and the supplied manifest * Defines a Package based on the given name and the supplied manifest
...@@ -793,18 +793,12 @@ public class URLClassLoader extends SecureClassLoader ...@@ -793,18 +793,12 @@ public class URLClassLoader extends SecureClassLoader
throws IllegalArgumentException throws IllegalArgumentException
{ {
Attributes attr = manifest.getMainAttributes(); Attributes attr = manifest.getMainAttributes();
String specTitle = String specTitle = attr.getValue(Attributes.Name.SPECIFICATION_TITLE);
attr.getValue(Attributes.Name.SPECIFICATION_TITLE); String specVersion = attr.getValue(Attributes.Name.SPECIFICATION_VERSION);
String specVersion = String specVendor = attr.getValue(Attributes.Name.SPECIFICATION_VENDOR);
attr.getValue(Attributes.Name.SPECIFICATION_VERSION); String implTitle = attr.getValue(Attributes.Name.IMPLEMENTATION_TITLE);
String specVendor = String implVersion = attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
attr.getValue(Attributes.Name.SPECIFICATION_VENDOR); String implVendor = attr.getValue(Attributes.Name.IMPLEMENTATION_VENDOR);
String implTitle =
attr.getValue(Attributes.Name.IMPLEMENTATION_TITLE);
String implVersion =
attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
String implVendor =
attr.getValue(Attributes.Name.IMPLEMENTATION_VENDOR);
// Look if the Manifest indicates that this package is sealed // Look if the Manifest indicates that this package is sealed
// XXX - most likely not completely correct! // XXX - most likely not completely correct!
...@@ -813,13 +807,11 @@ public class URLClassLoader extends SecureClassLoader ...@@ -813,13 +807,11 @@ public class URLClassLoader extends SecureClassLoader
// But how do we get that jar manifest here? // But how do we get that jar manifest here?
String sealed = attr.getValue(Attributes.Name.SEALED); String sealed = attr.getValue(Attributes.Name.SEALED);
if ("false".equals(sealed)) if ("false".equals(sealed))
{
// make sure that the URL is null so the package is not sealed // make sure that the URL is null so the package is not sealed
url = null; url = null;
}
return definePackage(name, specTitle, specVersion, specVendor, return definePackage(name, specTitle, specVersion, specVendor, implTitle,
implTitle, implVersion, implVendor, url); implVersion, implVendor, url);
} }
/** /**
...@@ -857,7 +849,7 @@ public class URLClassLoader extends SecureClassLoader ...@@ -857,7 +849,7 @@ public class URLClassLoader extends SecureClassLoader
// construct the class (and watch out for those nasty IOExceptions) // construct the class (and watch out for those nasty IOExceptions)
try try
{ {
byte [] data; byte[] data;
InputStream in = resource.getInputStream(); InputStream in = resource.getInputStream();
int length = resource.getLength(); int length = resource.getLength();
if (length != -1) if (length != -1)
...@@ -906,8 +898,8 @@ public class URLClassLoader extends SecureClassLoader ...@@ -906,8 +898,8 @@ public class URLClassLoader extends SecureClassLoader
// define the package // define the package
Manifest manifest = resource.loader.getManifest(); Manifest manifest = resource.loader.getManifest();
if (manifest == null) if (manifest == null)
definePackage(packageName, definePackage(packageName, null, null, null, null, null, null,
null, null, null, null, null, null, null); null);
else else
definePackage(packageName, manifest, resource.loader.baseURL); definePackage(packageName, manifest, resource.loader.baseURL);
} }
...@@ -928,9 +920,7 @@ public class URLClassLoader extends SecureClassLoader ...@@ -928,9 +920,7 @@ public class URLClassLoader extends SecureClassLoader
}, securityContext); }, securityContext);
} }
else else
return defineClass(className, classData, return defineClass(className, classData, 0, classData.length, source);
0, classData.length,
source);
} }
catch (IOException ioe) catch (IOException ioe)
{ {
...@@ -950,7 +940,7 @@ public class URLClassLoader extends SecureClassLoader ...@@ -950,7 +940,7 @@ public class URLClassLoader extends SecureClassLoader
int max = urls.size(); int max = urls.size();
for (int i = 0; i < max; i++) for (int i = 0; i < max; i++)
{ {
URLLoader loader = (URLLoader)urlinfos.elementAt(i); URLLoader loader = (URLLoader) urlinfos.elementAt(i);
if (loader == null) if (loader == null)
continue; continue;
...@@ -993,9 +983,9 @@ public class URLClassLoader extends SecureClassLoader ...@@ -993,9 +983,9 @@ public class URLClassLoader extends SecureClassLoader
synchronized (factoryCache) synchronized (factoryCache)
{ {
// Check if there're handler for the same protocol in cache. // Check if there're handler for the same protocol in cache.
HashMap cache = (HashMap)factoryCache.get(factory); HashMap cache = (HashMap) factoryCache.get(factory);
handler = (URLStreamHandler)cache.get(protocol); handler = (URLStreamHandler) cache.get(protocol);
if(handler == null) if (handler == null)
{ {
// Add it to cache. // Add it to cache.
handler = factory.createURLStreamHandler(protocol); handler = factory.createURLStreamHandler(protocol);
...@@ -1014,13 +1004,14 @@ public class URLClassLoader extends SecureClassLoader ...@@ -1014,13 +1004,14 @@ public class URLClassLoader extends SecureClassLoader
* @return a (possible empty) enumeration of URLs where the resource can be * @return a (possible empty) enumeration of URLs where the resource can be
* found * found
*/ */
public Enumeration findResources(String resourceName) throws IOException public Enumeration findResources(String resourceName)
throws IOException
{ {
Vector resources = new Vector(); Vector resources = new Vector();
int max = urls.size(); int max = urls.size();
for (int i = 0; i < max; i++) for (int i = 0; i < max; i++)
{ {
URLLoader loader = (URLLoader)urlinfos.elementAt(i); URLLoader loader = (URLLoader) urlinfos.elementAt(i);
Resource resource = loader.getResource(resourceName); Resource resource = loader.getResource(resourceName);
if (resource != null) if (resource != null)
resources.add(resource.getURL()); resources.add(resource.getURL());
...@@ -1052,7 +1043,6 @@ public class URLClassLoader extends SecureClassLoader ...@@ -1052,7 +1043,6 @@ public class URLClassLoader extends SecureClassLoader
{ {
// XXX - This implementation does exactly as the Javadoc describes. // XXX - This implementation does exactly as the Javadoc describes.
// But maybe we should/could use URLConnection.getPermissions()? // But maybe we should/could use URLConnection.getPermissions()?
// First get the permissions that would normally be granted // First get the permissions that would normally be granted
PermissionCollection permissions = super.getPermissions(source); PermissionCollection permissions = super.getPermissions(source);
...@@ -1062,6 +1052,7 @@ public class URLClassLoader extends SecureClassLoader ...@@ -1062,6 +1052,7 @@ public class URLClassLoader extends SecureClassLoader
if (protocol.equals("file")) if (protocol.equals("file"))
{ {
String file = url.getFile(); String file = url.getFile();
// If the file end in / it must be an directory. // If the file end in / it must be an directory.
if (file.endsWith("/") || file.endsWith(File.separator)) if (file.endsWith("/") || file.endsWith(File.separator))
{ {
...@@ -1109,7 +1100,7 @@ public class URLClassLoader extends SecureClassLoader ...@@ -1109,7 +1100,7 @@ public class URLClassLoader extends SecureClassLoader
* @exception SecurityException when the calling code does not have * @exception SecurityException when the calling code does not have
* permission to access the given <code>URL</code>s * permission to access the given <code>URL</code>s
*/ */
public static URLClassLoader newInstance(URL urls[]) public static URLClassLoader newInstance(URL[] urls)
throws SecurityException throws SecurityException
{ {
return newInstance(urls, null); return newInstance(urls, null);
...@@ -1127,8 +1118,7 @@ public class URLClassLoader extends SecureClassLoader ...@@ -1127,8 +1118,7 @@ public class URLClassLoader extends SecureClassLoader
* @exception SecurityException when the calling code does not have * @exception SecurityException when the calling code does not have
* permission to access the given <code>URL</code>s * permission to access the given <code>URL</code>s
*/ */
public static URLClassLoader newInstance(URL urls[], public static URLClassLoader newInstance(URL[] urls, final ClassLoader parent)
final ClassLoader parent)
throws SecurityException throws SecurityException
{ {
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
...@@ -1137,19 +1127,19 @@ public class URLClassLoader extends SecureClassLoader ...@@ -1137,19 +1127,19 @@ public class URLClassLoader extends SecureClassLoader
else else
{ {
final Object securityContext = sm.getSecurityContext(); final Object securityContext = sm.getSecurityContext();
// XXX - What to do with anything else then an AccessControlContext? // XXX - What to do with anything else then an AccessControlContext?
if (!(securityContext instanceof AccessControlContext)) if (! (securityContext instanceof AccessControlContext))
throw new SecurityException throw new SecurityException("securityContext must be AccessControlContext: "
("securityContext must be AccessControlContext: "
+ securityContext); + securityContext);
URLClassLoader loader = URLClassLoader loader =
(URLClassLoader)AccessController.doPrivileged(new PrivilegedAction() (URLClassLoader) AccessController.doPrivileged(new PrivilegedAction()
{ {
public Object run() public Object run()
{ {
return new URLClassLoader return new URLClassLoader(parent,
(parent, (AccessControlContext)securityContext); (AccessControlContext) securityContext);
} }
}); });
loader.addURLs(urls); loader.addURLs(urls);
......
...@@ -35,11 +35,10 @@ this exception to your version of the library, but you are not ...@@ -35,11 +35,10 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.security.AllPermission; import java.security.AllPermission;
import java.security.Permission; import java.security.Permission;
...@@ -53,13 +52,13 @@ import java.util.Map; ...@@ -53,13 +52,13 @@ import java.util.Map;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import gnu.gcj.io.MimeTypes; import gnu.gcj.io.MimeTypes;
/** /**
* Written using on-line Java Platform 1.2 API Specification, as well * Written using on-line Java Platform 1.2 API Specification, as well
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
* Status: One guessContentTypeFrom... methods not implemented. * Status: One guessContentTypeFrom... methods not implemented.
* getContent method assumes content type from response; see comment there. * getContent method assumes content type from response; see comment there.
*/ */
/** /**
* This class models a connection that retrieves the information pointed * This class models a connection that retrieves the information pointed
* to by a URL object. This is typically a connection to a remote node * to by a URL object. This is typically a connection to a remote node
...@@ -188,6 +187,8 @@ public abstract class URLConnection ...@@ -188,6 +187,8 @@ public abstract class URLConnection
/** /**
* Establishes the actual connection to the URL associated with this * Establishes the actual connection to the URL associated with this
* connection object * connection object
*
* @exception IOException if an error occurs
*/ */
public abstract void connect() throws IOException; public abstract void connect() throws IOException;
...@@ -295,7 +296,7 @@ public abstract class URLConnection ...@@ -295,7 +296,7 @@ public abstract class URLConnection
* Returns a String representing the value of the header field having * Returns a String representing the value of the header field having
* the named key. Returns null if the header field does not exist. * the named key. Returns null if the header field does not exist.
* *
* @param The key of the header field * @param name The key of the header field
* *
* @return The value of the header field as a String * @return The value of the header field as a String
*/ */
...@@ -308,6 +309,8 @@ public abstract class URLConnection ...@@ -308,6 +309,8 @@ public abstract class URLConnection
/** /**
* Returns a map of all sent header fields * Returns a map of all sent header fields
* *
* @return all header fields
*
* @since 1.4 * @since 1.4
*/ */
public Map getHeaderFields() public Map getHeaderFields()
...@@ -330,14 +333,14 @@ public abstract class URLConnection ...@@ -330,14 +333,14 @@ public abstract class URLConnection
*/ */
public int getHeaderFieldInt(String name, int defaultValue) public int getHeaderFieldInt(String name, int defaultValue)
{ {
String value = getHeaderField (name); String value = getHeaderField(name);
if (value == null) if (value == null)
return defaultValue; return defaultValue;
try try
{ {
return Integer.parseInt (value); return Integer.parseInt(value);
} }
catch (NumberFormatException e) catch (NumberFormatException e)
{ {
...@@ -357,23 +360,23 @@ public abstract class URLConnection ...@@ -357,23 +360,23 @@ public abstract class URLConnection
* @return Returns the date value of the header filed or the default value * @return Returns the date value of the header filed or the default value
* if the field is missing or malformed * if the field is missing or malformed
*/ */
public long getHeaderFieldDate (String name, long defaultValue) public long getHeaderFieldDate(String name, long defaultValue)
{ {
if (! dateformats_initialized) if (! dateformats_initialized)
initializeDateFormats (); initializeDateFormats();
long result = defaultValue; long result = defaultValue;
String str = getHeaderField (name); String str = getHeaderField(name);
if (str != null) if (str != null)
{ {
Date date; Date date;
if ((date = dateFormat1.parse (str, new ParsePosition (0))) != null) if ((date = dateFormat1.parse(str, new ParsePosition(0))) != null)
result = date.getTime (); result = date.getTime();
else if ((date = dateFormat2.parse (str, new ParsePosition (0))) != null) else if ((date = dateFormat2.parse(str, new ParsePosition(0))) != null)
result = date.getTime (); result = date.getTime();
else if ((date = dateFormat3.parse (str, new ParsePosition (0))) != null) else if ((date = dateFormat3.parse(str, new ParsePosition(0))) != null)
result = date.getTime (); result = date.getTime();
} }
return result; return result;
...@@ -390,7 +393,7 @@ public abstract class URLConnection ...@@ -390,7 +393,7 @@ public abstract class URLConnection
* @return The header field key or null if index is past the end * @return The header field key or null if index is past the end
* of the headers. * of the headers.
*/ */
public String getHeaderFieldKey (int index) public String getHeaderFieldKey(int index)
{ {
// Subclasses for specific protocols override this. // Subclasses for specific protocols override this.
return null; return null;
...@@ -407,7 +410,7 @@ public abstract class URLConnection ...@@ -407,7 +410,7 @@ public abstract class URLConnection
* This class first determines the MIME type of the content, then creates * This class first determines the MIME type of the content, then creates
* a ContentHandler object to process the input. If the ContentHandlerFactory * a ContentHandler object to process the input. If the ContentHandlerFactory
* is set, then that object is called to load a content handler, otherwise * is set, then that object is called to load a content handler, otherwise
* a class called gnu.java.net.content.<content_type> is tried. * a class called gnu.java.net.content.&lt;content_type&gt; is tried.
* The default class will also be used if the content handler factory returns * The default class will also be used if the content handler factory returns
* a null content handler. * a null content handler.
* *
...@@ -436,6 +439,8 @@ public abstract class URLConnection ...@@ -436,6 +439,8 @@ public abstract class URLConnection
/** /**
* Retrieves the content of this URLConnection * Retrieves the content of this URLConnection
* *
* @param classes The allowed classes for the content
*
* @exception IOException If an error occurs * @exception IOException If an error occurs
* @exception UnknownServiceException If the protocol does not support the * @exception UnknownServiceException If the protocol does not support the
* content type * content type
...@@ -443,7 +448,7 @@ public abstract class URLConnection ...@@ -443,7 +448,7 @@ public abstract class URLConnection
public Object getContent(Class[] classes) throws IOException public Object getContent(Class[] classes) throws IOException
{ {
// FIXME: implement this // FIXME: implement this
return getContent (); return getContent();
} }
/** /**
...@@ -480,8 +485,8 @@ public abstract class URLConnection ...@@ -480,8 +485,8 @@ public abstract class URLConnection
public InputStream getInputStream() throws IOException public InputStream getInputStream() throws IOException
{ {
// Subclasses for specific protocols override this. // Subclasses for specific protocols override this.
throw new UnknownServiceException("Protocol " + url.getProtocol() + throw new UnknownServiceException("Protocol " + url.getProtocol()
" does not support input."); + " does not support input.");
} }
/** /**
...@@ -496,8 +501,8 @@ public abstract class URLConnection ...@@ -496,8 +501,8 @@ public abstract class URLConnection
public OutputStream getOutputStream() throws IOException public OutputStream getOutputStream() throws IOException
{ {
// Subclasses for specific protocols override this. // Subclasses for specific protocols override this.
throw new UnknownServiceException("Protocol " + url.getProtocol() + throw new UnknownServiceException("Protocol " + url.getProtocol()
" does not support output."); + " does not support output.");
} }
/** /**
...@@ -524,7 +529,7 @@ public abstract class URLConnection ...@@ -524,7 +529,7 @@ public abstract class URLConnection
public void setDoInput(boolean input) public void setDoInput(boolean input)
{ {
if (connected) if (connected)
throw new IllegalStateException ("Already connected"); throw new IllegalStateException("Already connected");
doInput = input; doInput = input;
} }
...@@ -553,7 +558,7 @@ public abstract class URLConnection ...@@ -553,7 +558,7 @@ public abstract class URLConnection
public void setDoOutput(boolean output) public void setDoOutput(boolean output)
{ {
if (connected) if (connected)
throw new IllegalStateException ("Already connected"); throw new IllegalStateException("Already connected");
doOutput = output; doOutput = output;
} }
...@@ -628,7 +633,7 @@ public abstract class URLConnection ...@@ -628,7 +633,7 @@ public abstract class URLConnection
public void setUseCaches(boolean usecaches) public void setUseCaches(boolean usecaches)
{ {
if (connected) if (connected)
throw new IllegalStateException ("Already connected"); throw new IllegalStateException("Already connected");
useCaches = usecaches; useCaches = usecaches;
} }
...@@ -659,7 +664,7 @@ public abstract class URLConnection ...@@ -659,7 +664,7 @@ public abstract class URLConnection
public void setIfModifiedSince(long ifmodifiedsince) public void setIfModifiedSince(long ifmodifiedsince)
{ {
if (connected) if (connected)
throw new IllegalStateException ("Already connected"); throw new IllegalStateException("Already connected");
ifModifiedSince = ifmodifiedsince; ifModifiedSince = ifmodifiedsince;
} }
...@@ -695,9 +700,9 @@ public abstract class URLConnection ...@@ -695,9 +700,9 @@ public abstract class URLConnection
* *
* @param use true to use caches if possible by default, false otherwise * @param use true to use caches if possible by default, false otherwise
*/ */
public void setDefaultUseCaches(boolean defaultusecaches) public void setDefaultUseCaches(boolean use)
{ {
defaultUseCaches = defaultusecaches; defaultUseCaches = use;
} }
/** /**
...@@ -717,10 +722,10 @@ public abstract class URLConnection ...@@ -717,10 +722,10 @@ public abstract class URLConnection
public void setRequestProperty(String key, String value) public void setRequestProperty(String key, String value)
{ {
if (connected) if (connected)
throw new IllegalStateException ("Already connected"); throw new IllegalStateException("Already connected");
if (key == null) if (key == null)
throw new NullPointerException ("key is null"); throw new NullPointerException("key is null");
// Do nothing unless overridden by subclasses that support setting // Do nothing unless overridden by subclasses that support setting
// header fields in the request. // header fields in the request.
...@@ -744,10 +749,10 @@ public abstract class URLConnection ...@@ -744,10 +749,10 @@ public abstract class URLConnection
public void addRequestProperty(String key, String value) public void addRequestProperty(String key, String value)
{ {
if (connected) if (connected)
throw new IllegalStateException ("Already connected"); throw new IllegalStateException("Already connected");
if (key == null) if (key == null)
throw new NullPointerException ("key is null"); throw new NullPointerException("key is null");
// Do nothing unless overridden by subclasses that support adding // Do nothing unless overridden by subclasses that support adding
// header fields in the request. // header fields in the request.
...@@ -768,7 +773,7 @@ public abstract class URLConnection ...@@ -768,7 +773,7 @@ public abstract class URLConnection
public String getRequestProperty(String key) public String getRequestProperty(String key)
{ {
if (connected) if (connected)
throw new IllegalStateException ("Already connected"); throw new IllegalStateException("Already connected");
// Overridden by subclasses that support reading header fields from the // Overridden by subclasses that support reading header fields from the
// request. // request.
...@@ -787,7 +792,7 @@ public abstract class URLConnection ...@@ -787,7 +792,7 @@ public abstract class URLConnection
public Map getRequestProperties() public Map getRequestProperties()
{ {
if (connected) if (connected)
throw new IllegalStateException ("Already connected"); throw new IllegalStateException("Already connected");
// Overridden by subclasses that support reading header fields from the // Overridden by subclasses that support reading header fields from the
// request. // request.
...@@ -807,7 +812,7 @@ public abstract class URLConnection ...@@ -807,7 +812,7 @@ public abstract class URLConnection
* *
* @see URLConnection#setRequestProperty(String key, String value) * @see URLConnection#setRequestProperty(String key, String value)
*/ */
public static void setDefaultRequestProperty (String key, String value) public static void setDefaultRequestProperty(String key, String value)
{ {
// This method does nothing since JDK 1.3. // This method does nothing since JDK 1.3.
} }
...@@ -844,10 +849,9 @@ public abstract class URLConnection ...@@ -844,10 +849,9 @@ public abstract class URLConnection
* @exception SecurityException If a security manager exists and its * @exception SecurityException If a security manager exists and its
* checkSetFactory method doesn't allow the operation * checkSetFactory method doesn't allow the operation
*/ */
public static synchronized void setContentHandlerFactory public static synchronized void setContentHandlerFactory(ContentHandlerFactory factory)
(ContentHandlerFactory fac)
{ {
if (factory != null) if (URLConnection.factory != null)
throw new Error("ContentHandlerFactory already set"); throw new Error("ContentHandlerFactory already set");
// Throw an exception if an extant security mgr precludes // Throw an exception if an extant security mgr precludes
...@@ -856,7 +860,7 @@ public abstract class URLConnection ...@@ -856,7 +860,7 @@ public abstract class URLConnection
if (s != null) if (s != null)
s.checkSetFactory(); s.checkSetFactory();
factory = fac; URLConnection.factory = factory;
} }
/** /**
...@@ -1040,10 +1044,10 @@ public abstract class URLConnection ...@@ -1040,10 +1044,10 @@ public abstract class URLConnection
return; return;
Locale locale = new Locale("En", "Us", "Unix"); Locale locale = new Locale("En", "Us", "Unix");
dateFormat1 = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'", dateFormat1 =
locale); new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'", locale);
dateFormat2 = new SimpleDateFormat("EEEE, dd-MMM-yy hh:mm:ss 'GMT'", dateFormat2 =
locale); new SimpleDateFormat("EEEE, dd-MMM-yy hh:mm:ss 'GMT'", locale);
dateFormat3 = new SimpleDateFormat("EEE MMM d hh:mm:ss yyyy", locale); dateFormat3 = new SimpleDateFormat("EEE MMM d hh:mm:ss yyyy", locale);
dateformats_initialized = true; dateformats_initialized = true;
} }
......
...@@ -39,6 +39,7 @@ package java.net; ...@@ -39,6 +39,7 @@ package java.net;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
/** /**
* This utility class contains static methods that converts a * This utility class contains static methods that converts a
* string encoded in the x-www-form-urlencoded format to the original * string encoded in the x-www-form-urlencoded format to the original
...@@ -65,7 +66,7 @@ public class URLDecoder ...@@ -65,7 +66,7 @@ public class URLDecoder
/** /**
* Public contructor. Note that this class has only static methods. * Public contructor. Note that this class has only static methods.
*/ */
public URLDecoder () public URLDecoder()
{ {
} }
...@@ -134,12 +135,12 @@ public class URLDecoder ...@@ -134,12 +135,12 @@ public class URLDecoder
start = i; start = i;
// Get all consecutive encoded bytes // Get all consecutive encoded bytes
while ((i+2 < length) && (str.charAt(i) == '%')) while ((i + 2 < length) && (str.charAt(i) == '%'))
i += 3; i += 3;
// Decode all these bytes // Decode all these bytes
if ((bytes == null) || (bytes.length < ((i-start)/3))) if ((bytes == null) || (bytes.length < ((i - start) / 3)))
bytes = new byte[((i-start)/3)]; bytes = new byte[((i - start) / 3)];
int index = 0; int index = 0;
try try
...@@ -147,7 +148,7 @@ public class URLDecoder ...@@ -147,7 +148,7 @@ public class URLDecoder
while (start < i) while (start < i)
{ {
String sub = str.substring(start + 1, start + 3); String sub = str.substring(start + 1, start + 3);
bytes[index] = (byte)Integer.parseInt(sub, 16); bytes[index] = (byte) Integer.parseInt(sub, 16);
index++; index++;
start += 3; start += 3;
} }
...@@ -176,5 +177,4 @@ public class URLDecoder ...@@ -176,5 +177,4 @@ public class URLDecoder
return result.toString(); return result.toString();
} }
} // class URLDecoder } // class URLDecoder
...@@ -39,13 +39,14 @@ package java.net; ...@@ -39,13 +39,14 @@ package java.net;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
/* /*
* Written using on-line Java Platform 1.2/1.4 API Specification, as well * Written using on-line Java Platform 1.2/1.4 API Specification, as well
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
* Status: Believed complete and correct. * Status: Believed complete and correct.
*/ */
/** /**
* This utility class contains static methods that converts a * This utility class contains static methods that converts a
* string into a fully encoded URL string in x-www-form-urlencoded * string into a fully encoded URL string in x-www-form-urlencoded
* format. This format replaces certain disallowed characters with * format. This format replaces certain disallowed characters with
...@@ -115,7 +116,7 @@ public class URLEncoder ...@@ -115,7 +116,7 @@ public class URLEncoder
StringBuffer result = new StringBuffer(length); StringBuffer result = new StringBuffer(length);
while (true) while (true)
{ {
while ( i < length && isSafe(s.charAt(i)) ) while (i < length && isSafe(s.charAt(i)))
i++; i++;
// Safe character can just be added // Safe character can just be added
...@@ -134,12 +135,12 @@ public class URLEncoder ...@@ -134,12 +135,12 @@ public class URLEncoder
// Get all unsafe characters // Get all unsafe characters
start = i; start = i;
char c; char c;
while ( i < length && (c = s.charAt(i)) != ' ' && !isSafe(c) ) while (i < length && (c = s.charAt(i)) != ' ' && ! isSafe(c))
i++; i++;
// Convert them to %XY encoded strings // Convert them to %XY encoded strings
String unsafe = s.substring(start,i); String unsafe = s.substring(start, i);
byte bytes[] = unsafe.getBytes(encoding); byte[] bytes = unsafe.getBytes(encoding);
for (int j = 0; j < bytes.length; j++) for (int j = 0; j < bytes.length; j++)
{ {
result.append('%'); result.append('%');
...@@ -160,17 +161,18 @@ public class URLEncoder ...@@ -160,17 +161,18 @@ public class URLEncoder
*/ */
private static boolean isSafe(char c) private static boolean isSafe(char c)
{ {
return ((c >= 'a' && c <= 'z') || return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
(c >= 'A' && c <= 'Z') || || (c >= '0' && c <= '9') || c == '-' || c == '_' || c == '.'
(c >= '0' && c <= '9') || || c == '*');
c == '-' || c == '_' || c == '.' || c == '*');
} }
/** /**
* Private constructor that does nothing. Included to avoid a default * Private constructor that does nothing. Included to avoid a default
* public constructor being created by the compiler. * public constructor being created by the compiler.
*/ */
private URLEncoder() { } private URLEncoder()
{
}
/** /**
* Used to convert to hex. We don't use Integer.toHexString, since * Used to convert to hex. We don't use Integer.toHexString, since
...@@ -179,4 +181,4 @@ public class URLEncoder ...@@ -179,4 +181,4 @@ public class URLEncoder
* leading 0. * leading 0.
*/ */
private static final String hex = "0123456789ABCDEF"; private static final String hex = "0123456789ABCDEF";
} // class URLEncoder }
...@@ -35,11 +35,11 @@ this exception to your version of the library, but you are not ...@@ -35,11 +35,11 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
import java.io.IOException;
import java.io.File; import java.io.File;
import java.io.IOException;
/* /*
* Written using on-line Java Platform 1.2 API Specification, as well * Written using on-line Java Platform 1.2 API Specification, as well
...@@ -79,7 +79,7 @@ public abstract class URLStreamHandler ...@@ -79,7 +79,7 @@ public abstract class URLStreamHandler
/** /**
* Creates a URLStreamHander * Creates a URLStreamHander
*/ */
public URLStreamHandler () public URLStreamHandler()
{ {
} }
...@@ -96,7 +96,7 @@ public abstract class URLStreamHandler ...@@ -96,7 +96,7 @@ public abstract class URLStreamHandler
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
protected abstract URLConnection openConnection(URL u) protected abstract URLConnection openConnection(URL url)
throws IOException; throws IOException;
/** /**
...@@ -127,27 +127,28 @@ public abstract class URLStreamHandler ...@@ -127,27 +127,28 @@ public abstract class URLStreamHandler
String file = url.getFile(); String file = url.getFile();
String ref = url.getRef(); String ref = url.getRef();
if (spec.regionMatches (start, "//", 0, 2)) if (spec.regionMatches(start, "//", 0, 2))
{ {
String genuineHost; String genuineHost;
int hostEnd; int hostEnd;
int colon, at_host; int colon;
int at_host;
start += 2; start += 2;
int slash = spec.indexOf ('/', start); int slash = spec.indexOf('/', start);
if (slash >= 0) if (slash >= 0)
hostEnd = slash; hostEnd = slash;
else else
hostEnd = end; hostEnd = end;
host = spec.substring (start, hostEnd); host = spec.substring(start, hostEnd);
// We first need a genuine host name (with userinfo). // We first need a genuine host name (with userinfo).
// So we check for '@': if it's present check the port in the // So we check for '@': if it's present check the port in the
// section after '@' in the other case check it in the full string. // section after '@' in the other case check it in the full string.
// P.S.: We don't care having '@' at the beginning of the string. // P.S.: We don't care having '@' at the beginning of the string.
if ((at_host = host.indexOf ('@')) >= 0) if ((at_host = host.indexOf('@')) >= 0)
genuineHost = host.substring (at_host); genuineHost = host.substring(at_host);
else else
genuineHost = host; genuineHost = host;
...@@ -157,22 +158,23 @@ public abstract class URLStreamHandler ...@@ -157,22 +158,23 @@ public abstract class URLStreamHandler
// this is undocumented and likely an unintended side effect in 1.2 // this is undocumented and likely an unintended side effect in 1.2
// so we'll be simple here and stick with "". Note that // so we'll be simple here and stick with "". Note that
// "http://" or "http:///" produce a "" host in JDK 1.2. // "http://" or "http:///" produce a "" host in JDK 1.2.
if ((colon = genuineHost.indexOf (':')) >= 0) if ((colon = genuineHost.indexOf(':')) >= 0)
{ {
try try
{ {
port = Integer.parseInt (genuineHost.substring (colon + 1)); port = Integer.parseInt(genuineHost.substring(colon + 1));
} }
catch (NumberFormatException e) catch (NumberFormatException e)
{ {
; // Ignore invalid port values; port is already set to u's ; // Ignore invalid port values; port is already set to u's
// port. // port.
} }
// Now we must cut the port number in the original string. // Now we must cut the port number in the original string.
if (at_host >= 0) if (at_host >= 0)
host = host.substring (0, at_host + colon); host = host.substring(0, at_host + colon);
else else
host = host.substring (0, colon); host = host.substring(0, colon);
} }
file = null; file = null;
start = hostEnd; start = hostEnd;
...@@ -192,28 +194,27 @@ public abstract class URLStreamHandler ...@@ -192,28 +194,27 @@ public abstract class URLStreamHandler
{ {
// Context is available, but only override it if there is a new file. // Context is available, but only override it if there is a new file.
char sepChar = '/'; char sepChar = '/';
int lastSlash = file.lastIndexOf (sepChar); int lastSlash = file.lastIndexOf(sepChar);
if (lastSlash < 0 && File.separatorChar != sepChar if (lastSlash < 0 && File.separatorChar != sepChar
&& url.getProtocol ().equals ("file")) && url.getProtocol().equals("file"))
{ {
// On Windows, even '\' is allowed in a "file" URL. // On Windows, even '\' is allowed in a "file" URL.
sepChar = File.separatorChar; sepChar = File.separatorChar;
lastSlash = file.lastIndexOf (sepChar); lastSlash = file.lastIndexOf(sepChar);
} }
file = file.substring(0, lastSlash) file =
+ sepChar + spec.substring (start, end); file.substring(0, lastSlash) + sepChar + spec.substring(start, end);
if (url.getProtocol ().equals ("file")) if (url.getProtocol().equals("file"))
{ {
// For "file" URLs constructed relative to a context, we // For "file" URLs constructed relative to a context, we
// need to canonicalise the file path. // need to canonicalise the file path.
try try
{ {
boolean endsWithSlash = file.charAt(file.length() - 1) == '/'; boolean endsWithSlash = file.charAt(file.length() - 1) == '/';
file = new File (file).getCanonicalPath (); file = new File(file).getCanonicalPath();
if (endsWithSlash if (endsWithSlash && file.charAt(file.length() - 1) != '/')
&& file.charAt(file.length() - 1) != '/')
file += '/'; file += '/';
} }
catch (IOException e) catch (IOException e)
...@@ -240,7 +241,6 @@ public abstract class URLStreamHandler ...@@ -240,7 +241,6 @@ public abstract class URLStreamHandler
// XXX - Classpath used to call PlatformHelper.toCanonicalForm() on // XXX - Classpath used to call PlatformHelper.toCanonicalForm() on
// the file part. It seems like overhead, but supposedly there is some // the file part. It seems like overhead, but supposedly there is some
// benefit in windows based systems (it also lowercased the string). // benefit in windows based systems (it also lowercased the string).
setURL(url, url.getProtocol(), host, port, file, ref); setURL(url, url.getProtocol(), host, port, file, ref);
} }
...@@ -251,7 +251,6 @@ public abstract class URLStreamHandler ...@@ -251,7 +251,6 @@ public abstract class URLStreamHandler
{ {
// XXX - GNU Classpath has an implementation that might be more appropriate // XXX - GNU Classpath has an implementation that might be more appropriate
// for Windows based systems (gnu.java.io.PlatformHelper.toCanonicalForm) // for Windows based systems (gnu.java.io.PlatformHelper.toCanonicalForm)
int index; int index;
// Replace "/./" with "/". This probably isn't very efficient in // Replace "/./" with "/". This probably isn't very efficient in
...@@ -287,19 +286,21 @@ public abstract class URLStreamHandler ...@@ -287,19 +286,21 @@ public abstract class URLStreamHandler
{ {
if (url1 == url2) if (url1 == url2)
return true; return true;
// This comparison is very conservative. It assumes that any // This comparison is very conservative. It assumes that any
// field can be null. // field can be null.
if (url1 == null || url2 == null) if (url1 == null || url2 == null)
return false; return false;
int p1 = url1.getPort (); int p1 = url1.getPort();
if (p1 == -1) if (p1 == -1)
p1 = url1.ph.getDefaultPort (); p1 = url1.ph.getDefaultPort();
int p2 = url2.getPort (); int p2 = url2.getPort();
if (p2 == -1) if (p2 == -1)
p2 = url2.ph.getDefaultPort (); p2 = url2.ph.getDefaultPort();
if (p1 != p2) if (p1 != p2)
return false; return false;
String s1, s2; String s1;
String s2;
s1 = url1.getProtocol(); s1 = url1.getProtocol();
s2 = url2.getProtocol(); s2 = url2.getProtocol();
if (s1 != s2 && (s1 == null || ! s1.equals(s2))) if (s1 != s2 && (s1 == null || ! s1.equals(s2)))
...@@ -372,32 +373,29 @@ public abstract class URLStreamHandler ...@@ -372,32 +373,29 @@ public abstract class URLStreamHandler
* *
* @return True if both given URLs are equal, false otherwise. * @return True if both given URLs are equal, false otherwise.
*/ */
protected boolean equals (URL url1, URL url2) protected boolean equals(URL url1, URL url2)
{ {
// This comparison is very conservative. It assumes that any // This comparison is very conservative. It assumes that any
// field can be null. // field can be null.
return (url1.getPort () == url2.getPort () return (url1.getPort() == url2.getPort()
&& ((url1.getProtocol () == null && url2.getProtocol () == null) && ((url1.getProtocol() == null && url2.getProtocol() == null)
|| (url1.getProtocol () != null || (url1.getProtocol() != null
&& url1.getProtocol ().equals (url2.getProtocol ()))) && url1.getProtocol().equals(url2.getProtocol())))
&& ((url1.getUserInfo () == null && url2.getUserInfo () == null) && ((url1.getUserInfo() == null && url2.getUserInfo() == null)
|| (url1.getUserInfo () != null || (url1.getUserInfo() != null
&& url1.getUserInfo ().equals(url2.getUserInfo ()))) && url1.getUserInfo().equals(url2.getUserInfo())))
&& ((url1.getAuthority () == null && url2.getAuthority () == null) && ((url1.getAuthority() == null && url2.getAuthority() == null)
|| (url1.getAuthority () != null || (url1.getAuthority() != null
&& url1.getAuthority ().equals(url2.getAuthority ()))) && url1.getAuthority().equals(url2.getAuthority())))
&& ((url1.getHost () == null && url2.getHost () == null) && ((url1.getHost() == null && url2.getHost() == null)
|| (url1.getHost () != null || (url1.getHost() != null && url1.getHost().equals(url2.getHost())))
&& url1.getHost ().equals(url2.getHost ()))) && ((url1.getPath() == null && url2.getPath() == null)
&& ((url1.getPath () == null && url2.getPath () == null) || (url1.getPath() != null && url1.getPath().equals(url2.getPath())))
|| (url1.getPath () != null && ((url1.getQuery() == null && url2.getQuery() == null)
&& url1.getPath ().equals (url2.getPath ()))) || (url1.getQuery() != null
&& ((url1.getQuery () == null && url2.getQuery () == null) && url1.getQuery().equals(url2.getQuery())))
|| (url1.getQuery () != null && ((url1.getRef() == null && url2.getRef() == null)
&& url1.getQuery ().equals(url2.getQuery ()))) || (url1.getRef() != null && url1.getRef().equals(url2.getRef()))));
&& ((url1.getRef () == null && url2.getRef () == null)
|| (url1.getRef () != null
&& url1.getRef ().equals(url2.getRef ()))));
} }
/** /**
...@@ -410,19 +408,19 @@ public abstract class URLStreamHandler ...@@ -410,19 +408,19 @@ public abstract class URLStreamHandler
* *
* @exception UnknownHostException If an unknown host is found * @exception UnknownHostException If an unknown host is found
*/ */
protected boolean hostsEqual (URL url1, URL url2) protected boolean hostsEqual(URL url1, URL url2)
{ {
InetAddress addr1 = getHostAddress (url1); InetAddress addr1 = getHostAddress(url1);
InetAddress addr2 = getHostAddress (url2); InetAddress addr2 = getHostAddress(url2);
if (addr1 != null && addr2 != null) if (addr1 != null && addr2 != null)
return addr1.equals (addr2); return addr1.equals(addr2);
String host1 = url1.getHost(); String host1 = url1.getHost();
String host2 = url2.getHost(); String host2 = url2.getHost();
if (host1 != null && host2 != null) if (host1 != null && host2 != null)
return host1.equalsIgnoreCase (host2); return host1.equalsIgnoreCase(host2);
return host1 == null && host2 == null; return host1 == null && host2 == null;
} }
...@@ -435,16 +433,16 @@ public abstract class URLStreamHandler ...@@ -435,16 +433,16 @@ public abstract class URLStreamHandler
* *
* @return The address of the hostname in url. * @return The address of the hostname in url.
*/ */
protected InetAddress getHostAddress (URL url) protected InetAddress getHostAddress(URL url)
{ {
String hostname = url.getHost (); String hostname = url.getHost();
if (hostname.equals("")) if (hostname.equals(""))
return null; return null;
try try
{ {
return InetAddress.getByName (hostname); return InetAddress.getByName(hostname);
} }
catch (UnknownHostException e) catch (UnknownHostException e)
{ {
...@@ -458,7 +456,7 @@ public abstract class URLStreamHandler ...@@ -458,7 +456,7 @@ public abstract class URLStreamHandler
* *
* @return The default port number. * @return The default port number.
*/ */
protected int getDefaultPort () protected int getDefaultPort()
{ {
return -1; return -1;
} }
...@@ -471,12 +469,11 @@ public abstract class URLStreamHandler ...@@ -471,12 +469,11 @@ public abstract class URLStreamHandler
* *
* @return The hashcode for the given URL. * @return The hashcode for the given URL.
*/ */
protected int hashCode (URL url) protected int hashCode(URL url)
{ {
return url.getProtocol ().hashCode () + return url.getProtocol().hashCode()
((url.getHost () == null) ? 0 : url.getHost ().hashCode ()) + + ((url.getHost() == null) ? 0 : url.getHost().hashCode())
url.getFile ().hashCode() + + url.getFile().hashCode() + url.getPort();
url.getPort ();
} }
/** /**
...@@ -488,23 +485,27 @@ public abstract class URLStreamHandler ...@@ -488,23 +485,27 @@ public abstract class URLStreamHandler
* *
* @return A string representation of the url * @return A string representation of the url
*/ */
protected String toExternalForm(URL u) protected String toExternalForm(URL url)
{ {
String protocol, host, file, ref, user; String protocol;
String host;
String file;
String ref;
String user;
int port; int port;
protocol = u.getProtocol(); protocol = url.getProtocol();
// JDK 1.2 online doc infers that host could be null because it // JDK 1.2 online doc infers that host could be null because it
// explicitly states that file cannot be null, but is silent on host. // explicitly states that file cannot be null, but is silent on host.
host = u.getHost(); host = url.getHost();
if (host == null) if (host == null)
host = ""; host = "";
port = u.getPort(); port = url.getPort();
file = u.getFile(); file = url.getFile();
ref = u.getRef(); ref = url.getRef();
user = u.getUserInfo(); user = url.getUserInfo();
// Guess a reasonable size for the string buffer so we have to resize // Guess a reasonable size for the string buffer so we have to resize
// at most once. // at most once.
...@@ -520,7 +521,7 @@ public abstract class URLStreamHandler ...@@ -520,7 +521,7 @@ public abstract class URLStreamHandler
if (host.length() != 0) if (host.length() != 0)
{ {
sb.append("//"); sb.append("//");
if (user != null && !"".equals(user)) if (user != null && ! "".equals(user))
sb.append(user).append('@'); sb.append(user).append('@');
sb.append(host); sb.append(host);
......
...@@ -37,12 +37,12 @@ exception statement from your version. */ ...@@ -37,12 +37,12 @@ exception statement from your version. */
package java.net; package java.net;
/** /**
* Written using on-line Java Platform 1.2 API Specification, as well * Written using on-line Java Platform 1.2 API Specification, as well
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
* Status: Believed complete and correct. * Status: Believed complete and correct.
*/ */
/** /**
* This interface contains one method which maps the protocol portion of * This interface contains one method which maps the protocol portion of
* a URL (eg, "http" in "http://www.urbanophile.com/arenn/") to a * a URL (eg, "http" in "http://www.urbanophile.com/arenn/") to a
...@@ -61,7 +61,5 @@ public interface URLStreamHandlerFactory ...@@ -61,7 +61,5 @@ public interface URLStreamHandlerFactory
* *
* @return The <code>URLStreamHandler</code> for the specified protocol * @return The <code>URLStreamHandler</code> for the specified protocol
*/ */
URLStreamHandler createURLStreamHandler (String protocol); URLStreamHandler createURLStreamHandler(String protocol);
} // interface URLStreamHandlerFactory } // interface URLStreamHandlerFactory
...@@ -39,6 +39,7 @@ package java.net; ...@@ -39,6 +39,7 @@ package java.net;
import java.io.IOException; import java.io.IOException;
/** /**
* This exception indicates that an attempt was made to reference a hostname * This exception indicates that an attempt was made to reference a hostname
* or IP address that is not valid. This could possibly indicate that a * or IP address that is not valid. This could possibly indicate that a
......
...@@ -39,6 +39,7 @@ package java.net; ...@@ -39,6 +39,7 @@ package java.net;
import java.io.IOException; import java.io.IOException;
/** /**
* Contrary to what you might think, this does not indicate that the * Contrary to what you might think, this does not indicate that the
* TCP/IP service name specified was invalid. Instead it indicates that * TCP/IP service name specified was invalid. Instead it indicates that
......
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