diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 78a4d99a9425..b64d0c119c65 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,51 @@ +2004-04-20 Michael Koch + + * 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 * java/lang/Byte.java, diff --git a/libjava/java/net/Authenticator.java b/libjava/java/net/Authenticator.java index 7592b525a509..8a951cb2dfd3 100644 --- a/libjava/java/net/Authenticator.java +++ b/libjava/java/net/Authenticator.java @@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -37,18 +37,19 @@ exception statement from your version. */ package java.net; + /** * This abstract class provides a model for obtaining authentication * information (in the form of a username and password) required by * some network operations (such as hitting a password protected * web site). *

- * To make use of this feature, a programmer must create a subclass + * To make use of this feature, a programmer must create a subclass * that knows how to obtain the necessary info. An example - * would be a class that popped up a dialog box to prompt the user. - * After creating an instance of that subclass, the static - * setDefault method of this class is called to set up - * that instance as the object to use on subsequent calls to obtain + * would be a class that popped up a dialog box to prompt the user. + * After creating an instance of that subclass, the static + * setDefault method of this class is called to set up + * that instance as the object to use on subsequent calls to obtain * authorization. * * @since 1.2 @@ -106,8 +107,8 @@ public abstract class Authenticator */ /** - * This method sets the default Authenticator object (an - * instance of a subclass of Authenticator) to use when + * This method sets the default Authenticator object (an + * instance of a subclass of Authenticator) to use when * prompting the user for * information. Note that this method checks to see if the caller is * allowed to set this value (the "setDefaultAuthenticator" permission) @@ -115,9 +116,9 @@ public abstract class Authenticator * * @param defAuth The new default Authenticator object to use * - * @exception SecurityException If the caller does not have permission + * @exception SecurityException If the caller does not have permission * to perform this operation - */ + */ public static void setDefault(Authenticator defAuth) { SecurityManager sm = System.getSecurityManager(); @@ -125,38 +126,40 @@ public abstract class Authenticator sm.checkPermission(new NetPermission("setDefaultAuthenticator")); defaultAuthenticator = defAuth; - } + } /** * This method is called whenever a username and password for a given * network operation is required. First, a security check is made to see * if the caller has the "requestPasswordAuthentication" * permission. If not, the method thows an exception. If there is no - * default Authenticator object, the method then returns - * null. Otherwise, the default authenticators's instance + * default Authenticator object, the method then returns + * null. Otherwise, the default authenticators's instance * variables are initialized and it's getPasswordAuthentication * method is called to get the actual authentication information to return. * * @param addr The address requesting authentication * @param port The port requesting authentication * @param protocol The protocol requesting authentication - * @param prompt The prompt to display to the user when requesting + * @param prompt The prompt to display to the user when requesting * authentication info * @param scheme The authentication scheme in use - * - * @return A PasswordAuthentication object with the user's + * + * @return A PasswordAuthentication object with the user's * authentication info. * - * @exception SecurityException If the caller does not have permission to + * @exception SecurityException If the caller does not have permission to * perform this operation - */ - public static PasswordAuthentication - requestPasswordAuthentication(InetAddress addr, int port, String protocol, - String prompt, String scheme) + */ + public static PasswordAuthentication requestPasswordAuthentication(InetAddress addr, + int port, + String protocol, + String prompt, + String scheme) throws SecurityException { - return(requestPasswordAuthentication (null, addr, port, protocol, - prompt, scheme)); + return requestPasswordAuthentication(null, addr, port, protocol, prompt, + scheme); } /** @@ -175,21 +178,24 @@ public abstract class Authenticator * @param addr The address requesting authentication * @param port The port requesting authentication * @param protocol The protocol requesting authentication - * @param prompt The prompt to display to the user when requesting + * @param prompt The prompt to display to the user when requesting * authentication info * @param scheme The authentication scheme in use * - * @return A PasswordAuthentication object with the user's + * @return A PasswordAuthentication object with the user's * authentication info. * - * @exception SecurityException If the caller does not have permission to + * @exception SecurityException If the caller does not have permission to * perform this operation * * @since 1.4 */ - public static PasswordAuthentication - requestPasswordAuthentication(String host, InetAddress addr, int port, - String protocol, String prompt, String scheme) + public static PasswordAuthentication requestPasswordAuthentication(String host, + InetAddress addr, + int port, + String protocol, + String prompt, + String scheme) throws SecurityException { SecurityManager sm = System.getSecurityManager(); @@ -197,7 +203,7 @@ public abstract class Authenticator sm.checkPermission(new NetPermission("requestPasswordAuthentication")); if (defaultAuthenticator == null) - return(null); + return null; defaultAuthenticator.host = host; defaultAuthenticator.addr = addr; @@ -206,7 +212,7 @@ public abstract class Authenticator defaultAuthenticator.prompt = prompt; defaultAuthenticator.scheme = scheme; - return(defaultAuthenticator.getPasswordAuthentication()); + return defaultAuthenticator.getPasswordAuthentication(); } /* @@ -232,7 +238,7 @@ public abstract class Authenticator */ protected final InetAddress getRequestingSite() { - return(addr); + return addr; } /** @@ -240,24 +246,24 @@ public abstract class Authenticator * or null if not available. * * @return The name of the host requesting authentication, or - * null if it is not available. + * null if it is not available. * * @since 1.4 */ protected final String getRequestingHost() { - return(host); + return host; } /** - * This method returns the port of the site that is requesting + * This method returns the port of the site that is requesting * authentication. * * @return The requesting port */ protected final int getRequestingPort() { - return(port); + return port; } /** @@ -268,18 +274,18 @@ public abstract class Authenticator */ protected final String getRequestingProtocol() { - return(protocol); + return protocol; } /** - * Returns the prompt that should be used when requesting authentication + * Returns the prompt that should be used when requesting authentication * information from the user - * + * * @return The user prompt */ protected final String getRequestingPrompt() { - return(prompt); + return prompt; } /** @@ -289,7 +295,7 @@ public abstract class Authenticator */ protected final String getRequestingScheme() { - return(scheme); + return scheme; } /** @@ -302,8 +308,6 @@ public abstract class Authenticator */ protected PasswordAuthentication getPasswordAuthentication() { - return(null); + return null; } - } // class Authenticator - diff --git a/libjava/java/net/BindException.java b/libjava/java/net/BindException.java index cfc36b312f6e..00885e8f21c7 100644 --- a/libjava/java/net/BindException.java +++ b/libjava/java/net/BindException.java @@ -37,6 +37,7 @@ exception statement from your version. */ package java.net; + /** * This exception indicates that an error occurred while attempting to bind * socket to a particular port. diff --git a/libjava/java/net/ConnectException.java b/libjava/java/net/ConnectException.java index e731858ca19d..2dd35e72d0fb 100644 --- a/libjava/java/net/ConnectException.java +++ b/libjava/java/net/ConnectException.java @@ -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 exception statement from your version. */ - package java.net; + /** * This exception indicates that an error occurred while attempting to * connect to a remote host. Often this indicates that the remote host diff --git a/libjava/java/net/ContentHandler.java b/libjava/java/net/ContentHandler.java index ed7469847752..5e3de23d4dcd 100644 --- a/libjava/java/net/ContentHandler.java +++ b/libjava/java/net/ContentHandler.java @@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -47,11 +47,11 @@ import java.io.IOException; /** * This is an abstract class that is the superclass for classes that read - * objects from URL's. Calling the getContent() method in the - * URL class or the URLConnection class will cause - * an instance of a subclass of ContentHandler to be created for - * the MIME type of the object being downloaded from the URL. Thus, this - * class is seldom needed by applications/applets directly, but only + * objects from URL's. Calling the getContent() method in the + * URL class or the URLConnection class will cause + * an instance of a subclass of ContentHandler to be created for + * the MIME type of the object being downloaded from the URL. Thus, this + * class is seldom needed by applications/applets directly, but only * indirectly through methods in other classes. * * @author Aaron M. Renn (arenn@urbanophile.com) @@ -66,8 +66,8 @@ public abstract class ContentHandler /** * Default, no-argument constructor. */ - public ContentHandler() - { + public ContentHandler() + { } /* @@ -75,10 +75,10 @@ public abstract class ContentHandler */ /** - * This method reads from the InputStream of the passed in URL - * connection and uses the data downloaded to create an Object - * represening the content. For example, if the URL is pointing to a GIF - * file, this method might return an Image object. This method + * This method reads from the InputStream of the passed in URL + * connection and uses the data downloaded to create an Object + * represening the content. For example, if the URL is pointing to a GIF + * file, this method might return an Image object. This method * must be implemented by subclasses. * * @param urlc A URLConnection object to read data from. @@ -87,16 +87,16 @@ public abstract class ContentHandler * * @exception IOException If an error occurs */ - public abstract Object getContent(URLConnection urlc) + public abstract Object getContent(URLConnection urlc) throws IOException; /** * This method reads from the InputStream of the passed in URL * connection and uses the data downloaded to create an Object - * represening the content. For example, if the URL is pointing to a GIF - * file, this method might return an Image object. This method + * represening the content. For example, if the URL is pointing to a GIF + * file, this method might return an Image object. This method * must be implemented by subclasses. This method uses the list of - * supplied classes as candidate types. If the data read doesn't match + * supplied classes as candidate types. If the data read doesn't match * any of the supplied type, null is returned. * * @param urlc A URLConnection object to read data from. @@ -113,15 +113,14 @@ public abstract class ContentHandler public Object getContent(URLConnection urlc, Class[] classes) throws IOException { - Object obj = getContent (urlc); + Object obj = getContent(urlc); for (int i = 0; i < classes.length; i++) { - if (classes [i].isInstance (obj)) - return obj; + if (classes[i].isInstance(obj)) + return obj; } return null; } - } // class ContentHandler diff --git a/libjava/java/net/ContentHandlerFactory.java b/libjava/java/net/ContentHandlerFactory.java index 7310f5696785..cdfbca285d3c 100644 --- a/libjava/java/net/ContentHandlerFactory.java +++ b/libjava/java/net/ContentHandlerFactory.java @@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -35,18 +35,17 @@ 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 exception statement from your version. */ - package java.net; + /** * Written using on-line Java Platform 1.2 API Specification, as well * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). * Status: Believed complete and correct. */ - /** - * This interface maps MIME types to ContentHandler objects. - * It consists of one method that, when passed a MIME type, returns a + * This interface maps MIME types to ContentHandler objects. + * It consists of one method that, when passed a MIME type, returns a * handler for that type. * * @author Aaron M. Renn (arenn@urbanophile.com) @@ -63,6 +62,4 @@ public interface ContentHandlerFactory * @return The ContentHandler for the passed in MIME type */ ContentHandler createContentHandler(String mimeType); - } // interface ContentHandlerFactory - diff --git a/libjava/java/net/DatagramPacket.java b/libjava/java/net/DatagramPacket.java index f23364cd0af8..8ff64435c2bb 100644 --- a/libjava/java/net/DatagramPacket.java +++ b/libjava/java/net/DatagramPacket.java @@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -37,6 +37,7 @@ exception statement from your version. */ package java.net; + /* * Written using on-line Java Platform 1.2 API Specification, as well * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). @@ -86,7 +87,7 @@ public final class DatagramPacket * The maximal length of the buffer. */ int maxlen; - + /** * The address to which the packet should be sent or from which it * was received. @@ -134,14 +135,14 @@ public final class DatagramPacket * * @param buf A buffer containing the data to send * @param offset The offset into the buffer to start writing from. - * @param len The length of the buffer (must be <= buf.length) - * @param addr The address to send to + * @param length The length of the buffer (must be <= buf.length) + * @param address The address to send to * @param port The port to send to * * @since 1.2 */ public DatagramPacket(byte[] buf, int offset, int length, - InetAddress address, int port) + InetAddress address, int port) { setData(buf, offset, length); setAddress(address); @@ -177,8 +178,7 @@ public final class DatagramPacket * @since 1.4 */ public DatagramPacket(byte[] buf, int offset, int length, - SocketAddress address) - throws SocketException + SocketAddress address) throws SocketException { if (! (address instanceof InetSocketAddress)) throw new IllegalArgumentException("unsupported address type"); @@ -272,16 +272,16 @@ public final class DatagramPacket /** * 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 */ - public synchronized void setAddress(InetAddress iaddr) + public synchronized void setAddress(InetAddress address) { - if (iaddr == null) + if (address == null) throw new NullPointerException("Null address"); - address = iaddr; + this.address = address; } /** @@ -291,12 +291,12 @@ public final class DatagramPacket * * @since 1.1 */ - public synchronized void setPort(int iport) + public synchronized void setPort(int port) { - if (iport < 0 || iport > 65535) - throw new IllegalArgumentException("Invalid port: " + iport); + if (port < 0 || port > 65535) + throw new IllegalArgumentException("Invalid port: " + port); - port = iport; + this.port = port; } /** @@ -324,12 +324,12 @@ public final class DatagramPacket * will be sent to/is coming from * * @return The socket address of the remote host - * + * * @since 1.4 */ public SocketAddress getSocketAddress() { - return new InetSocketAddress (address, port); + return new InetSocketAddress(address, port); } /** @@ -360,7 +360,6 @@ public final class DatagramPacket public synchronized void setData(byte[] buf, int offset, int length) { // This form of setData must be used if offset is to be changed. - if (buf == null) throw new NullPointerException("Null buffer"); if (offset < 0) @@ -372,7 +371,7 @@ public final class DatagramPacket } /** - * Sets the length of the data in the buffer. + * Sets the length of the data in the buffer. * * @param length The new length. (Where len <= buf.length) * @@ -387,7 +386,7 @@ public final class DatagramPacket throw new IllegalArgumentException("Invalid length: " + length); if (offset + length > buffer.length) throw new IllegalArgumentException("Potential buffer overflow - offset: " - + offset + " length: " + length); + + offset + " length: " + length); this.length = length; this.maxlen = length; diff --git a/libjava/java/net/DatagramSocket.java b/libjava/java/net/DatagramSocket.java index 895db94fa525..2808d82428b5 100644 --- a/libjava/java/net/DatagramSocket.java +++ b/libjava/java/net/DatagramSocket.java @@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -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 exception statement from your version. */ - package java.net; import gnu.java.net.PlainDatagramSocketImpl; @@ -44,24 +43,23 @@ import java.io.IOException; import java.nio.channels.DatagramChannel; import java.nio.channels.IllegalBlockingModeException; + /** * Written using on-line Java Platform 1.2 API Specification, as well * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). * 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, * this means UDP. Datagram packets do not have guaranteed delivery, * or any guarantee about the order the data will be received on the * remote host. - * + * * @author Aaron M. Renn (arenn@urbanophile.com) * @author Warren Levy (warrenl@cygnus.com) * @date May 3, 1999. */ - public class DatagramSocket { /** @@ -69,7 +67,7 @@ public class DatagramSocket * variable is null, a default factory is used. */ private static DatagramSocketImplFactory factory; - + /** * This is the implementation object used by this socket. */ @@ -96,15 +94,15 @@ public class DatagramSocket private boolean bound; /** - * Creates a DatagramSocket from a specified + * Creates a DatagramSocket from a specified * DatagramSocketImpl instance * - * @param impl The DatagramSocketImpl the socket will be + * @param impl The DatagramSocketImpl the socket will be * created from - * + * * @since 1.4 */ - protected DatagramSocket (DatagramSocketImpl impl) + protected DatagramSocket(DatagramSocketImpl impl) { if (impl == null) throw new NullPointerException("impl may not be null"); @@ -115,7 +113,7 @@ public class DatagramSocket } /** - * Initializes a new instance of DatagramSocket that binds to + * Initializes a new instance of DatagramSocket that binds to * a random port and every address on the local machine. * * @exception SocketException If an error occurs. @@ -128,7 +126,7 @@ public class DatagramSocket } /** - * Initializes a new instance of DatagramSocket that binds to + * Initializes a new instance of DatagramSocket that binds to * the specified port and every address on the local machine. * * @param port The local port number to bind to. @@ -143,7 +141,7 @@ public class DatagramSocket } /** - * Initializes a new instance of DatagramSocket that binds to + * Initializes a new instance of DatagramSocket that binds to * the specified local port and address. * * @param port The local port number to bind to. @@ -159,7 +157,7 @@ public class DatagramSocket } /** - * Initializes a new instance of DatagramSocket that binds to + * Initializes a new instance of DatagramSocket that binds to * the specified local port and address. * * @param address The local address and port number to bind to. @@ -170,35 +168,36 @@ public class DatagramSocket * * @since 1.4 */ - public DatagramSocket (SocketAddress address) throws SocketException + public DatagramSocket(SocketAddress address) throws SocketException { String propVal = System.getProperty("impl.prefix"); if (propVal == null || propVal.equals("")) impl = new PlainDatagramSocketImpl(); else try - { - impl = (DatagramSocketImpl) Class.forName - ("java.net." + propVal + "DatagramSocketImpl").newInstance(); - } + { + impl = + (DatagramSocketImpl) Class.forName("java.net." + propVal + + "DatagramSocketImpl") + .newInstance(); + } catch (Exception e) - { - System.err.println("Could not instantiate class: java.net." + - propVal + "DatagramSocketImpl"); + { + System.err.println("Could not instantiate class: java.net." + + propVal + "DatagramSocketImpl"); impl = new PlainDatagramSocketImpl(); - } + } if (address != null) bind(address); } - + // This needs to be accessible from java.net.MulticastSocket - DatagramSocketImpl getImpl() - throws SocketException + DatagramSocketImpl getImpl() throws SocketException { try { - if (!implCreated) + if (! implCreated) { impl.create(); implCreated = true; @@ -211,7 +210,7 @@ public class DatagramSocket throw new SocketException(e.getMessage()); } } - + /** * Closes this datagram socket. */ @@ -219,7 +218,7 @@ public class DatagramSocket { if (isClosed()) return; - + try { getImpl().close(); @@ -247,10 +246,10 @@ public class DatagramSocket } /** - * This method returns the remote address to which this socket is + * This method returns the remote address to which this socket is * connected. If this socket is not connected, then this method will * return null. - * + * * @return The remote address. * * @since 1.2 @@ -264,7 +263,7 @@ public class DatagramSocket * This method returns the remote port to which this socket is * connected. If this socket is not connected, then this method will * return -1. - * + * * @return The remote port. * * @since 1.2 @@ -276,7 +275,7 @@ public class DatagramSocket /** * Returns the local address this datagram socket is bound to. - * + * * @return The local address is the socket is bound or null * * @since 1.1 @@ -285,16 +284,17 @@ public class DatagramSocket { if (isClosed()) return null; - + InetAddress localAddr; - + try { - localAddr = (InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR); + localAddr = + (InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR); SecurityManager s = System.getSecurityManager(); if (s != null) - s.checkConnect (localAddr.getHostName(), -1); + s.checkConnect(localAddr.getHostName(), -1); } catch (SecurityException e) { @@ -303,7 +303,7 @@ public class DatagramSocket catch (SocketException e) { // This cannot happen as we are bound. - return null; + return null; } return localAddr; @@ -318,7 +318,7 @@ public class DatagramSocket { if (isClosed()) return -1; - + try { return getImpl().getLocalPort(); @@ -337,7 +337,7 @@ public class DatagramSocket * @return The current timeout in milliseconds. * * @exception SocketException If an error occurs. - * + * * @since 1.1 */ public synchronized int getSoTimeout() throws SocketException @@ -347,7 +347,7 @@ public class DatagramSocket Object buf = getImpl().getOption(SocketOptions.SO_TIMEOUT); - if (buf instanceof Integer) + if (buf instanceof Integer) return ((Integer) buf).intValue(); throw new SocketException("unexpected type"); @@ -368,7 +368,7 @@ public class DatagramSocket { if (isClosed()) throw new SocketException("socket is closed"); - + if (timeout < 0) throw new IllegalArgumentException("Invalid timeout: " + timeout); @@ -390,7 +390,7 @@ public class DatagramSocket { if (isClosed()) throw new SocketException("socket is closed"); - + Object buf = getImpl().getOption(SocketOptions.SO_SNDBUF); if (buf instanceof Integer) @@ -415,10 +415,10 @@ public class DatagramSocket { if (isClosed()) throw new SocketException("socket is closed"); - + if (size < 0) throw new IllegalArgumentException("Buffer size is less than 0"); - + getImpl().setOption(SocketOptions.SO_SNDBUF, new Integer(size)); } @@ -439,7 +439,7 @@ public class DatagramSocket throw new SocketException("socket is closed"); Object buf = getImpl().getOption(SocketOptions.SO_RCVBUF); - + if (buf instanceof Integer) return ((Integer) buf).intValue(); @@ -455,7 +455,7 @@ public class DatagramSocket * * @exception SocketException If an error occurs. * @exception IllegalArgumentException If size is 0 or negative. - * + * * @since 1.2 */ public void setReceiveBufferSize(int size) throws SocketException @@ -474,7 +474,7 @@ public class DatagramSocket * When a datagram socket is connected, it will only send or receive * packets to and from the host to which it is connected. A multicast * socket that is connected may only send and not receive packets. - * + * * @param address The address to connect this socket to. * @param port The port to connect this socket to. * @@ -488,10 +488,10 @@ public class DatagramSocket public void connect(InetAddress address, int port) { 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)) - throw new IllegalArgumentException ("Port number is illegal: " + port); + throw new IllegalArgumentException("Port number is illegal: " + port); SecurityManager sm = System.getSecurityManager(); if (sm != null) @@ -499,13 +499,13 @@ public class DatagramSocket try { - getImpl().connect (address, port); - remoteAddress = address; - remotePort = port; + getImpl().connect(address, port); + remoteAddress = address; + remotePort = port; } catch (SocketException e) { - // This means simply not connected or connect not implemented. + // This means simply not connected or connect not implemented. } } @@ -513,12 +513,12 @@ public class DatagramSocket * This method disconnects this socket from the address/port it was * connected to. If the socket was not connected in the first place, * this method does nothing. - * + * * @since 1.2 */ public void disconnect() { - if (!isConnected()) + if (! isConnected()) return; try @@ -559,22 +559,20 @@ public class DatagramSocket { if (isClosed()) throw new SocketException("socket is closed"); - - if (remoteAddress != null - && remoteAddress.isMulticastAddress()) - throw new IOException - ("Socket connected to a multicast address my not receive"); - if (getChannel() != null - && !getChannel().isBlocking () - && !((DatagramChannelImpl) getChannel()).isInChannelOperation()) - throw new IllegalBlockingModeException (); + if (remoteAddress != null && remoteAddress.isMulticastAddress()) + throw new IOException + ("Socket connected to a multicast address my not receive"); + + if (getChannel() != null && ! getChannel().isBlocking() + && ! ((DatagramChannelImpl) getChannel()).isInChannelOperation()) + throw new IllegalBlockingModeException(); getImpl().receive(p); SecurityManager s = System.getSecurityManager(); - if (s != null && isConnected ()) - s.checkAccept (p.getAddress().getHostName (), p.getPort ()); + if (s != null && isConnected()) + s.checkAccept(p.getAddress().getHostName(), p.getPort()); } /** @@ -596,33 +594,31 @@ public class DatagramSocket { if (isClosed()) throw new SocketException("socket is closed"); - + // JDK1.2: Don't do security checks if socket is connected; see jdk1.2 api. SecurityManager s = System.getSecurityManager(); - if (s != null && !isConnected ()) + if (s != null && ! isConnected()) { - InetAddress addr = p.getAddress(); - if (addr.isMulticastAddress()) - s.checkMulticast(addr); - else - s.checkConnect(addr.getHostAddress(), p.getPort()); + InetAddress addr = p.getAddress(); + if (addr.isMulticastAddress()) + s.checkMulticast(addr); + else + s.checkConnect(addr.getHostAddress(), p.getPort()); } - if (isConnected ()) + if (isConnected()) { - if (p.getAddress () != null && (remoteAddress != p.getAddress () || - remotePort != p.getPort ())) - throw new IllegalArgumentException ( - "DatagramPacket address does not match remote address" ); + if (p.getAddress() != null + && (remoteAddress != p.getAddress() || remotePort != p.getPort())) + throw new IllegalArgumentException + ("DatagramPacket address does not match remote address"); } - + // FIXME: if this is a subclass of MulticastSocket, // use getTimeToLive for TTL val. - - if (getChannel() != null - && !getChannel().isBlocking () - && !((DatagramChannelImpl) getChannel()).isInChannelOperation()) - throw new IllegalBlockingModeException (); + if (getChannel() != null && ! getChannel().isBlocking() + && ! ((DatagramChannelImpl) getChannel()).isInChannelOperation()) + throw new IllegalBlockingModeException(); getImpl().send(p); } @@ -639,12 +635,11 @@ public class DatagramSocket * * @since 1.4 */ - public void bind (SocketAddress address) - throws SocketException + public void bind(SocketAddress address) throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - + if (! (address instanceof InetSocketAddress)) throw new IllegalArgumentException("unsupported address type"); @@ -654,32 +649,32 @@ public class DatagramSocket if (port < 0 || port > 65535) throw new IllegalArgumentException("Invalid port: " + port); - SecurityManager s = System.getSecurityManager (); + SecurityManager s = System.getSecurityManager(); if (s != null) s.checkListen(port); if (addr == null) addr = InetAddress.ANY_IF; - + try { - getImpl().bind(port, addr); + getImpl().bind(port, addr); bound = true; } catch (SocketException exception) { - getImpl().close(); - throw exception; + getImpl().close(); + throw exception; } catch (RuntimeException exception) { - getImpl().close(); - throw exception; + getImpl().close(); + throw exception; } catch (Error error) { - getImpl().close(); - throw error; + getImpl().close(); + throw error; } } @@ -687,7 +682,7 @@ public class DatagramSocket * Checks if the datagram socket is closed. * * @return True if socket is closed, false otherwise. - * + * * @since 1.4 */ public boolean isClosed() @@ -697,9 +692,9 @@ public class DatagramSocket /** * Returns the datagram channel assoziated with this datagram socket. - * + * * @return The associated DatagramChannel object or null - * + * * @since 1.4 */ public DatagramChannel getChannel() @@ -717,23 +712,23 @@ public class DatagramSocket * * @since 1.4 */ - public void connect (SocketAddress address) throws SocketException + public void connect(SocketAddress address) throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - - if ( !(address instanceof InetSocketAddress) ) + + if (! (address instanceof InetSocketAddress)) throw new IllegalArgumentException("unsupported address type"); InetSocketAddress tmp = (InetSocketAddress) address; connect(tmp.getAddress(), tmp.getPort()); } - + /** * Returns the binding state of the socket. - * + * * @return True if socket bound, false otherwise. - * + * * @since 1.4 */ public boolean isBound() @@ -743,9 +738,9 @@ public class DatagramSocket /** * Returns the connection state of the socket. - * + * * @return True if socket is connected, false otherwise. - * + * * @since 1.4 */ public boolean isConnected() @@ -756,32 +751,32 @@ public class DatagramSocket /** * Returns the SocketAddress of the host this socket is conneted to * or null if this socket is not connected. - * + * * @return The socket address of the remote host if connected or null - * + * * @since 1.4 */ public SocketAddress getRemoteSocketAddress() { - if (!isConnected ()) + if (! isConnected()) return null; - return new InetSocketAddress (remoteAddress, remotePort); + return new InetSocketAddress(remoteAddress, remotePort); } /** * Returns the local SocketAddress this socket is bound to. * * @return The local SocketAddress or null if the socket is not bound. - * + * * @since 1.4 */ public SocketAddress getLocalSocketAddress() { - if (!isBound()) + if (! isBound()) return null; - - return new InetSocketAddress (getLocalAddress(), getLocalPort()); + + return new InetSocketAddress(getLocalAddress(), getLocalPort()); } /** @@ -798,7 +793,7 @@ public class DatagramSocket if (isClosed()) throw new SocketException("socket is closed"); - getImpl().setOption (SocketOptions.SO_REUSEADDR, Boolean.valueOf(on)); + getImpl().setOption(SocketOptions.SO_REUSEADDR, Boolean.valueOf(on)); } /** @@ -807,7 +802,7 @@ public class DatagramSocket * @return True if SO_REUSEADDR is set on the socket, false otherwise. * * @exception SocketException If an error occurs. - * + * * @since 1.4 */ public boolean getReuseAddress() throws SocketException @@ -815,8 +810,8 @@ public class DatagramSocket if (isClosed()) throw new SocketException("socket is closed"); - Object buf = getImpl().getOption (SocketOptions.SO_REUSEADDR); - + Object buf = getImpl().getOption(SocketOptions.SO_REUSEADDR); + if (buf instanceof Boolean) return ((Boolean) buf).booleanValue(); @@ -825,7 +820,7 @@ public class DatagramSocket /** * Enables/Disables SO_BROADCAST - * + * * @param enable True if SO_BROADCAST should be enabled, false otherwise. * * @exception SocketException If an error occurs @@ -842,11 +837,11 @@ public class DatagramSocket /** * Checks if SO_BROADCAST is enabled - * + * * @return Whether SO_BROADCAST is set * * @exception SocketException If an error occurs - * + * * @since 1.4 */ public boolean getBroadcast() throws SocketException @@ -855,7 +850,7 @@ public class DatagramSocket throw new SocketException("socket is closed"); Object buf = getImpl().getOption(SocketOptions.SO_BROADCAST); - + if (buf instanceof Boolean) return ((Boolean) buf).booleanValue(); @@ -871,11 +866,10 @@ public class DatagramSocket * @exception IllegalArgumentException If tc value is illegal * * @see DatagramSocket#getTrafficClass() - * + * * @since 1.4 */ - public void setTrafficClass(int tc) - throws SocketException + public void setTrafficClass(int tc) throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); @@ -883,25 +877,25 @@ public class DatagramSocket if (tc < 0 || tc > 255) throw new IllegalArgumentException(); - getImpl().setOption (SocketOptions.IP_TOS, new Integer (tc)); + getImpl().setOption(SocketOptions.IP_TOS, new Integer(tc)); } - + /** * Returns the current traffic class - * + * * @return The current traffic class. * * @see DatagramSocket#setTrafficClass(int tc) * * @exception SocketException If an error occurs - * + * * @since 1.4 */ public int getTrafficClass() throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - + Object buf = getImpl().getOption(SocketOptions.IP_TOS); if (buf instanceof Integer) @@ -909,7 +903,7 @@ public class DatagramSocket throw new SocketException("unexpected type"); } - + /** * Sets the datagram socket implementation factory for the application * @@ -920,11 +914,11 @@ public class DatagramSocket * @exception SecurityException If a security manager exists and its * checkSetFactory method doesn't allow the operation */ - public static void setDatagramSocketImplFactory - (DatagramSocketImplFactory fac) throws IOException + public static void setDatagramSocketImplFactory(DatagramSocketImplFactory fac) + throws IOException { if (factory != null) - throw new SocketException ("DatagramSocketImplFactory already defined"); + throw new SocketException("DatagramSocketImplFactory already defined"); SecurityManager sm = System.getSecurityManager(); if (sm != null) diff --git a/libjava/java/net/DatagramSocketImpl.java b/libjava/java/net/DatagramSocketImpl.java index 891c8d183b5e..0c21e2410d89 100644 --- a/libjava/java/net/DatagramSocketImpl.java +++ b/libjava/java/net/DatagramSocketImpl.java @@ -1,5 +1,5 @@ /* DatagramSocketImpl.java -- Abstract class for UDP socket implementations - Copyright (C) 1998, 1999 2000, 2001, + Copyright (C) 1998, 1999 2000, 2001, 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -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 exception statement from your version. */ - package java.net; -import java.io.IOException; import java.io.FileDescriptor; +import java.io.IOException; + /** * This abstract class models a datagram socket implementation. An @@ -58,7 +58,6 @@ import java.io.FileDescriptor; */ public abstract class DatagramSocketImpl implements SocketOptions { - /** * The local port to which this socket is bound */ @@ -103,7 +102,7 @@ public abstract class DatagramSocketImpl implements SocketOptions * Takes a peek at the next packet received in order to retrieve the * address of the sender * - * @param i The InetAddress to fill in with the information + * @param i The InetAddress to fill in with the information * about the sender if the next packet * * @return The port number of the sender of the packet @@ -118,19 +117,19 @@ public abstract class DatagramSocketImpl implements SocketOptions /** * Takes a peek at the next packet received. This packet is not consumed. * With the next peekData/receive operation this packet will be read again. - * + * * @param p The DatagramPacket to fill in with the data sent. * * @return The port number of the sender of the packet. - * + * * @exception IOException If an error occurs * @exception PortUnreachableException May be thrown if the socket is * connected to a currently unreachable destination. Note, there is no * guarantee that the exception will be thrown. - * + * * @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 @@ -169,17 +168,18 @@ public abstract class DatagramSocketImpl implements SocketOptions * * @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 } /** * Disconnects the socket. - * + * * @since 1.4 */ - protected void disconnect () + protected void disconnect() { // This method has to be overwritten by real implementations } @@ -199,8 +199,11 @@ public abstract class DatagramSocketImpl implements SocketOptions * This method returns the current Time to Live (TTL) setting on this * socket. Use getTimeToLive() instead. * + * @return the current time-to-live + * * @exception IOException If an error occurs - * @deprecated + * + * @deprecated // FIXME: when ? */ protected abstract byte getTTL() throws IOException; @@ -218,6 +221,8 @@ public abstract class DatagramSocketImpl implements SocketOptions * This method returns the current Time to Live (TTL) setting on this * socket. * + * @return the current time-to-live + * * @exception IOException If an error occurs */ protected abstract int getTimeToLive() throws IOException; @@ -242,35 +247,37 @@ public abstract class DatagramSocketImpl implements SocketOptions /** * Causes this socket to join the specified multicast group on a specified - * device - * + * device + * * @param mcastaddr The address to leave * @param netIf The specified network interface to join the group at * * @exception IOException If an error occurs - * + * * @since 1.4 */ - protected abstract void joinGroup (SocketAddress mcastaddr, - NetworkInterface netIf) + protected abstract void joinGroup(SocketAddress mcastaddr, + NetworkInterface netIf) throws IOException; /** * Leaves a multicast group - * + * * @param mcastaddr The address to join * @param netIf The specified network interface to leave the group at * * @exception IOException If an error occurs - * + * * @since 1.4 */ - protected abstract void leaveGroup (SocketAddress mcastaddr, - NetworkInterface netIf) + protected abstract void leaveGroup(SocketAddress mcastaddr, + NetworkInterface netIf) throws IOException; - + /** * Returns the FileDescriptor for this socket + * + * @return the file descriptor associated with this socket */ protected FileDescriptor getFileDescriptor() { @@ -279,6 +286,8 @@ public abstract class DatagramSocketImpl implements SocketOptions /** * Returns the local port this socket is bound to + * + * @return the local port */ protected int getLocalPort() { diff --git a/libjava/java/net/DatagramSocketImplFactory.java b/libjava/java/net/DatagramSocketImplFactory.java index 45bb18919aca..16a0a2ec1aa2 100644 --- a/libjava/java/net/DatagramSocketImplFactory.java +++ b/libjava/java/net/DatagramSocketImplFactory.java @@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -37,12 +37,12 @@ exception statement from your version. */ package java.net; + /** Written using on-line Java Platform 1.4 API Specification. * Status: Believed complete and correct. */ - /** - * This interface defines one method which returns a + * This interface defines one method which returns a * DatagramSocketImpl object. * This should not be needed by ordinary applications. * @@ -57,5 +57,4 @@ public interface DatagramSocketImplFactory * @return A DatagramSocketImpl object */ DatagramSocketImpl createDatagramSocketImpl(); - } // interface DatagramSocketImplFactory diff --git a/libjava/java/net/FileNameMap.java b/libjava/java/net/FileNameMap.java index c6c50000c770..fbc6059c564f 100644 --- a/libjava/java/net/FileNameMap.java +++ b/libjava/java/net/FileNameMap.java @@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -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 exception statement from your version. */ - package java.net; + /** * Written using on-line Java Platform 1.2 API Specification, as well * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). * Status: Believed complete and correct. */ - /** * This interface has one method which, when passed a filename, returns * the MIME type associated with that filename. @@ -63,6 +62,4 @@ public interface FileNameMap * @return The MIME type for the filename passed in. */ String getContentTypeFor(String filename); - } // interface FileNameMap - diff --git a/libjava/java/net/HttpURLConnection.java b/libjava/java/net/HttpURLConnection.java index 6d5fdfcef6a2..e603d2b929d6 100644 --- a/libjava/java/net/HttpURLConnection.java +++ b/libjava/java/net/HttpURLConnection.java @@ -8,7 +8,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -17,7 +17,7 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +02111-1307 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and @@ -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 exception statement from your version. */ - package java.net; -import java.io.InputStream; import java.io.IOException; +import java.io.InputStream; import java.io.PushbackInputStream; import java.security.Permission; + /* * Written using on-line Java Platform 1.2 API Specification, as well * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). @@ -51,12 +51,12 @@ import java.security.Permission; */ /** - * This class provides a common abstract implementation for those + * This class provides a common abstract implementation for those * URL connection classes that will connect using the HTTP protocol. * In addition to the functionality provided by the URLConnection * class, it defines constants for HTTP return code values and * methods for setting the HTTP request method and determining whether - * or not to follow redirects. + * or not to follow redirects. * * @since 1.1 * @@ -73,27 +73,27 @@ public abstract class HttpURLConnection extends URLConnection * beware of using this value */ static final int HTTP_CONTINUE = 100; - + /** * Indicates the request succeeded. */ - public static final int HTTP_OK = 200; + public static final int HTTP_OK = 200; /** * The requested resource has been created. */ - public static final int HTTP_CREATED = 201; + public static final int HTTP_CREATED = 201; /** * The request has been accepted for processing but has not completed. * There is no guarantee that the requested action will actually ever * be completed succesfully, but everything is ok so far. */ - public static final int HTTP_ACCEPTED = 202; + public static final int HTTP_ACCEPTED = 202; /** * The meta-information returned in the header is not the actual data - * from the original server, but may be from a local or other copy. + * from the original server, but may be from a local or other copy. * Normally this still indicates a successful completion. */ public static final int HTTP_NOT_AUTHORITATIVE = 203; @@ -102,20 +102,19 @@ public abstract class HttpURLConnection extends URLConnection * The server performed the request, but there is no data to send * back. This indicates that the user's display should not be changed. */ - public static final int HTTP_NO_CONTENT = 204; + public static final int HTTP_NO_CONTENT = 204; /** * The server performed the request, but there is no data to sent back, * however, the user's display should be "reset" to clear out any form * fields entered. */ - public static final int HTTP_RESET = 205; + public static final int HTTP_RESET = 205; /** * The server completed the partial GET request for the resource. */ - public static final int HTTP_PARTIAL = 206; - + public static final int HTTP_PARTIAL = 206; /* HTTP Redirection Response Codes */ @@ -123,22 +122,22 @@ public abstract class HttpURLConnection extends URLConnection * There is a list of choices available for the requested resource. */ public static final int HTTP_MULT_CHOICE = 300; - + /** * The resource has been permanently moved to a new location. */ public static final int HTTP_MOVED_PERM = 301; - + /** * The resource requested has been temporarily moved to a new location. */ public static final int HTTP_MOVED_TEMP = 302; - + /** * The response to the request issued is available at another location. */ public static final int HTTP_SEE_OTHER = 303; - + /** * The document has not been modified since the criteria specified in * a conditional GET. @@ -149,64 +148,63 @@ public abstract class HttpURLConnection extends URLConnection * The requested resource needs to be accessed through a proxy. */ public static final int HTTP_USE_PROXY = 305; - - + /* HTTP Client Error Response Codes */ /** * The request was misformed or could not be understood. */ public static final int HTTP_BAD_REQUEST = 400; - + /** * The request made requires user authorization. Try again with * a correct authentication header. */ public static final int HTTP_UNAUTHORIZED = 401; - + /** * Code reserved for future use - I hope way in the future. */ public static final int HTTP_PAYMENT_REQUIRED = 402; - + /** * There is no permission to access the requested resource. */ public static final int HTTP_FORBIDDEN = 403; - + /** * The requested resource was not found. */ public static final int HTTP_NOT_FOUND = 404; - + /** * The specified request method is not allowed for this resource. */ public static final int HTTP_BAD_METHOD = 405; - + /** * Based on the input headers sent, the resource returned in response * to the request would not be acceptable to the client. */ public static final int HTTP_NOT_ACCEPTABLE = 406; - + /** * The client must authenticate with a proxy prior to attempting this * request. */ public static final int HTTP_PROXY_AUTH = 407; - + /** * The request timed out. */ public static final int HTTP_CLIENT_TIMEOUT = 408; - + /** * There is a conflict between the current state of the resource and the * requested action. */ public static final int HTTP_CONFLICT = 409; - + /** * The requested resource is no longer available. This ususally indicates * a permanent condition. @@ -218,28 +216,27 @@ public abstract class HttpURLConnection extends URLConnection * supplied. */ public static final int HTTP_LENGTH_REQUIRED = 411; - + /** * A client specified pre-condition was not met on the server. */ public static final int HTTP_PRECON_FAILED = 412; - + /** * The request sent was too large for the server to handle. */ public static final int HTTP_ENTITY_TOO_LARGE = 413; - + /** * The name of the resource specified was too long. */ public static final int HTTP_REQ_TOO_LONG = 414; - + /** * The request is in a format not supported by the requested resource. */ public static final int HTTP_UNSUPPORTED_TYPE = 415; - /* HTTP Server Error Response Codes */ /** @@ -247,16 +244,16 @@ public abstract class HttpURLConnection extends URLConnection * * @deprecated */ - public static final int HTTP_SERVER_ERROR = 500; + public static final int HTTP_SERVER_ERROR = 500; /** * The server encountered an unexpected error (such as a CGI script crash) * that prevents the request from being fulfilled. */ - public static final int HTTP_INTERNAL_ERROR = 500; + public static final int HTTP_INTERNAL_ERROR = 500; /** - * The server does not support the requested functionality. + * The server does not support the requested functionality. * @since 1.3 */ public static final int HTTP_NOT_IMPLEMENTED = 501; @@ -294,8 +291,8 @@ public abstract class HttpURLConnection extends URLConnection /** * This is a list of valid request methods, separated by "|" characters. */ - private static String valid_methods - = "|GET|POST|HEAD|OPTIONS|PUT|DELETE|TRACE|"; + private static String valid_methods = + "|GET|POST|HEAD|OPTIONS|PUT|DELETE|TRACE|"; // Instance Variables @@ -312,7 +309,7 @@ public abstract class HttpURLConnection extends URLConnection /** * The response message string received from the server. */ - protected String responseMessage = null; + protected String responseMessage; /** * If this instance should follow redirect requests. @@ -324,7 +321,7 @@ public abstract class HttpURLConnection extends URLConnection * Used by getResponseCode() and * getResponseMessage(). */ - private boolean gotResponseVals = false; + private boolean gotResponseVals; /** * Create an HttpURLConnection for the specified URL @@ -335,16 +332,16 @@ public abstract class HttpURLConnection extends URLConnection { super(url); } - - /** + + /** * Closes the connection to the server. */ public abstract void disconnect(); - /** + /** * Returns a boolean indicating whether or not this connection is going * through a proxy - * + * * @return true if through a proxy, false otherwise */ public abstract boolean usingProxy(); @@ -370,7 +367,7 @@ public abstract class HttpURLConnection extends URLConnection } /** - * Returns a boolean indicating whether or not HTTP redirects will + * Returns a boolean indicating whether or not HTTP redirects will * automatically be followed or not. * * @return true if redirects will be followed, false otherwise @@ -383,16 +380,20 @@ public abstract class HttpURLConnection extends URLConnection /** * Returns the value of this HttpURLConnection's instanceFollowRedirects * field + * + * @return true if following redirects is enabled, false otherwise */ - public boolean getInstanceFollowRedirects () + public boolean getInstanceFollowRedirects() { return instanceFollowRedirects; } /** * 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; } @@ -401,6 +402,8 @@ public abstract class HttpURLConnection extends URLConnection * Set the method for the URL request, one of: * 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 * requested method isn't valid for HTTP */ @@ -414,7 +417,6 @@ public abstract class HttpURLConnection extends URLConnection this.method = method; else throw new ProtocolException("Invalid HTTP request method: " + method); - } /** @@ -439,7 +441,7 @@ public abstract class HttpURLConnection extends URLConnection */ public int getResponseCode() throws IOException { - if (!gotResponseVals) + if (! gotResponseVals) getResponseVals(); return responseCode; } @@ -455,7 +457,7 @@ public abstract class HttpURLConnection extends URLConnection */ public String getResponseMessage() throws IOException { - if (!gotResponseVals) + if (! gotResponseVals) getResponseVals(); return responseMessage; } @@ -464,9 +466,9 @@ public abstract class HttpURLConnection extends URLConnection { // getHeaderField() will connect for us, but do it here first in // order to pick up IOExceptions. - if (!connected) + if (! connected) connect(); - + gotResponseVals = true; // If responseCode not yet explicitly set by subclass @@ -474,7 +476,7 @@ public abstract class HttpURLConnection extends URLConnection { // Response is the first header received from the connection. String respField = getHeaderField(0); - + if (respField == null || ! respField.startsWith("HTTP/")) { // Set to default values on failure. @@ -483,7 +485,8 @@ public abstract class HttpURLConnection extends URLConnection return; } - int firstSpc, nextSpc; + int firstSpc; + int nextSpc; firstSpc = respField.indexOf(' '); nextSpc = respField.indexOf(' ', firstSpc + 1); responseMessage = respField.substring(nextSpc + 1); @@ -505,6 +508,8 @@ public abstract class HttpURLConnection extends URLConnection * Returns a permission object representing the permission necessary to make * the connection represented by this object * + * @return the permission necessary for this connection + * * @exception IOException If an error occurs */ public Permission getPermission() throws IOException @@ -514,9 +519,9 @@ public abstract class HttpURLConnection extends URLConnection int port = url.getPort(); if (port == -1) port = 80; - + host = host + ":" + port; - + return new SocketPermission(host, "connect"); } @@ -529,52 +534,56 @@ public abstract class HttpURLConnection extends URLConnection * * @return An InputStream for reading error data. */ - public InputStream getErrorStream () + public InputStream getErrorStream() { - if (!connected) - return(null); - + if (! connected) + return (null); + int code; - try + try { code = getResponseCode(); } - catch(IOException e) + catch (IOException e) { code = -1; } - + if (code == -1) - return(null); - - if (((code/100) != 4) || ((code/100) != 5)) - return(null); - + return (null); + + if (((code / 100) != 4) || ((code / 100) != 5)) + return (null); + try { PushbackInputStream pbis = new PushbackInputStream(getInputStream()); - + int i = pbis.read(); if (i == -1) - return(null); - + return (null); + 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 + * + * @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 // http://www.w3.org/Protocols/HTTP-NG/ng-notes.txt - - return super.getHeaderFieldDate (key, value); + return super.getHeaderFieldDate(key, value); } } diff --git a/libjava/java/net/Inet4Address.java b/libjava/java/net/Inet4Address.java index 76abfc3fce41..0a583efc9c6d 100644 --- a/libjava/java/net/Inet4Address.java +++ b/libjava/java/net/Inet4Address.java @@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -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 exception statement from your version. */ - package java.net; import java.io.ObjectStreamException; import java.util.Arrays; + /** * @author Michael Koch * @date August 3, 2002. @@ -53,7 +53,6 @@ import java.util.Arrays; * RFC 2365 (http://www.ietf.org/rfc/rfc2365.txt) * Status: Believed complete and correct. */ - public final class Inet4Address extends InetAddress { static final long serialVersionUID = 3286316764910316507L; @@ -61,20 +60,20 @@ public final class Inet4Address extends InetAddress /** * needed for serialization */ - private Object writeReplace () throws ObjectStreamException + private Object writeReplace() throws ObjectStreamException { - return new InetAddress (addr, hostName); + return new InetAddress(addr, hostName); } /** * Creates a Inet4Address - * + * * @param addr The IP address * @param host The Hostname */ Inet4Address(byte[] addr, String host) { - super (addr, host); + super(addr, host); } /** @@ -82,37 +81,37 @@ public final class Inet4Address extends InetAddress * * @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 */ - public boolean isLoopbackAddress () + public boolean isLoopbackAddress() { - return addr [0] == 0x7F; + return addr[0] == 0x7F; } - + /** * Checks if this address is a wildcard address * * @since 1.4 */ - public boolean isAnyLocalAddress () + public boolean isAnyLocalAddress() { byte[] anylocal = { 0, 0, 0, 0 }; - + return Arrays.equals(addr, anylocal); } /** * Checks if this address is a link local address - * + * * @since 1.4 */ - public boolean isLinkLocalAddress () + public boolean isLinkLocalAddress() { // XXX: This seems to not exist with IPv4 addresses return false; @@ -120,36 +119,36 @@ public final class Inet4Address extends InetAddress /** * Checks if this address is a site local address - * + * * @since 1.4 */ - public boolean isSiteLocalAddress () + public boolean isSiteLocalAddress() { // 10.0.0.0/8 - if (addr [0] == 0x0A) + if (addr[0] == 0x0A) return true; // 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 // // 172.16.0.0/12 - if (addr [0] == 0xAC && (addr [1] & 0xF0) == 0x01) + if (addr[0] == 0xAC && (addr[1] & 0xF0) == 0x01) return true; // 192.168.0.0/16 - if (addr [0] == 0xC0 && addr [1] == 0xA8) + if (addr[0] == 0xC0 && addr[1] == 0xA8) return true; - + // XXX: Do we need to check more addresses here ? return false; } /** * Checks if this multicast address has global scope - * + * * @since 1.4 */ - public boolean isMCGlobal () + public boolean isMCGlobal() { // XXX: This seems to net exist with IPv4 addresses return false; @@ -157,120 +156,118 @@ public final class Inet4Address extends InetAddress /** * Checks if this multicast address has node scope - * + * * @since 1.4 */ - public boolean isMCNodeLocal () + public boolean isMCNodeLocal() { // XXX: This seems to net exist with IPv4 addresses return false; } - + /** * Checks if this multicast address has link scope - * + * * @since 1.4 */ - public boolean isMCLinkLocal () + public boolean isMCLinkLocal() { - if (!isMulticastAddress ()) + if (! isMulticastAddress()) return false; - - return (addr [0] == 0xE0) - && (addr [1] == 0x00) - && (addr [2] == 0x00); + + return (addr[0] == 0xE0) && (addr[1] == 0x00) && (addr[2] == 0x00); } - + /** * Checks if this multicast address has site scope - * + * * @since 1.4 */ - public boolean isMCSiteLocal () + public boolean isMCSiteLocal() { // XXX: This seems to net exist with IPv4 addresses return false; } - + /** * Checks if this multicast address has organization scope - * + * * @since 1.4 */ - public boolean isMCOrgLocal () + public boolean isMCOrgLocal() { // XXX: This seems to net exist with IPv4 addresses return false; } - + /** * Returns the address of the current instance */ - public byte[] getAddress () + public byte[] getAddress() { return addr; } - + /** * Returns the address as string - * + * * @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 i = 0; - - for ( ; ; ) + + for (;;) { - sbuf.append (addr [i] & 0xFF); + sbuf.append(addr[i] & 0xFF); i++; - + if (i == len) break; - - sbuf.append ('.'); + + sbuf.append('.'); } - - return sbuf.toString (); + + return sbuf.toString(); } - + /** * Computes the hashcode of the instance */ - public int hashCode () + public int hashCode() { int hash = 0; int len = addr.length; int i = len > 4 ? len - 4 : 0; - - for ( ; i < len; i++) - hash = (hash << 8) | (addr [i] & 0xFF); - + + for (; i < len; i++) + hash = (hash << 8) | (addr[i] & 0xFF); + return hash; } - + /** * Compare the current Inet4Address instance with obj - * + * * @param obj Object to compare with */ - public boolean equals (Object obj) + public boolean equals(Object obj) { if (! (obj instanceof InetAddress)) return false; - + byte[] addr1 = addr; byte[] addr2 = ((InetAddress) obj).addr; - + if (addr1.length != addr2.length) return false; - - for (int i = addr1.length; --i >= 0; ) - if (addr1 [i] != addr2 [i]) - return false; - + + for (int i = addr1.length; --i >= 0;) + if (addr1[i] != addr2[i]) + return false; + return true; } } // class Inet4Address diff --git a/libjava/java/net/Inet6Address.java b/libjava/java/net/Inet6Address.java index c3418c654a95..5d5273599805 100644 --- a/libjava/java/net/Inet6Address.java +++ b/libjava/java/net/Inet6Address.java @@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -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 exception statement from your version. */ - package java.net; import java.util.Arrays; + /** * @author Michael Koch * @date August 3, 2002. @@ -50,7 +50,6 @@ import java.util.Arrays; * RFC 1884 (http://www.ietf.org/rfc/rfc1884.txt) * Status: Believed complete and correct. */ - public final class Inet6Address extends InetAddress { static final long serialVersionUID = 6880410070516793377L; @@ -59,213 +58,210 @@ public final class Inet6Address extends InetAddress * Needed for serialization */ byte[] ipaddress; - + /** * Create an Inet6Address object * * @param addr The IP address * @param host The hostname */ - Inet6Address (byte[] addr, String host) + Inet6Address(byte[] addr, String host) { - super (addr, host); + super(addr, host); this.ipaddress = addr; } /** * Utility routine to check if the InetAddress is an IP multicast address - * + * * @since 1.1 */ - public boolean isMulticastAddress () + public boolean isMulticastAddress() { - return ipaddress [0] == 0xFF; + return ipaddress[0] == 0xFF; } - + /** * Utility routine to check if the InetAddress in a wildcard address - * + * * @since 1.4 */ - public boolean isAnyLocalAddress () + public boolean isAnyLocalAddress() { - byte[] anylocal = { 0, 0, 0, 0, 0, 0, 0, 0, - 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 }; + return Arrays.equals(ipaddress, anylocal); } - + /** * Utility routine to check if the InetAddress is a loopback address - * + * * @since 1.4 */ - public boolean isLoopbackAddress () + public boolean isLoopbackAddress() { - byte[] loopback = { 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1 }; - + byte[] loopback = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + return Arrays.equals(ipaddress, loopback); } /** * Utility routine to check if the InetAddress is an link local address - * + * * @since 1.4 */ - public boolean isLinkLocalAddress () + public boolean isLinkLocalAddress() { - return ipaddress [0] == 0xFA; + return ipaddress[0] == 0xFA; } /** * Utility routine to check if the InetAddress is a site local address - * + * * @since 1.4 */ - public boolean isSiteLocalAddress () + public boolean isSiteLocalAddress() { - return ipaddress [0] == 0xFB; + return ipaddress[0] == 0xFB; } /** * Utility routine to check if the multicast address has global scope - * + * * @since 1.4 */ - public boolean isMCGlobal () + public boolean isMCGlobal() { - if (!isMulticastAddress ()) + if (! isMulticastAddress()) return false; - - return (ipaddress [1] & 0x0F) == 0xE; + + return (ipaddress[1] & 0x0F) == 0xE; } /** * Utility routine to check if the multicast address has node scope - * + * * @since 1.4 */ - public boolean isMCNodeLocal () + public boolean isMCNodeLocal() { - if (!isMulticastAddress ()) + if (! isMulticastAddress()) return false; - - return (ipaddress [1] & 0x0F) == 0x1; + + return (ipaddress[1] & 0x0F) == 0x1; } /** * Utility routine to check if the multicast address has link scope - * + * * @since 1.4 */ - public boolean isMCLinkLocal () + public boolean isMCLinkLocal() { - if (!isMulticastAddress ()) + if (! isMulticastAddress()) return false; - - return (ipaddress [1] & 0x0F) == 0x2; + + return (ipaddress[1] & 0x0F) == 0x2; } /** * Utility routine to check if the multicast address has site scope - * + * * @since 1.4 */ - public boolean isMCSiteLocal () + public boolean isMCSiteLocal() { - if (!isMulticastAddress ()) + if (! isMulticastAddress()) return false; - - return (ipaddress [1] & 0x0F) == 0x5; + + return (ipaddress[1] & 0x0F) == 0x5; } /** * Utility routine to check if the multicast address has organization scope - * + * * @since 1.4 */ - public boolean isMCOrgLocal () + public boolean isMCOrgLocal() { - if (!isMulticastAddress ()) + if (! isMulticastAddress()) return false; - - return (ipaddress [1] & 0x0F) == 0x8; + + return (ipaddress[1] & 0x0F) == 0x8; } - + /** * Returns the raw IP address of this InetAddress object. The result is in * network byte order: the highest order byte of the address is i * n getAddress()[0] */ - public byte[] getAddress () + public byte[] getAddress() { return ipaddress; } - + /** * 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) { - int x = ((ipaddress [i] & 0xFF) << 8) | (ipaddress [i + 1] & 0xFF); - boolean empty = sbuf.length () == 0; - - if (empty) - { - if (i > 0) - sbuf.append ("::"); - } - else - sbuf.append (':'); + int x = ((ipaddress[i] & 0xFF) << 8) | (ipaddress[i + 1] & 0xFF); + boolean empty = sbuf.length() == 0; - if (x != 0 || i >= 14) - sbuf.append (Integer.toHexString (x)); + if (empty) + { + if (i > 0) + sbuf.append("::"); + } + else + sbuf.append(':'); + + if (x != 0 || i >= 14) + sbuf.append(Integer.toHexString(x)); } - - return sbuf.toString (); + + return sbuf.toString(); } /** * 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 */ - public boolean equals (Object obj) + public boolean equals(Object obj) { if (! (obj instanceof Inet6Address)) return false; Inet6Address tmp = (Inet6Address) obj; - return super.equals (tmp) - && this.ipaddress == tmp.ipaddress; + return super.equals(tmp) && this.ipaddress == tmp.ipaddress; } - + /** * Utility routine to check if the InetAddress is an * IPv4 compatible IPv6 address * * @since 1.4 */ - public boolean isIPv4CompatibleAddress () + public boolean isIPv4CompatibleAddress() { - if (ipaddress [0] != 0x00 || ipaddress [1] != 0x00 || - ipaddress [2] != 0x00 || ipaddress [3] != 0x00 || - ipaddress [4] != 0x00 || ipaddress [5] != 0x00 || - ipaddress [6] != 0x00 || ipaddress [7] != 0x00 || - ipaddress [8] != 0x00 || ipaddress [9] != 0x00 || - ipaddress [10] != 0x00 || ipaddress [11] != 0x00) + if (ipaddress[0] != 0x00 || ipaddress[1] != 0x00 || ipaddress[2] != 0x00 + || ipaddress[3] != 0x00 || ipaddress[4] != 0x00 + || ipaddress[5] != 0x00 || ipaddress[6] != 0x00 + || ipaddress[7] != 0x00 || ipaddress[8] != 0x00 + || ipaddress[9] != 0x00 || ipaddress[10] != 0x00 + || ipaddress[11] != 0x00) return false; return true; diff --git a/libjava/java/net/InetAddress.java b/libjava/java/net/InetAddress.java index 126348b412ee..6d57566a1b3a 100644 --- a/libjava/java/net/InetAddress.java +++ b/libjava/java/net/InetAddress.java @@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -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 exception statement from your version. */ - package java.net; import gnu.classpath.Configuration; @@ -63,7 +62,7 @@ import java.io.Serializable; public class InetAddress implements Serializable { private static final long serialVersionUID = 3286316764910316507L; - + /** * Dummy InetAddress, used to bind socket to any (all) network interfaces. */ @@ -101,7 +100,7 @@ public class InetAddress implements Serializable * The name of the host for this address. */ String hostName; - + /** * The field 'family' seems to be the AF_ value. * FIXME: Much of the code in the other java.net classes does not make @@ -118,7 +117,7 @@ public class InetAddress implements Serializable * * @param ipaddr The IP number of this address as an array of bytes */ - InetAddress (byte[] address) + InetAddress(byte[] address) { this (address, null); } @@ -131,7 +130,7 @@ public class InetAddress implements Serializable * @param ipaddr The IP number of this address as an array of bytes * @param hostname The hostname of this IP address. */ - InetAddress (byte[] address, String hostname) + InetAddress(byte[] address, String hostname) { addr = address; hostName = hostname; @@ -153,8 +152,8 @@ public class InetAddress implements Serializable { // Mask against high order bits of 1110 if (addr.length == 4) - return (addr [0] & 0xF0) == 0xE0; - + return (addr[0] & 0xF0) == 0xE0; + // Mask against high order bits of 11111111 if (addr.length == 16) return addr [0] == (byte) 0xFF; @@ -164,68 +163,62 @@ public class InetAddress implements Serializable /** * Utility routine to check if the InetAddress in a wildcard address - * + * * @since 1.4 */ public boolean isAnyLocalAddress() { // This is the IPv4 implementation. // Any class derived from InetAddress should override this. - return equals (ANY_IF); + return equals(ANY_IF); } /** * Utility routine to check if the InetAddress is a loopback address - * + * * @since 1.4 */ public boolean isLoopbackAddress() { // This is the IPv4 implementation. // Any class derived from InetAddress should override this. - - return addr [0] == 0x7F; + return addr[0] == 0x7F; } /** * Utility routine to check if InetAddress is a link local address - * + * * @since 1.4 */ public boolean isLinkLocalAddress() { // This is the IPv4 implementation. // Any class derived from InetAddress should override this. - // XXX: This seems to not exist with IPv4 addresses return false; } /** * Utility routine to check if InetAddress is a site local address - * + * * @since 1.4 */ public boolean isSiteLocalAddress() { // This is the IPv4 implementation. // Any class derived from InetAddress should override this. - // 10.0.0.0/8 - if (addr [0] == 0x0A) + if (addr[0] == 0x0A) return true; // 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 - // 172.16.0.0/12 - if (addr [0] == 0xAC - && (addr [1] & 0xF0) == 0x01) + if (addr[0] == 0xAC && (addr[1] & 0xF0) == 0x01) return true; // 192.168.0.0/16 - if (addr [0] == 0xC0 - && addr [1] == 0xA8) + if (addr[0] == 0xC0 && addr[1] == 0xA8) return true; // XXX: Do we need to check more addresses here ? @@ -234,48 +227,43 @@ public class InetAddress implements Serializable /** * Utility routine to check if InetAddress is a global multicast address - * + * * @since 1.4 */ public boolean isMCGlobal() { // This is the IPv4 implementation. // Any class derived from InetAddress should override this. - // XXX: This seems to not exist with IPv4 addresses return false; } /** * Utility reoutine to check if InetAddress is a node local multicast address - * + * * @since 1.4 */ public boolean isMCNodeLocal() { // This is the IPv4 implementation. // Any class derived from InetAddress should override this. - // XXX: This seems to not exist with IPv4 addresses return false; } /** * Utility reoutine to check if InetAddress is a link local multicast address - * + * * @since 1.4 */ public boolean isMCLinkLocal() { // This is the IPv4 implementation. // Any class derived from InetAddress should override this. - - if (!isMulticastAddress()) + if (! isMulticastAddress()) return false; - return (addr [0] == 0xE0 - && addr [1] == 0x00 - && addr [2] == 0x00); + return (addr[0] == 0xE0 && addr[1] == 0x00 && addr[2] == 0x00); } /** @@ -287,7 +275,6 @@ public class InetAddress implements Serializable { // This is the IPv4 implementation. // Any class derived from InetAddress should override this. - // XXX: This seems to not exist with IPv4 addresses return false; } @@ -295,14 +282,13 @@ public class InetAddress implements Serializable /** * Utility reoutine to check if InetAddress is a organization local * multicast address - * + * * @since 1.4 */ public boolean isMCOrgLocal() { // This is the IPv4 implementation. // Any class derived from InetAddress should override this. - // XXX: This seems to not exist with IPv4 addresses return false; } @@ -384,7 +370,7 @@ public class InetAddress implements Serializable } /** - * Returns the IP address of this object as a String. The address is in + * Returns the IP address of this object as a String. The address is in * the dotted octet notation, for example, "127.0.0.1". * * @return The IP address of this object in String form @@ -393,7 +379,8 @@ public class InetAddress implements Serializable */ public String getHostAddress() { - StringBuffer sb = new StringBuffer (40); + StringBuffer sb = new StringBuffer(40); + int len = addr.length; int i = 0; @@ -440,7 +427,7 @@ public class InetAddress implements Serializable sb.append ('.'); } - + return sb.toString(); } @@ -457,10 +444,10 @@ public class InetAddress implements Serializable int hash = 0; int len = addr.length; int i = len > 4 ? len - 4 : 0; - - for ( ; i < len; i++) + + for (; i < len; i++) hash = (hash << 8) | (addr[i] & 0xFF); - + return hash; } @@ -474,11 +461,11 @@ public class InetAddress implements Serializable * @return true if the passed in object's address is equal to this one's, * false otherwise */ - public boolean equals (Object obj) + public boolean equals(Object obj) { if (! (obj instanceof InetAddress)) return false; - + // "The Java Class Libraries" 2nd edition says "If a machine has // multiple names instances of InetAddress for different name of // that same machine are not equal. This is because they have @@ -486,14 +473,14 @@ public class InetAddress implements Serializable // JDK 1.2 API documentation. A little experimentation // shows that the latter is correct. byte[] addr2 = ((InetAddress) obj).addr; - + if (addr.length != addr2.length) return false; - + for (int i = 0; i < addr.length; i++) - if (addr [i] != addr2 [i]) + if (addr[i] != addr2[i]) return false; - + return true; } @@ -508,12 +495,12 @@ public class InetAddress implements Serializable { String host; String address = getHostAddress(); - + if (hostName != null) host = hostName; else host = address; - + return host + "/" + address; } @@ -529,10 +516,10 @@ public class InetAddress implements Serializable * * @since 1.4 */ - public static InetAddress getByAddress (byte[] addr) + public static InetAddress getByAddress(byte[] addr) throws UnknownHostException { - return getByAddress (null, addr); + return getByAddress(null, addr); } /** @@ -546,18 +533,18 @@ public class InetAddress implements Serializable * * @since 1.4 */ - public static InetAddress getByAddress (String host, byte[] addr) + public static InetAddress getByAddress(String host, byte[] addr) throws UnknownHostException { if (addr.length == 4) - return new Inet4Address (addr, host); + return new Inet4Address(addr, host); if (addr.length == 16) - return new Inet6Address (addr, host); - - throw new UnknownHostException ("IP address has illegal length"); + return new Inet6Address(addr, host); + + throw new UnknownHostException("IP address has illegal length"); } - + /** * If host is a valid numeric IP address, return the numeric address. * Otherwise, return null. @@ -578,7 +565,7 @@ public class InetAddress implements Serializable * the InetAddress array returned from GetAllByName. * * @param hostname The name of the desired host, or null for the local machine. - * + * * @return The address of the host as an InetAddress object. * * @exception UnknownHostException If no IP address for the host could @@ -586,19 +573,19 @@ public class InetAddress implements Serializable * @exception SecurityException If a security manager exists and its * checkConnect method doesn't allow the operation */ - public static InetAddress getByName (String hostname) + public static InetAddress getByName(String hostname) throws UnknownHostException { SecurityManager s = System.getSecurityManager(); if (s != null) - s.checkConnect (hostname, -1); - + s.checkConnect(hostname, -1); + // Default to current host if necessary if (hostname == null || hostname.length() == 0) return getLocalHost(); // Assume that the host string is an IP address - byte[] address = aton (hostname); + byte[] address = aton(hostname); if (address != null) { if (address.length == 4) @@ -619,10 +606,10 @@ public class InetAddress implements Serializable else throw new UnknownHostException ("Address has invalid length"); } - + // Try to resolve the host by DNS - InetAddress[] addresses = getAllByName (hostname); - return addresses [0]; + InetAddress[] addresses = getAllByName(hostname); + return addresses[0]; } /** @@ -632,22 +619,22 @@ public class InetAddress implements Serializable * dotted decimal format such as "127.0.0.1". If the value is null, the * 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. * * @return All addresses of the host as an array of InetAddress objects. - * + * * @exception UnknownHostException If no IP address for the host could * be found * @exception SecurityException If a security manager exists and its * checkConnect method doesn't allow the operation */ - public static InetAddress[] getAllByName (String hostname) + public static InetAddress[] getAllByName(String hostname) throws UnknownHostException { SecurityManager s = System.getSecurityManager(); if (s != null) - s.checkConnect (hostname, -1); + s.checkConnect(hostname, -1); // Check if hostname is an IP address byte[] address = aton (hostname); @@ -657,7 +644,7 @@ public class InetAddress implements Serializable result [0] = new InetAddress (address, null); return result; } - + // Try to resolve the hostname by DNS return lookup (hostname, null, true); } @@ -747,17 +734,17 @@ public class InetAddress implements Serializable { // FIXME: implement this } - - private void readObject (ObjectInputStream ois) + + private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { ois.defaultReadObject(); - addr = new byte [4]; - addr [3] = (byte) address; - + addr = new byte[4]; + addr[3] = (byte) address; + 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 // the deserialized object will have an IPv4 address i.e. AF_INET family. // FIXME: An alternative is to call the aton method on the deserialized @@ -766,16 +753,16 @@ public class InetAddress implements Serializable 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 // or a 16 byte IPv6 address. int len = addr.length; int i = len - 4; - + for (; i < len; i++) - address = address << 8 | (((int) addr [i]) & 0xFF); - + address = address << 8 | (((int) addr[i]) & 0xFF); + oos.defaultWriteObject(); } } diff --git a/libjava/java/net/InetSocketAddress.java b/libjava/java/net/InetSocketAddress.java index f0a27e3c3beb..5dc63dcd0db8 100644 --- a/libjava/java/net/InetSocketAddress.java +++ b/libjava/java/net/InetSocketAddress.java @@ -1,4 +1,4 @@ -/* InetSocketAddress.java -- +/* InetSocketAddress.java -- Copyright (C) 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -37,21 +37,21 @@ exception statement from your version. */ package java.net; -/** + +/** * InetSocketAddress instances represent socket addresses * in the java.nio package. They encapsulate a InetAddress and * a port number. * * @since 1.4 */ - public class InetSocketAddress extends SocketAddress { /** * Compatible with JDK 1.4+ */ private static final long serialVersionUID = 5076001401234631237L; - + /** * Name of host. */ @@ -66,10 +66,10 @@ public class InetSocketAddress extends SocketAddress * Port of host. */ private int port; - + /** * Constructs an InetSocketAddress instance. - * + * * @param addr Address of the socket * @param port Port if the socket * @@ -79,34 +79,33 @@ public class InetSocketAddress extends SocketAddress throws IllegalArgumentException { if (port < 0 || port > 65535) - throw new IllegalArgumentException ("Bad port number: " + port); + throw new IllegalArgumentException("Bad port number: " + port); if (addr == null) addr = InetAddress.ANY_IF; - + this.addr = addr; this.port = port; - this.hostname = addr.getHostName (); + this.hostname = addr.getHostName(); } /** * Constructs an InetSocketAddress instance. - * + * * @param port Port if the socket * * @exception IllegalArgumentException If the port number is illegal */ - public InetSocketAddress(int port) - throws IllegalArgumentException + public InetSocketAddress(int port) throws IllegalArgumentException { - this ((InetAddress) null, port); + this((InetAddress) null, port); } /** * Constructs an InetSocketAddress instance. * - * @param addr Address of the socket - * @param port Port if the socket + * @param hostname The hostname for the socket address + * @param port The port for the socket address * * @exception IllegalArgumentException If the port number is illegal */ @@ -114,49 +113,48 @@ public class InetSocketAddress extends SocketAddress throws IllegalArgumentException { if (hostname == null) - throw new IllegalArgumentException ("Null host name value"); - + throw new IllegalArgumentException("Null host name value"); + if (port < 0 || port > 65535) - throw new IllegalArgumentException ("Bad port number: " + port); + throw new IllegalArgumentException("Bad port number: " + port); this.port = port; this.hostname = hostname; try { - this.addr = InetAddress.getByName(hostname); + this.addr = InetAddress.getByName(hostname); } catch (Exception e) // UnknownHostException, SecurityException { - this.addr = null; + this.addr = null; } } - - /** + + /** * Test if obj is a InetSocketAddress and * has the same address and port * * @param obj The obj to compare this address with. * - * @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. // The hostname may differ. - if (obj instanceof InetSocketAddress) { - InetSocketAddress sa = (InetSocketAddress) obj; - - if (addr == null && sa.addr != null) - return false; - else if (addr == null && sa.addr == null) - return hostname.equals (sa.hostname) && sa.port == port; - else - return addr.equals (sa.addr) && sa.port == port; + InetSocketAddress sa = (InetSocketAddress) obj; + + if (addr == null && sa.addr != null) + return false; + else if (addr == null && sa.addr == null) + return hostname.equals(sa.hostname) && sa.port == port; + else + return addr.equals(sa.addr) && sa.port == port; } - + return false; } @@ -190,7 +188,7 @@ public class InetSocketAddress extends SocketAddress { return port; } - + /** * Returns the hashcode of the InetSocketAddress * @@ -210,7 +208,7 @@ public class InetSocketAddress extends SocketAddress { return addr == null; } - + /** * Returns the InetSocketAddress as string * diff --git a/libjava/java/net/JarURLConnection.java b/libjava/java/net/JarURLConnection.java index 87d9db36f1c4..96f214da8ac5 100644 --- a/libjava/java/net/JarURLConnection.java +++ b/libjava/java/net/JarURLConnection.java @@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -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 exception statement from your version. */ - package java.net; import java.io.IOException; +import java.security.cert.Certificate; import java.util.jar.Attributes; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.jar.JarInputStream; import java.util.jar.Manifest; import java.util.zip.ZipEntry; -import java.security.cert.Certificate; + /** * 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 * files on remote systems to be accessed. It has the form: *

- * jar:!/file/within/jarfile + * jar:<standard URL pointing to jar filei>!/file/within/jarfile *

for example: *

* jar:http://www.urbanophile.com/java/foo.jar!/com/urbanophile/bar.class @@ -96,30 +96,29 @@ public abstract class JarURLConnection extends URLConnection /** * 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 * * @specnote This constructor is protected since JDK 1.4 */ - protected JarURLConnection (URL url) - throws MalformedURLException + protected JarURLConnection(URL url) throws MalformedURLException { - super (url); + super(url); - if (!url.getProtocol().equals ("jar")) - throw new MalformedURLException (url + ": Not jar protocol."); + if (! url.getProtocol().equals("jar")) + throw new MalformedURLException(url + ": Not jar protocol."); String spec = url.getFile(); - int bang = spec.indexOf ("!/"); + int bang = spec.indexOf("!/"); if (bang == -1) - throw new MalformedURLException (url + ": No `!/' in spec."); + throw new MalformedURLException(url + ": No `!/' in spec."); // 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. - 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 * * @return The remote URL */ - public URL getJarFileURL () + public URL getJarFileURL() { return jarFileURL; } @@ -140,19 +139,19 @@ public abstract class JarURLConnection extends URLConnection * * @return The entry name. */ - public String getEntryName () + public String getEntryName() { return entryName; } /** - * Returns the entry in this jar file specified by the URL. - * + * Returns the entry in this jar file specified by the URL. + * * @return The jar entry * * @exception IOException If an error occurs */ - public JarEntry getJarEntry () throws IOException + public JarEntry getJarEntry() throws IOException { JarFile jarfile = null; @@ -203,7 +202,7 @@ public abstract class JarURLConnection extends URLConnection * * @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 @@ -213,10 +212,10 @@ public abstract class JarURLConnection extends URLConnection * * @exception IOException If an error occurs */ - public Certificate[] getCertificates () throws IOException + public Certificate[] getCertificates() throws IOException { JarEntry entry = getJarEntry(); - + return entry != null ? entry.getCertificates() : null; } @@ -228,10 +227,10 @@ public abstract class JarURLConnection extends URLConnection * * @exception IOException If an error occurs */ - public Attributes getMainAttributes () throws IOException + public Attributes getMainAttributes() throws IOException { Manifest manifest = getManifest(); - + return manifest != null ? manifest.getMainAttributes() : null; } @@ -244,7 +243,7 @@ public abstract class JarURLConnection extends URLConnection * * @exception IOException If an error occurs */ - public Attributes getAttributes () throws IOException + public Attributes getAttributes() throws IOException { JarEntry entry = getJarEntry(); @@ -259,7 +258,7 @@ public abstract class JarURLConnection extends URLConnection * * @exception IOException If an error occurs */ - public Manifest getManifest () throws IOException + public Manifest getManifest() throws IOException { JarFile file = getJarFile(); diff --git a/libjava/java/net/MalformedURLException.java b/libjava/java/net/MalformedURLException.java index 9cfae9aa5e5c..c9a50fa86502 100644 --- a/libjava/java/net/MalformedURLException.java +++ b/libjava/java/net/MalformedURLException.java @@ -39,6 +39,7 @@ package java.net; import java.io.IOException; + /** * This exception indicates that a URL passed to an object was not in a * valid format. diff --git a/libjava/java/net/MulticastSocket.java b/libjava/java/net/MulticastSocket.java index 28b76b365ee4..c177531f22f3 100644 --- a/libjava/java/net/MulticastSocket.java +++ b/libjava/java/net/MulticastSocket.java @@ -8,7 +8,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -41,21 +41,21 @@ package java.net; import java.io.IOException; import java.util.Enumeration; + /** * Written using on-line Java Platform 1.2 API Specification, as well * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). * Status: Believed complete and correct. */ - /** * 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). * A multicast group consists of a multicast address and a well known * port number. All members of the group listening on that address and * port will receive all the broadcasts to the group. *

- * Please note that applets are not allowed to use multicast sockets - * + * Please note that applets are not allowed to use multicast sockets + * * Written using on-line Java Platform 1.2 API Specification, as well * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). * Status: Believed complete and correct. @@ -111,10 +111,10 @@ public class MulticastSocket extends DatagramSocket if (address != null) bind(address); } - + /** * Returns the interface being used for multicast packets - * + * * @return The multicast interface * * @exception SocketException If an error occurs @@ -131,7 +131,7 @@ public class MulticastSocket extends DatagramSocket * Returns the current value of the "Time to Live" option. This is the * number of hops a packet can make before it "expires". This method id * deprecated. Use getTimeToLive instead. - * + * * @return The TTL value * * @exception IOException If an error occurs @@ -153,8 +153,8 @@ public class MulticastSocket extends DatagramSocket /** * Returns the current value of the "Time to Live" option. This is the - * number of hops a packet can make before it "expires". - * + * number of hops a packet can make before it "expires". + * * @return The TTL value * * @exception IOException If an error occurs @@ -189,12 +189,12 @@ public class MulticastSocket extends DatagramSocket /** * 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 - * + * * @see MulticastSocket#getNetworkInterface() - * + * * @since 1.4 */ public void setNetworkInterface(NetworkInterface netIf) @@ -203,13 +203,13 @@ public class MulticastSocket extends DatagramSocket if (isClosed()) 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"); - InetAddress address = (InetAddress) e.nextElement (); - getImpl().setOption (SocketOptions.IP_MULTICAST_IF, address); + InetAddress address = (InetAddress) e.nextElement(); + getImpl().setOption(SocketOptions.IP_MULTICAST_IF, address); } /** @@ -220,18 +220,17 @@ public class MulticastSocket extends DatagramSocket * @exception SocketException If an error occurs * * @see MulticastSocket#setNetworkInterface(NetworkInterface netIf) - * + * * @since 1.4 */ - public NetworkInterface getNetworkInterface() - throws SocketException + public NetworkInterface getNetworkInterface() throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); InetAddress address = - (InetAddress) getImpl().getOption (SocketOptions.IP_MULTICAST_IF); - NetworkInterface netIf = NetworkInterface.getByInetAddress (address); + (InetAddress) getImpl().getOption(SocketOptions.IP_MULTICAST_IF); + NetworkInterface netIf = NetworkInterface.getByInetAddress(address); return netIf; } @@ -239,7 +238,7 @@ public class MulticastSocket extends DatagramSocket /** * Disable/Enable local loopback of multicast packets. The option is used by * the platform's networking code as a hint for setting whether multicast - * data will be looped back to the local socket. + * data will be looped back to the local socket. * * Because this option is a hint, applications that want to verify what * loopback mode is set to should call #getLoopbackMode @@ -255,12 +254,15 @@ public class MulticastSocket extends DatagramSocket if (isClosed()) 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 * * @since 1.4 @@ -270,11 +272,11 @@ public class MulticastSocket extends DatagramSocket if (isClosed()) 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) return ((Boolean) buf).booleanValue(); - + throw new SocketException("unexpected type"); } @@ -303,12 +305,12 @@ public class MulticastSocket extends DatagramSocket /** * Sets the "Time to Live" value for a socket. The value must be between - * 1 and 255. + * 1 and 255. * * @param ttl The new TTL value * * @exception IOException If an error occurs - * + * * @since 1.2 */ public void setTimeToLive(int ttl) throws IOException @@ -323,10 +325,10 @@ public class MulticastSocket extends DatagramSocket } /** - * Joins the specified mulitcast group. + * Joins the specified multicast group. + * + * @param mcastaddr The address of the group to join * - * @param addr The address of the group to join - * * @exception IOException If an error occurs * @exception SecurityException If a security manager exists and its * checkMulticast method doesn't allow the operation @@ -349,7 +351,7 @@ public class MulticastSocket extends DatagramSocket /** * 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 SecurityException If a security manager exists and its @@ -377,7 +379,7 @@ public class MulticastSocket extends DatagramSocket * @param netIf The local network interface to receive the multicast * messages on or null to defer the interface set by #setInterface or * #setNetworkInterface - * + * * @exception IOException If an error occurs * @exception IllegalArgumentException If address type is not supported * @exception SecurityException If a security manager exists and its @@ -395,26 +397,26 @@ public class MulticastSocket extends DatagramSocket throw new SocketException("socket is closed"); if (! (mcastaddr instanceof InetSocketAddress)) - throw new IllegalArgumentException ("SocketAddress type not supported"); + throw new IllegalArgumentException("SocketAddress type not supported"); InetSocketAddress tmp = (InetSocketAddress) mcastaddr; - - if (! tmp.getAddress ().isMulticastAddress ()) - throw new IOException ("Not a Multicast address"); - SecurityManager s = System.getSecurityManager (); + if (! tmp.getAddress().isMulticastAddress()) + throw new IOException("Not a Multicast address"); + + SecurityManager s = System.getSecurityManager(); if (s != null) - s.checkMulticast (tmp.getAddress ()); + s.checkMulticast(tmp.getAddress()); - getImpl().joinGroup (mcastaddr, netIf); + getImpl().joinGroup(mcastaddr, netIf); } - + /** * Leaves the specified mulitcast group on a specified interface. * * @param mcastaddr The multicast address to leave * @param netIf The local networki interface or null to defer to the - * interface set by setInterface or setNetworkInterface + * interface set by setInterface or setNetworkInterface * * @exception IOException If an error occurs * @exception IllegalArgumentException If address type is not supported @@ -433,17 +435,17 @@ public class MulticastSocket extends DatagramSocket throw new SocketException("socket is closed"); InetSocketAddress tmp = (InetSocketAddress) mcastaddr; - - if (! tmp.getAddress ().isMulticastAddress ()) - throw new IOException ("Not a Multicast address"); - SecurityManager s = System.getSecurityManager (); + if (! tmp.getAddress().isMulticastAddress()) + throw new IOException("Not a Multicast address"); + + SecurityManager s = System.getSecurityManager(); if (s != null) - s.checkMulticast (tmp.getAddress ()); + s.checkMulticast(tmp.getAddress()); - getImpl().leaveGroup (mcastaddr, netIf); + getImpl().leaveGroup(mcastaddr, netIf); } - + /** * Sends a packet of data to a multicast address with a TTL that is * different from the default TTL on this socket. The default TTL for @@ -458,7 +460,8 @@ public class MulticastSocket extends DatagramSocket * * @deprecated */ - public synchronized void send(DatagramPacket p, byte ttl) throws IOException + public synchronized void send(DatagramPacket packet, byte ttl) + throws IOException { if (isClosed()) throw new SocketException("socket is closed"); @@ -466,18 +469,18 @@ public class MulticastSocket extends DatagramSocket SecurityManager s = System.getSecurityManager(); if (s != null) { - InetAddress addr = p.getAddress(); - if (addr.isMulticastAddress()) - s.checkPermission (new SocketPermission - (addr.getHostName () + p.getPort (), - "accept,connect")); - else - s.checkConnect(addr.getHostAddress(), p.getPort()); + InetAddress addr = packet.getAddress(); + if (addr.isMulticastAddress()) + s.checkPermission(new SocketPermission(addr.getHostName() + + packet.getPort(), + "accept,connect")); + else + s.checkConnect(addr.getHostAddress(), packet.getPort()); } int oldttl = getImpl().getTimeToLive(); getImpl().setTimeToLive(((int) ttl) & 0xFF); - getImpl().send(p); + getImpl().send(packet); getImpl().setTimeToLive(oldttl); } -} // class MulticastSocket +} diff --git a/libjava/java/net/NetPermission.java b/libjava/java/net/NetPermission.java index 6b796be7f04a..38a15c48ab7a 100644 --- a/libjava/java/net/NetPermission.java +++ b/libjava/java/net/NetPermission.java @@ -39,22 +39,23 @@ package java.net; import java.security.BasicPermission; + /** * This class is used to model miscellaneous network permissions. It is - * a subclass of BasicPermission. This means that it models a - * "boolean" permission. One that you either have or do not have. Thus - * there is no permitted action list associated with this object. + * a subclass of BasicPermission. This means that it models a + * "boolean" permission. One that you either have or do not have. Thus + * there is no permitted action list associated with this object. * * The following permission names are defined for this class: - * + * *

* * @author Aaron M. Renn (arenn@urbanophile.com) @@ -75,8 +76,8 @@ public final class NetPermission extends BasicPermission } /** - * Initializes a new instance of NetPermission with the - * specified name and perms. Note that the perms field is irrelevant and is + * Initializes a new instance of NetPermission with the + * specified name and perms. Note that the perms field is irrelevant and is * ignored. This constructor should never need to be used. * * @param name The name of this permission diff --git a/libjava/java/net/NetworkInterface.java b/libjava/java/net/NetworkInterface.java index f6d374898364..e7f7290febcc 100644 --- a/libjava/java/net/NetworkInterface.java +++ b/libjava/java/net/NetworkInterface.java @@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -41,6 +41,7 @@ import gnu.classpath.Configuration; import java.util.Enumeration; import java.util.Vector; + /** * This class models a network interface on the host computer. A network * interface contains a name (typically associated with a specific @@ -54,25 +55,22 @@ import java.util.Vector; public final class NetworkInterface { static - { - if (Configuration.INIT_LOAD_LIBRARY) - { - System.loadLibrary ("javanet"); - } - } + { + if (Configuration.INIT_LOAD_LIBRARY) + System.loadLibrary("javanet"); + } private String name; - private Vector inetAddresses; - private NetworkInterface (String name, InetAddress address) + private NetworkInterface(String name, InetAddress address) { this.name = name; - this.inetAddresses = new Vector (1, 1); - this.inetAddresses.add (address); + this.inetAddresses = new Vector(1, 1); + this.inetAddresses.add(address); } - private native static Vector getRealNetworkInterfaces () + private static native Vector getRealNetworkInterfaces() throws SocketException; /** @@ -80,45 +78,45 @@ public final class NetworkInterface * * @return The name of the interface. */ - public String getName () + public String getName() { return name; } /** * Returns all available addresses of the network interface - * + * * If a @see SecurityManager is available all addresses are checked * with @see SecurityManager::checkConnect() if they are available. - * Only InetAddresses are returned where the security manager + * Only InetAddresses are returned where the security manager * doesn't throw an exception. - * + * * @return An enumeration of all addresses. */ - public Enumeration getInetAddresses () + public Enumeration getInetAddresses() { - SecurityManager s = System.getSecurityManager (); + SecurityManager s = System.getSecurityManager(); 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 (); - addresses.hasMoreElements (); ) + for (Enumeration addresses = inetAddresses.elements(); + addresses.hasMoreElements();) { - InetAddress addr = (InetAddress) addresses.nextElement (); + InetAddress addr = (InetAddress) addresses.nextElement(); try { - s.checkConnect (addr.getHostAddress (), 58000); - tmpInetAddresses.add (addr); + s.checkConnect(addr.getHostAddress(), 58000); + tmpInetAddresses.add(addr); } catch (SecurityException e) { } - } + } - return tmpInetAddresses.elements (); + return tmpInetAddresses.elements(); } /** @@ -126,7 +124,7 @@ public final class NetworkInterface * * @return The display name of the interface */ - public String getDisplayName () + public String getDisplayName() { return name; } @@ -139,21 +137,20 @@ public final class NetworkInterface * @exception SocketException If an error occurs * @exception NullPointerException If the specified name is null */ - public static NetworkInterface getByName (String name) + public static NetworkInterface getByName(String name) throws SocketException { - Vector networkInterfaces = getRealNetworkInterfaces (); + Vector networkInterfaces = getRealNetworkInterfaces(); - for (Enumeration e = networkInterfaces.elements (); - e.hasMoreElements (); ) + for (Enumeration e = networkInterfaces.elements(); e.hasMoreElements();) { - NetworkInterface tmp = (NetworkInterface) e.nextElement (); - - if (name.equals (tmp.getName ())) - return tmp; + NetworkInterface tmp = (NetworkInterface) e.nextElement(); + + if (name.equals(tmp.getName())) + 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 * @exception SocketException If an error occurs * @exception NullPointerException If the specified addess is null */ - public static NetworkInterface getByInetAddress (InetAddress addr) + public static NetworkInterface getByInetAddress(InetAddress addr) throws SocketException { - Vector networkInterfaces = getRealNetworkInterfaces (); - - for (Enumeration interfaces = networkInterfaces.elements (); - interfaces.hasMoreElements (); ) + Vector networkInterfaces = getRealNetworkInterfaces(); + + for (Enumeration interfaces = networkInterfaces.elements(); + interfaces.hasMoreElements();) { - NetworkInterface tmp = (NetworkInterface) interfaces.nextElement (); - - for (Enumeration addresses = tmp.inetAddresses.elements (); - addresses.hasMoreElements (); ) - { - if (addr.equals ((InetAddress) addresses.nextElement ())) - return tmp; - } + NetworkInterface tmp = (NetworkInterface) interfaces.nextElement(); + + for (Enumeration addresses = tmp.inetAddresses.elements(); + addresses.hasMoreElements();) + { + if (addr.equals((InetAddress) addresses.nextElement())) + return tmp; + } } - throw new SocketException ( - "no network interface is bound to such an IP address"); + throw new SocketException("no network interface is bound to such an IP address"); } /** @@ -191,8 +187,7 @@ public final class NetworkInterface * * @exception SocketException If an error occurs */ - public static Enumeration getNetworkInterfaces () - throws SocketException + public static Enumeration getNetworkInterfaces() throws SocketException { Vector networkInterfaces = getRealNetworkInterfaces(); @@ -206,44 +201,43 @@ public final class NetworkInterface * Checks if the current instance is equal to obj * * @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; - + NetworkInterface tmp = (NetworkInterface) obj; - return (name.equals (tmp.name) - && inetAddresses.equals (tmp.inetAddresses)); + return (name.equals(tmp.name) && inetAddresses.equals(tmp.inetAddresses)); } /** * Returns the hashcode of the current instance */ - public int hashCode () + public int hashCode() { // FIXME: hash correctly - return name.hashCode () + inetAddresses.hashCode (); + return name.hashCode() + inetAddresses.hashCode(); } /** * Returns a string representation of the interface */ - public String toString () + public String toString() { // FIXME: check if this is correct String result; - String separator = System.getProperty ("line.separator"); + String separator = System.getProperty("line.separator"); - result = "name: " + getDisplayName () + " (" + getName () + - ") addresses:" + separator; + result = + "name: " + getDisplayName() + " (" + getName() + ") addresses:" + + separator; - for (Enumeration e = inetAddresses.elements (); - e.hasMoreElements (); ) + for (Enumeration e = inetAddresses.elements(); e.hasMoreElements();) { - InetAddress address = (InetAddress) e.nextElement (); - result += address.toString () + ";" + separator; + InetAddress address = (InetAddress) e.nextElement(); + result += address.toString() + ";" + separator; } return result; diff --git a/libjava/java/net/NoRouteToHostException.java b/libjava/java/net/NoRouteToHostException.java index 2f7fb7276d71..d13389386591 100644 --- a/libjava/java/net/NoRouteToHostException.java +++ b/libjava/java/net/NoRouteToHostException.java @@ -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 exception statement from your version. */ - package java.net; + /** * This exception indicates that there is no TCP/IP route to the requested * host. This is often due to a misconfigured routing table. diff --git a/libjava/java/net/PasswordAuthentication.java b/libjava/java/net/PasswordAuthentication.java index 97554e3dde42..910803a8f3a5 100644 --- a/libjava/java/net/PasswordAuthentication.java +++ b/libjava/java/net/PasswordAuthentication.java @@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -37,6 +37,7 @@ exception statement from your version. */ package java.net; + /** * This class serves a container for username/password pairs. * @@ -50,7 +51,7 @@ public final class PasswordAuthentication */ /** - * The username + * The username */ private String username; @@ -66,7 +67,7 @@ public final class PasswordAuthentication */ /** - * Creates a new PasswordAuthentication object from the + * Creates a new PasswordAuthentication object from the * specified username and password. * * @param username The username for this object @@ -91,9 +92,9 @@ public final class PasswordAuthentication */ public String getUserName() { - return(username); + return (username); } - + /** * Returns the password associated with this object * @@ -101,8 +102,6 @@ public final class PasswordAuthentication */ public char[] getPassword() { - return(password); + return (password); } - } // class PasswordAuthentication - diff --git a/libjava/java/net/PortUnreachableException.java b/libjava/java/net/PortUnreachableException.java index b6abfe95a92c..def02636e58c 100644 --- a/libjava/java/net/PortUnreachableException.java +++ b/libjava/java/net/PortUnreachableException.java @@ -37,6 +37,7 @@ exception statement from your version. */ package java.net; + /** * This exception signals that an ICMP port unreachable datagram has been * received. @@ -69,4 +70,3 @@ public class PortUnreachableException extends SocketException super(message); } } // class PortUnreachableException - diff --git a/libjava/java/net/ProtocolException.java b/libjava/java/net/ProtocolException.java index c50bbcf6e8f3..d058113495e8 100644 --- a/libjava/java/net/ProtocolException.java +++ b/libjava/java/net/ProtocolException.java @@ -39,6 +39,7 @@ package java.net; import java.io.IOException; + /** * This exception indicates that some sort of low level protocol * exception occurred. Look in the descriptive message (if any) for diff --git a/libjava/java/net/ServerSocket.java b/libjava/java/net/ServerSocket.java index be3f8008d86b..037421d682a5 100644 --- a/libjava/java/net/ServerSocket.java +++ b/libjava/java/net/ServerSocket.java @@ -8,7 +8,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -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 exception statement from your version. */ - package java.net; import gnu.java.net.PlainSocketImpl; @@ -44,6 +43,7 @@ import java.io.IOException; import java.nio.channels.IllegalBlockingModeException; import java.nio.channels.ServerSocketChannel; + /* Written using on-line Java Platform 1.2 API Specification. * Status: I believe all methods are implemented. */ @@ -55,7 +55,7 @@ import java.nio.channels.ServerSocketChannel; * server sockets are ready to communicate with one another utilizing * whatever application layer protocol they desire. * - * As with the Socket class, most instance methods of this class + * As with the Socket class, most instance methods of this class * simply redirect their calls to an implementation class. * * @author Aaron M. Renn (arenn@urbanophile.com) @@ -78,13 +78,14 @@ public class ServerSocket * True if socket is bound. */ private boolean bound; - + /* * This constructor is only used by java.nio. */ + // FIXME: Workaround a bug in gcj. //ServerSocket (PlainSocketImpl impl) throws IOException - ServerSocket (SocketImpl impl) throws IOException + ServerSocket(SocketImpl impl) throws IOException { if (impl == null) throw new NullPointerException("impl may not be null"); @@ -96,16 +97,17 @@ public class ServerSocket /* * This method is only used by java.nio. */ + // FIXME: Workaround a bug in gcj. //PlainSocketImpl getImpl() SocketImpl getImpl() { return impl; } - + /** * Constructor that simply sets the implementation. - * + * * @exception IOException If an error occurs * * @specnote This constructor is public since JDK 1.4 @@ -126,13 +128,12 @@ public class ServerSocket * connection queue on this socket will be set to 50. * * @param port The port number to bind to - * + * * @exception IOException If an error occurs * @exception SecurityException If a security manager exists and its * checkListen method doesn't allow the operation */ - public ServerSocket (int port) - throws IOException + public ServerSocket(int port) throws IOException { this(port, 50); } @@ -150,8 +151,7 @@ public class ServerSocket * @exception SecurityException If a security manager exists and its * checkListen method doesn't allow the operation */ - public ServerSocket (int port, int backlog) - throws IOException + public ServerSocket(int port, int backlog) throws IOException { this(port, backlog, null); } @@ -173,13 +173,13 @@ public class ServerSocket * * @since 1.1 */ - public ServerSocket (int port, int backlog, InetAddress bindAddr) + public ServerSocket(int port, int backlog, InetAddress bindAddr) throws IOException { this(); // bind/listen socket - bind (new InetSocketAddress (bindAddr, port), backlog); + bind(new InetSocketAddress(bindAddr, port), backlog); } /** @@ -191,21 +191,20 @@ public class ServerSocket * @exception IllegalArgumentException If address type is not supported * @exception SecurityException If a security manager exists and its * checkListen method doesn't allow the operation - * + * * @since 1.4 */ - public void bind (SocketAddress endpoint) - throws IOException + public void bind(SocketAddress endpoint) throws IOException { - bind (endpoint, 50); + bind(endpoint, 50); } - + /** * Binds the server socket to a specified socket address * * @param endpoint The socket address to bind to * @param backlog The length of the pending connection queue - * + * * @exception IOException If an error occurs * @exception IllegalArgumentException If address type is not supported * @exception SecurityException If a security manager exists and its @@ -213,26 +212,27 @@ public class ServerSocket * * @since 1.4 */ - public void bind (SocketAddress endpoint, int backlog) throws IOException + public void bind(SocketAddress endpoint, int backlog) + throws IOException { if (isClosed()) throw new SocketException("ServerSocket is closed"); - + if (! (endpoint instanceof InetSocketAddress)) - throw new IllegalArgumentException ("Address type not supported"); + throw new IllegalArgumentException("Address type not supported"); InetSocketAddress tmp = (InetSocketAddress) endpoint; - SecurityManager s = System.getSecurityManager (); + SecurityManager s = System.getSecurityManager(); if (s != null) - s.checkListen (tmp.getPort ()); + s.checkListen(tmp.getPort()); InetAddress addr = tmp.getAddress(); - + // Initialize addr with 0.0.0.0. if (addr == null) addr = InetAddress.ANY_IF; - + try { impl.bind(addr, tmp.getPort()); @@ -241,21 +241,21 @@ public class ServerSocket } catch (IOException exception) { - close(); - throw exception; + close(); + throw exception; } catch (RuntimeException exception) { - close(); - throw exception; + close(); + throw exception; } catch (Error error) { - close(); - throw error; + close(); + throw error; } } - + /** * This method returns the local address to which this socket is bound * @@ -263,17 +263,17 @@ public class ServerSocket */ public InetAddress getInetAddress() { - if (!isBound()) + if (! isBound()) return null; - + try { - return (InetAddress) impl.getOption (SocketOptions.SO_BINDADDR); + return (InetAddress) impl.getOption(SocketOptions.SO_BINDADDR); } catch (SocketException e) { - // This never happens as we are bound. - return null; + // This never happens as we are bound. + return null; } } @@ -284,30 +284,34 @@ public class ServerSocket */ public int getLocalPort() { - if (!isBound()) + if (! isBound()) return -1; - + return impl.getLocalPort(); } /** * Returns the local socket address * + * @return the local socket address, null if not bound + * * @since 1.4 */ public SocketAddress getLocalSocketAddress() { - if (!isBound()) + if (! isBound()) return null; - + return new InetSocketAddress(getInetAddress(), getLocalPort()); } /** - * Accepts a new connection and returns a connected Socket - * instance representing that connection. This method will block until a + * Accepts a new connection and returns a connected Socket + * instance representing that connection. This method will block until a * connection is available. * + * @return socket object for the just accepted connection + * * @exception IOException If an error occurs * @exception SecurityException If a security manager exists and its * checkListen method doesn't allow the operation @@ -316,17 +320,17 @@ public class ServerSocket * @exception SocketTimeoutException If a timeout was previously set with * 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) - sm.checkListen (impl.getLocalPort ()); + sm.checkListen(impl.getLocalPort()); Socket socket = new Socket(); - + try { - implAccept(socket); + implAccept(socket); } catch (IOException e) { @@ -337,15 +341,15 @@ public class ServerSocket catch (IOException e2) { } - + throw e; } - + return socket; } /** - * This protected method is used to help subclasses override + * This protected method is used to help subclasses override * ServerSocket.accept(). The passed in socket will be * connected when this method returns. * @@ -357,12 +361,11 @@ public class ServerSocket * * @since 1.1 */ - protected final void implAccept (Socket socket) - throws IOException + protected final void implAccept(Socket socket) throws IOException { if (isClosed()) throw new SocketException("ServerSocket is closed"); - + // The Sun spec says that if we have an associated channel and // it is in non-blocking mode, we throw an IllegalBlockingModeException. // However, in our implementation if the channel itself initiated this @@ -380,11 +383,11 @@ public class ServerSocket * * @exception IOException If an error occurs */ - public void close () throws IOException + public void close() throws IOException { if (isClosed()) return; - + impl.close(); impl = null; bound = false; @@ -399,6 +402,8 @@ public class ServerSocket * * The socket only has a ServerSocketChannel if its created * by ServerSocketChannel.open. + * + * @return the associated socket channel, null if none exists * * @since 1.4 */ @@ -409,6 +414,8 @@ public class ServerSocket /** * Returns true when the socket is bound, otherwise false + * + * @return true if socket is bound, false otherwise * * @since 1.4 */ @@ -419,6 +426,8 @@ public class ServerSocket /** * Returns true if the socket is closed, otherwise false + * + * @return true if socket is closed, false otherwise * * @since 1.4 */ @@ -429,7 +438,7 @@ public class ServerSocket /** * Sets the value of SO_TIMEOUT. A value of 0 implies that SO_TIMEOUT is - * disabled (ie, operations never time out). This is the number of + * disabled (ie, operations never time out). This is the number of * milliseconds a socket operation can block before an * InterruptedIOException is thrown. * @@ -439,11 +448,11 @@ public class ServerSocket * * @since 1.1 */ - public void setSoTimeout (int timeout) throws SocketException + public void setSoTimeout(int timeout) throws SocketException { if (isClosed()) throw new SocketException("ServerSocket is closed"); - + if (timeout < 0) throw new IllegalArgumentException("SO_TIMEOUT value must be >= 0"); @@ -462,113 +471,113 @@ public class ServerSocket * * @since 1.1 */ - public int getSoTimeout () throws IOException + public int getSoTimeout() throws IOException { if (isClosed()) throw new SocketException("ServerSocket is closed"); - + Object timeout = impl.getOption(SocketOptions.SO_TIMEOUT); - if (!(timeout instanceof Integer)) + if (! (timeout instanceof Integer)) throw new IOException("Internal Error"); - return ((Integer)timeout).intValue(); + return ((Integer) timeout).intValue(); } /** * Enables/Disables the SO_REUSEADDR option + * + * @param on true if SO_REUSEADDR should be enabled, false otherwise * * @exception SocketException If an error occurs - * + * * @since 1.4 */ - public void setReuseAddress (boolean on) - throws SocketException + public void setReuseAddress(boolean on) throws SocketException { if (isClosed()) 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 - * + * + * @return true if SO_REUSEADDR is set, false otherwise + * * @exception SocketException If an error occurs - * + * * @since 1.4 */ - public boolean getReuseAddress() - throws SocketException + public boolean getReuseAddress() throws SocketException { if (isClosed()) throw new SocketException("ServerSocket is closed"); - - Object reuseaddr = impl.getOption (SocketOptions.SO_REUSEADDR); - if (!(reuseaddr instanceof Boolean)) - throw new SocketException ("Internal Error"); - - return ((Boolean) reuseaddr).booleanValue (); + Object reuseaddr = impl.getOption(SocketOptions.SO_REUSEADDR); + + if (! (reuseaddr instanceof Boolean)) + throw new SocketException("Internal Error"); + + return ((Boolean) reuseaddr).booleanValue(); } /** * This method sets the value for the system level socket option * SO_RCVBUF to the specified value. Note that valid values for this * option are specific to a given operating system. - * + * * @param size The new receive buffer size. - * + * * @exception SocketException If an error occurs or Socket is not connected * @exception IllegalArgumentException If size is 0 or negative * * @since 1.4 */ - public void setReceiveBufferSize (int size) - throws SocketException + public void setReceiveBufferSize(int size) throws SocketException { if (isClosed()) throw new SocketException("ServerSocket is closed"); - - if (size <= 0) - throw new IllegalArgumentException ("SO_RCVBUF value must be > 0"); - impl.setOption (SocketOptions.SO_RCVBUF, new Integer (size)); + if (size <= 0) + throw new IllegalArgumentException("SO_RCVBUF value must be > 0"); + + impl.setOption(SocketOptions.SO_RCVBUF, new Integer(size)); } /** * This method returns the value of the system level socket option * SO_RCVBUF, which is used by the operating system to tune buffer * sizes for data transfers. - * + * * @return The receive buffer size. - * + * * @exception SocketException If an error occurs or Socket is not connected - * + * * @since 1.4 */ - public int getReceiveBufferSize () - throws SocketException + public int getReceiveBufferSize() throws SocketException { if (isClosed()) throw new SocketException("ServerSocket is closed"); - - Object buf = impl.getOption (SocketOptions.SO_RCVBUF); - if (!(buf instanceof Integer)) - throw new SocketException ("Internal Error: Unexpected type"); - - return ((Integer) buf).intValue (); + Object buf = impl.getOption(SocketOptions.SO_RCVBUF); + + if (! (buf instanceof Integer)) + throw new SocketException("Internal Error: Unexpected type"); + + return ((Integer) buf).intValue(); } /** - * Returns the value of this socket as a String. + * Returns the value of this socket as a String. * * @return This socket represented as a String. */ - public String toString () + public String toString() { - if (!isBound()) + if (! isBound()) return "ServerSocket[unbound]"; return ("ServerSocket[addr=" + getInetAddress() @@ -578,19 +587,21 @@ public class ServerSocket } /** - * Sets the SocketImplFactory for all + * Sets the SocketImplFactory for all * ServerSocket's. This may only be done * once per virtual machine. Subsequent attempts will generate an * exception. Note that a SecurityManager check is made prior * to setting the factory. If insufficient privileges exist to set the * factory, an exception will be thrown * + * @param fac the factory to set + * * @exception SecurityException If this operation is not allowed by the * SecurityManager. * @exception SocketException If the factory object is already defined * @exception IOException If any other error occurs */ - public static synchronized void setSocketFactory (SocketImplFactory fac) + public static synchronized void setSocketFactory(SocketImplFactory fac) throws IOException { factory = fac; diff --git a/libjava/java/net/Socket.java b/libjava/java/net/Socket.java index 4c14e8d99b34..789e40616620 100644 --- a/libjava/java/net/Socket.java +++ b/libjava/java/net/Socket.java @@ -8,7 +8,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -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 exception statement from your version. */ - package java.net; import gnu.java.net.PlainSocketImpl; -import java.io.InputStream; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; -import java.nio.channels.SocketChannel; import java.nio.channels.IllegalBlockingModeException; +import java.nio.channels.SocketChannel; + /* Written using on-line Java Platform 1.2 API Specification. * Status: I believe all methods are implemented. @@ -56,11 +56,11 @@ import java.nio.channels.IllegalBlockingModeException; *

* This class does not actually do any work. Instead, it redirects all of * its calls to a socket implementation object which implements the - * SocketImpl interface. The implementation class is - * instantiated by factory class that implements the + * SocketImpl interface. The implementation class is + * instantiated by factory class that implements the * SocketImplFactory interface. A default * factory is provided, however the factory may be set by a call to - * the setSocketImplFactory method. Note that this may only be + * the setSocketImplFactory method. Note that this may only be * done once per virtual machine. If a subsequent attempt is made to set the * factory, a SocketException will be thrown. * @@ -81,7 +81,8 @@ public class Socket 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; @@ -101,14 +102,14 @@ public class Socket private boolean outputShutdown; /** - * Initializes a new instance of Socket object without - * connecting to a remote host. This useful for subclasses of socket that + * Initializes a new instance of Socket object without + * connecting to a remote host. This useful for subclasses of socket that * might want this behavior. * * @specnote This constructor is public since JDK 1.4 * @since 1.1 */ - public Socket () + public Socket() { if (factory != null) impl = factory.createSocketImpl(); @@ -119,7 +120,7 @@ public class Socket /** * Initializes a new instance of Socket object without * connecting to a remote host. This is useful for subclasses of socket - * that might want this behavior. + * that might want this behavior. *

* Additionally, this socket will be created using the supplied * implementation class instead the default class or one returned by a @@ -133,7 +134,7 @@ public class Socket * * @since 1.1 */ - protected Socket (SocketImpl impl) throws SocketException + protected Socket(SocketImpl impl) throws SocketException { if (impl == null) this.impl = new PlainSocketImpl(); @@ -142,7 +143,7 @@ public class Socket } /** - * Initializes a new instance of Socket and connects to the + * Initializes a new instance of Socket and connects to the * hostname and port specified as arguments. * * @param host The name of the host to connect to @@ -154,14 +155,14 @@ public class Socket * @exception SecurityException If a security manager exists and its * checkConnect method doesn't allow the operation */ - public Socket (String host, int port) + public Socket(String host, int port) throws UnknownHostException, IOException { this(InetAddress.getByName(host), port, null, 0, true); } /** - * Initializes a new instance of Socket and connects to the + * Initializes a new instance of Socket and connects to the * address and port number specified as arguments. * * @param address The address to connect to @@ -171,15 +172,14 @@ public class Socket * @exception SecurityException If a security manager exists and its * checkConnect method doesn't allow the operation */ - public Socket (InetAddress address, int port) - throws IOException + public Socket(InetAddress address, int port) throws IOException { this(address, port, null, 0, true); } /** - * Initializes a new instance of Socket that connects to the - * named host on the specified port and binds to the specified local address + * Initializes a new instance of Socket that connects to the + * named host on the specified port and binds to the specified local address * and port. * * @param host The name of the remote host to connect to. @@ -194,15 +194,15 @@ public class Socket * * @since 1.1 */ - public Socket (String host, int port, - InetAddress localAddr, int localPort) throws IOException + public Socket(String host, int port, InetAddress localAddr, int localPort) + throws IOException { this(InetAddress.getByName(host), port, localAddr, localPort, true); } /** - * Initializes a new instance of Socket and connects to the - * address and port number specified as arguments, plus binds to the + * Initializes a new instance of Socket and connects to the + * address and port number specified as arguments, plus binds to the * specified local address and port. * * @param address The remote address to connect to @@ -216,16 +216,16 @@ public class Socket * * @since 1.1 */ - public Socket (InetAddress address, int port, - InetAddress localAddr, int localPort) throws IOException + public Socket(InetAddress address, int port, InetAddress localAddr, + int localPort) throws IOException { this(address, port, localAddr, localPort, true); } /** - * Initializes a new instance of Socket and connects to the - * hostname and port specified as arguments. If the stream argument is set - * to true, then a stream socket is created. If it is + * Initializes a new instance of Socket and connects to the + * hostname and port specified as arguments. If the stream argument is set + * to true, then a stream socket is created. If it is * false, a datagram socket is created. * * @param host The name of the host to connect to @@ -240,20 +240,21 @@ public class Socket * @deprecated Use the DatagramSocket class to create * 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); } /** - * Initializes a new instance of Socket and connects to the - * address and port number specified as arguments. If the stream param is - * true, a stream socket will be created, otherwise a datagram + * Initializes a new instance of Socket and connects to the + * address and port number specified as arguments. If the stream param is + * true, a stream socket will be created, otherwise a datagram * socket is created. * * @param host The address to connect to * @param port The port number to connect to - * @param stream true to create a stream socket, + * @param stream true to create a stream socket, * false to create a datagram socket. * * @exception IOException If an error occurs @@ -263,7 +264,8 @@ public class Socket * @deprecated Use the DatagramSocket class to create * 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); } @@ -296,11 +298,11 @@ public class Socket // bind socket SocketAddress bindaddr = - laddr == null ? null : new InetSocketAddress (laddr, lport); - bind (bindaddr); - + laddr == null ? null : new InetSocketAddress(laddr, lport); + bind(bindaddr); + // 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, // i.e. '0' and if localAddr is unspecified, use getLocalAddress() as @@ -308,12 +310,11 @@ public class Socket } // This has to be accessible from java.net.ServerSocket. - SocketImpl getImpl() - throws SocketException + SocketImpl getImpl() throws SocketException { try { - if (!implCreated) + if (! implCreated) { impl.create(true); implCreated = true; @@ -336,10 +337,10 @@ public class Socket * @exception SecurityException If a security manager exists and its * checkConnect method doesn't allow the operation * @exception IllegalArgumentException If the address type is not supported - * + * * @since 1.4 */ - public void bind (SocketAddress bindpoint) throws IOException + public void bind(SocketAddress bindpoint) throws IOException { if (isClosed()) throw new SocketException("socket is closed"); @@ -347,36 +348,36 @@ public class Socket // 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. if (bindpoint == null) - bindpoint = new InetSocketAddress (InetAddress.ANY_IF, 0); - - if ( !(bindpoint instanceof InetSocketAddress)) - throw new IllegalArgumentException (); + bindpoint = new InetSocketAddress(InetAddress.ANY_IF, 0); + + if (! (bindpoint instanceof InetSocketAddress)) + throw new IllegalArgumentException(); InetSocketAddress tmp = (InetSocketAddress) bindpoint; - + // bind to address/port try { - getImpl().bind (tmp.getAddress(), tmp.getPort()); + getImpl().bind(tmp.getAddress(), tmp.getPort()); bound = true; } catch (IOException exception) { - close (); - throw exception; + close(); + throw exception; } catch (RuntimeException exception) { - close (); - throw exception; + close(); + throw exception; } catch (Error error) { - close (); - throw error; + close(); + throw error; } } - + /** * Connects the socket with a remote address. * @@ -386,13 +387,12 @@ public class Socket * @exception IllegalArgumentException If the addess type is not supported * @exception IllegalBlockingModeException If this socket has an associated * channel, and the channel is in non-blocking mode - * + * * @since 1.4 */ - public void connect (SocketAddress endpoint) - throws IOException + public void connect(SocketAddress endpoint) throws IOException { - connect (endpoint, 0); + connect(endpoint, 0); } /** @@ -401,7 +401,7 @@ public class Socket * until established or an error occurs. * * @param endpoint The address to connect to - * @param timeout The length of the timeout in milliseconds, or + * @param timeout The length of the timeout in milliseconds, or * 0 to indicate no timeout. * * @exception IOException If an error occurs @@ -409,15 +409,15 @@ public class Socket * @exception IllegalBlockingModeException If this socket has an associated * channel, and the channel is in non-blocking mode * @exception SocketTimeoutException If the timeout is reached - * + * * @since 1.4 */ - public void connect (SocketAddress endpoint, int timeout) + public void connect(SocketAddress endpoint, int timeout) throws IOException { if (isClosed()) throw new SocketException("socket is closed"); - + if (! (endpoint instanceof InetSocketAddress)) throw new IllegalArgumentException("unsupported address type"); @@ -425,32 +425,31 @@ public class Socket // it is in non-blocking mode, we throw an IllegalBlockingModeException. // However, in our implementation if the channel itself initiated this // operation, then we must honor it regardless of its blocking mode. - if (getChannel() != null - && !getChannel().isBlocking () - && !((PlainSocketImpl) getImpl()).isInChannelOperation()) - throw new IllegalBlockingModeException (); - - if (!isBound ()) - bind (null); + if (getChannel() != null && ! getChannel().isBlocking() + && ! ((PlainSocketImpl) getImpl()).isInChannelOperation()) + throw new IllegalBlockingModeException(); + + if (! isBound()) + bind(null); try { - getImpl().connect (endpoint, timeout); + getImpl().connect(endpoint, timeout); } catch (IOException exception) { - close (); - throw exception; + close(); + throw exception; } catch (RuntimeException exception) { - close (); - throw exception; + close(); + throw exception; } catch (Error error) { - close (); - throw error; + close(); + throw error; } } @@ -460,9 +459,9 @@ public class Socket * * @return The remote address this socket is connected to */ - public InetAddress getInetAddress () + public InetAddress getInetAddress() { - if (!isConnected()) + if (! isConnected()) return null; try @@ -485,20 +484,20 @@ public class Socket * * @since 1.1 */ - public InetAddress getLocalAddress () + public InetAddress getLocalAddress() { InetAddress addr = null; - + try { - addr = (InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR); + addr = (InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR); } - catch(SocketException e) + catch (SocketException e) { - // (hopefully) shouldn't happen - // throw new java.lang.InternalError - // ("Error in PlainSocketImpl.getOption"); - return null; + // (hopefully) shouldn't happen + // throw new java.lang.InternalError + // ("Error in PlainSocketImpl.getOption"); + return null; } // FIXME: According to libgcj, checkConnect() is supposed to be called @@ -519,9 +518,9 @@ public class Socket * * @return The remote port this socket is connected to */ - public int getPort () + public int getPort() { - if (!isConnected()) + if (! isConnected()) return 0; try @@ -543,11 +542,11 @@ public class Socket * * @return The local port */ - public int getLocalPort () + public int getLocalPort() { - if (!isBound()) + if (! isBound()) return -1; - + try { if (getImpl() != null) @@ -562,21 +561,22 @@ public class Socket } /** - * If the socket is already bound this returns the local SocketAddress, - * otherwise null + * Returns local socket address. + * + * @return the local socket address, null if not bound * * @since 1.4 */ public SocketAddress getLocalSocketAddress() { - if (!isBound()) + if (! isBound()) return null; - - InetAddress addr = getLocalAddress (); + + InetAddress addr = getLocalAddress(); try { - return new InetSocketAddress (addr, getImpl().getLocalPort()); + return new InetSocketAddress(addr, getImpl().getLocalPort()); } catch (SocketException e) { @@ -586,19 +586,21 @@ public class Socket } /** - * If the socket is already connected this returns the remote SocketAddress, - * otherwise null + * Returns the remote socket address. + * + * @return the remote socket address, null of not connected * * @since 1.4 */ public SocketAddress getRemoteSocketAddress() { - if (!isConnected ()) + if (! isConnected()) return null; try { - return new InetSocketAddress (getImpl().getInetAddress (), getImpl().getPort ()); + return new InetSocketAddress(getImpl().getInetAddress(), + getImpl().getPort()); } catch (SocketException e) { @@ -614,14 +616,14 @@ public class Socket * * @exception IOException If an error occurs or Socket is not connected */ - public InputStream getInputStream () throws IOException + public InputStream getInputStream() throws IOException { if (isClosed()) throw new SocketException("socket is closed"); - - if (!isConnected()) + + if (! isConnected()) throw new IOException("not connected"); - + return getImpl().getInputStream(); } @@ -632,42 +634,42 @@ public class Socket * * @exception IOException If an error occurs or Socket is not connected */ - public OutputStream getOutputStream () throws IOException + public OutputStream getOutputStream() throws IOException { if (isClosed()) throw new SocketException("socket is closed"); - - if (!isConnected()) + + if (! isConnected()) throw new IOException("not connected"); - + return getImpl().getOutputStream(); } /** - * Sets the TCP_NODELAY option on the socket. + * Sets the TCP_NODELAY option on the socket. * * @param on true to enable, false to disable - * + * * @exception SocketException If an error occurs or Socket is not connected * * @since 1.1 */ - public void setTcpNoDelay (boolean on) throws SocketException + public void setTcpNoDelay(boolean on) throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - + getImpl().setOption(SocketOptions.TCP_NODELAY, Boolean.valueOf(on)); } /** - * Tests whether or not the TCP_NODELAY option is set on the socket. + * Tests whether or not the TCP_NODELAY option is set on the socket. * Returns true if enabled, false if disabled. When on it disables the * Nagle algorithm which means that packets are always send immediatly and * never merged together to reduce network trafic. * * @return Whether or not TCP_NODELAY is set - * + * * @exception SocketException If an error occurs or Socket not connected * * @since 1.1 @@ -676,17 +678,17 @@ public class Socket { if (isClosed()) throw new SocketException("socket is closed"); - + Object on = getImpl().getOption(SocketOptions.TCP_NODELAY); - + if (on instanceof Boolean) - return(((Boolean)on).booleanValue()); + return (((Boolean) on).booleanValue()); else throw new SocketException("Internal Error"); } /** - * Sets the value of the SO_LINGER option on the socket. If the + * Sets the value of the SO_LINGER option on the socket. If the * SO_LINGER option is set on a socket and there is still data waiting to * be sent when the socket is closed, then the close operation will block * until either that data is delivered or until the timeout period @@ -694,7 +696,7 @@ public class Socket * (platform specific?) * * @param on true to enable SO_LINGER, false to disable - * @param linger The SO_LINGER timeout in hundreths of a second or -1 if + * @param linger The SO_LINGER timeout in hundreths of a second or -1 if * SO_LINGER not set. * * @exception SocketException If an error occurs or Socket not connected @@ -706,25 +708,23 @@ public class Socket { if (isClosed()) throw new SocketException("socket is closed"); - - if (on == true) + + if (on) { - if (linger < 0) - throw new IllegalArgumentException("SO_LINGER must be >= 0"); + if (linger < 0) + throw new IllegalArgumentException("SO_LINGER must be >= 0"); - if (linger > 65535) - linger = 65535; + if (linger > 65535) + linger = 65535; - getImpl().setOption(SocketOptions.SO_LINGER, new Integer(linger)); + getImpl().setOption(SocketOptions.SO_LINGER, new Integer(linger)); } 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 * SO_LINGER option is set on a socket and there is still data waiting to * be sent when the socket is closed, then the close operation will block * until either that data is delivered or until the timeout period @@ -732,7 +732,7 @@ public class Socket * of a second (platform specific?)) if SO_LINGER is set, or -1 if * SO_LINGER is not set. * - * @return The SO_LINGER timeout in hundreths of a second or -1 + * @return The SO_LINGER timeout in hundreths of a second or -1 * if SO_LINGER not set * * @exception SocketException If an error occurs or Socket is not connected @@ -743,11 +743,11 @@ public class Socket { if (isClosed()) throw new SocketException("socket is closed"); - + Object linger = getImpl().getOption(SocketOptions.SO_LINGER); if (linger instanceof Integer) - return(((Integer)linger).intValue()); + return (((Integer) linger).intValue()); else return -1; } @@ -762,78 +762,78 @@ public class Socket * * @since 1.4 */ - public void sendUrgentData (int data) throws IOException + public void sendUrgentData(int data) throws IOException { if (isClosed()) throw new SocketException("socket is closed"); - - getImpl().sendUrgentData (data); + + getImpl().sendUrgentData(data); } /** * Enables/disables the SO_OOBINLINE option - * - * @param on True if SO_OOBLINE should be enabled - * + * + * @param on True if SO_OOBLINE should be enabled + * * @exception SocketException If an error occurs - * + * * @since 1.4 */ - public void setOOBInline (boolean on) throws SocketException + public void setOOBInline(boolean on) throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - + getImpl().setOption(SocketOptions.SO_OOBINLINE, Boolean.valueOf(on)); } /** * Returns the current setting of the SO_OOBINLINE option for this socket - * + * * @return True if SO_OOBINLINE is set, false otherwise. * * @exception SocketException If an error occurs - * + * * @since 1.4 */ - public boolean getOOBInline () throws SocketException + public boolean getOOBInline() throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - + Object buf = getImpl().getOption(SocketOptions.SO_OOBINLINE); if (buf instanceof Boolean) - return(((Boolean)buf).booleanValue()); + return (((Boolean) buf).booleanValue()); else throw new SocketException("Internal Error: Unexpected type"); } - + /** * Sets the value of the SO_TIMEOUT option on the socket. If this value * is set, and an read/write is performed that does not complete within * the timeout period, a short count is returned (or an EWOULDBLOCK signal * would be sent in Unix if no data had been read). A value of 0 for - * this option implies that there is no timeout (ie, operations will + * this option implies that there is no timeout (ie, operations will * block forever). On systems that have separate read and write timeout * values, this method returns the read timeout. This * value is in milliseconds. * - * @param timeout The length of the timeout in milliseconds, or + * @param timeout The length of the timeout in milliseconds, or * 0 to indicate no timeout. * * @exception SocketException If an error occurs or Socket not connected * * @since 1.1 */ - public synchronized void setSoTimeout (int timeout) throws SocketException + public synchronized void setSoTimeout(int timeout) throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - + if (timeout < 0) throw new IllegalArgumentException("SO_TIMEOUT value must be >= 0"); - + getImpl().setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout)); } @@ -842,26 +842,26 @@ public class Socket * is set, and an read/write is performed that does not complete within * the timeout period, a short count is returned (or an EWOULDBLOCK signal * would be sent in Unix if no data had been read). A value of 0 for - * this option implies that there is no timeout (ie, operations will + * this option implies that there is no timeout (ie, operations will * block forever). On systems that have separate read and write timeout * values, this method returns the read timeout. This * value is in thousandths of a second (implementation specific?). * - * @return The length of the timeout in thousandth's of a second or 0 + * @return The length of the timeout in thousandth's of a second or 0 * if not set * * @exception SocketException If an error occurs or Socket not connected * * @since 1.1 */ - public synchronized int getSoTimeout () throws SocketException + public synchronized int getSoTimeout() throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - + Object timeout = getImpl().getOption(SocketOptions.SO_TIMEOUT); if (timeout instanceof Integer) - return(((Integer)timeout).intValue()); + return (((Integer) timeout).intValue()); else return 0; } @@ -878,14 +878,14 @@ public class Socket * * @since 1.2 */ - public void setSendBufferSize (int size) throws SocketException + public void setSendBufferSize(int size) throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - + if (size <= 0) throw new IllegalArgumentException("SO_SNDBUF value must be > 0"); - + getImpl().setOption(SocketOptions.SO_SNDBUF, new Integer(size)); } @@ -900,15 +900,15 @@ public class Socket * * @since 1.2 */ - public int getSendBufferSize () throws SocketException + public int getSendBufferSize() throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - + Object buf = getImpl().getOption(SocketOptions.SO_SNDBUF); if (buf instanceof Integer) - return(((Integer)buf).intValue()); + return (((Integer) buf).intValue()); else throw new SocketException("Internal Error: Unexpected type"); } @@ -925,14 +925,14 @@ public class Socket * * @since 1.2 */ - public void setReceiveBufferSize (int size) throws SocketException + public void setReceiveBufferSize(int size) throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - + if (size <= 0) throw new IllegalArgumentException("SO_RCVBUF value must be > 0"); - + getImpl().setOption(SocketOptions.SO_RCVBUF, new Integer(size)); } @@ -947,15 +947,15 @@ public class Socket * * @since 1.2 */ - public int getReceiveBufferSize () throws SocketException + public int getReceiveBufferSize() throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - + Object buf = getImpl().getOption(SocketOptions.SO_RCVBUF); if (buf instanceof Integer) - return(((Integer)buf).intValue()); + return (((Integer) buf).intValue()); else throw new SocketException("Internal Error: Unexpected type"); } @@ -970,11 +970,11 @@ public class Socket * * @since 1.3 */ - public void setKeepAlive (boolean on) throws SocketException + public void setKeepAlive(boolean on) throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - + getImpl().setOption(SocketOptions.SO_KEEPALIVE, Boolean.valueOf(on)); } @@ -988,15 +988,15 @@ public class Socket * * @since 1.3 */ - public boolean getKeepAlive () throws SocketException + public boolean getKeepAlive() throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - + Object buf = getImpl().getOption(SocketOptions.SO_KEEPALIVE); if (buf instanceof Boolean) - return(((Boolean)buf).booleanValue()); + return (((Boolean) buf).booleanValue()); else throw new SocketException("Internal Error: Unexpected type"); } @@ -1006,11 +1006,11 @@ public class Socket * * @exception IOException If an error occurs */ - public synchronized void close () throws IOException + public synchronized void close() throws IOException { if (isClosed()) return; - + getImpl().close(); impl = null; bound = false; @@ -1024,15 +1024,14 @@ public class Socket * * @return The String representation of this Socket */ - public String toString () + public String toString() { try { if (isConnected()) - return ("Socket[addr=" + getImpl().getInetAddress() - + ",port=" + getImpl().getPort() - + ",localport=" + getImpl().getLocalPort() - + "]"); + return ("Socket[addr=" + getImpl().getInetAddress() + ",port=" + + getImpl().getPort() + ",localport=" + + getImpl().getLocalPort() + "]"); } catch (SocketException e) { @@ -1043,19 +1042,21 @@ public class Socket } /** - * Sets the SocketImplFactory. This may be done only once per - * virtual machine. Subsequent attempts will generate a + * Sets the SocketImplFactory. This may be done only once per + * virtual machine. Subsequent attempts will generate a * SocketException. Note that a SecurityManager - * check is made prior to setting the factory. If - * insufficient privileges exist to set the factory, then an + * check is made prior to setting the factory. If + * insufficient privileges exist to set the factory, then an * IOException will be thrown. * + * @param fac the factory to set + * * @exception SecurityException If the SecurityManager does * not allow this operation. * @exception SocketException If the SocketImplFactory is already defined * @exception IOException If any other error occurs */ - public static synchronized void setSocketImplFactory (SocketImplFactory fac) + public static synchronized void setSocketImplFactory(SocketImplFactory fac) throws IOException { // See if already set @@ -1084,7 +1085,7 @@ public class Socket { if (isClosed()) throw new SocketException("socket is closed"); - + getImpl().shutdownInput(); inputShutdown = true; } @@ -1100,7 +1101,7 @@ public class Socket { if (isClosed()) throw new SocketException("socket is closed"); - + getImpl().shutdownOutput(); outputShutdown = true; } @@ -1108,7 +1109,8 @@ public class 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 */ @@ -1126,55 +1128,57 @@ public class Socket * * @since 1.4 */ - public boolean getReuseAddress () throws SocketException + public boolean getReuseAddress() throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - - Object reuseaddr = getImpl().getOption (SocketOptions.SO_REUSEADDR); - if (!(reuseaddr instanceof Boolean)) - throw new SocketException ("Internal Error"); + Object reuseaddr = getImpl().getOption(SocketOptions.SO_REUSEADDR); - return ((Boolean) reuseaddr).booleanValue (); + if (! (reuseaddr instanceof Boolean)) + throw new SocketException("Internal Error"); + + return ((Boolean) reuseaddr).booleanValue(); } /** * 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 * * @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)); } /** * Returns the current traffic class * * @return The current traffic class. - * + * * @exception SocketException If an error occurs * * @see Socket#setTrafficClass(int tc) * * @since 1.4 */ - public int getTrafficClass () throws SocketException + public int getTrafficClass() throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - + Object obj = getImpl().getOption(SocketOptions.IP_TOS); if (obj instanceof Integer) - return ((Integer) obj).intValue (); + return ((Integer) obj).intValue(); else - throw new SocketException ("Unexpected type"); + throw new SocketException("Unexpected type"); } /** @@ -1189,15 +1193,15 @@ public class Socket * * @since 1.4 */ - public void setTrafficClass (int tc) throws SocketException + public void setTrafficClass(int tc) throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - + if (tc < 0 || tc > 255) 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 * * @since 1.4 */ - public boolean isConnected () + public boolean isConnected() { try { - return getImpl().getInetAddress () != null; + return getImpl().getInetAddress() != null; } catch (SocketException e) { @@ -1226,19 +1230,19 @@ public class Socket * * @since 1.4 */ - public boolean isBound () + public boolean isBound() { return bound; } /** * Checks if the socket is closed. - * + * * @return True if socket is closed, false otherwise. * * @since 1.4 */ - public boolean isClosed () + public boolean isClosed() { return impl == null; } @@ -1247,10 +1251,10 @@ public class Socket * Checks if the socket's input stream is shutdown * * @return True if input is shut down. - * + * * @since 1.4 */ - public boolean isInputShutdown () + public boolean isInputShutdown() { return inputShutdown; } @@ -1259,10 +1263,10 @@ public class Socket * Checks if the socket's output stream is shutdown * * @return True if output is shut down. - * + * * @since 1.4 */ - public boolean isOutputShutdown () + public boolean isOutputShutdown() { return outputShutdown; } diff --git a/libjava/java/net/SocketAddress.java b/libjava/java/net/SocketAddress.java index f3e67d84cc0a..d8239a416955 100644 --- a/libjava/java/net/SocketAddress.java +++ b/libjava/java/net/SocketAddress.java @@ -1,4 +1,4 @@ -/* SocketAddress.java -- +/* SocketAddress.java -- Copyright (C) 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,7 +39,8 @@ package java.net; import java.io.Serializable; -/** + +/** * Abstract base class for InetSocketAddress. * InetSocketAddress is to my knowledge the only derived * class. [Ronald] diff --git a/libjava/java/net/SocketException.java b/libjava/java/net/SocketException.java index 6494cae9d3ee..6b863606630d 100644 --- a/libjava/java/net/SocketException.java +++ b/libjava/java/net/SocketException.java @@ -39,6 +39,7 @@ package java.net; import java.io.IOException; + /** * This exception indicates that a generic error occurred related to an * operation on a socket. Check the descriptive message (if any) for diff --git a/libjava/java/net/SocketImpl.java b/libjava/java/net/SocketImpl.java index e43b49ed599b..8cfb9ef5a1d2 100644 --- a/libjava/java/net/SocketImpl.java +++ b/libjava/java/net/SocketImpl.java @@ -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 exception statement from your version. */ - package java.net; import java.io.FileDescriptor; -import java.io.InputStream; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; + /* Written using on-line Java Platform 1.2 API Specification. * Believed complete and correct. */ @@ -113,7 +113,8 @@ public abstract class SocketImpl implements SocketOptions * * @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. @@ -153,7 +154,8 @@ public abstract class SocketImpl implements SocketOptions * * @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 @@ -220,26 +222,38 @@ public abstract class SocketImpl implements SocketOptions * * @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 * * @return The remote address */ - protected InetAddress getInetAddress() { return address; } + protected InetAddress getInetAddress() + { + return address; + } /** * Returns the remote port this socket is connected to * * @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 * or not. * + * @return true if the socket implementation supports sending urgent data, + * false otherwise + * * @since 1.4 */ protected boolean supportsUrgentData() @@ -248,7 +262,7 @@ public abstract class SocketImpl implements SocketOptions // sending urgend data. return false; } - + /** * Sends one byte of urgent data to the socket. * @@ -258,15 +272,17 @@ public abstract class SocketImpl implements SocketOptions * * @since 1.4 */ - protected abstract void sendUrgentData(int data) - throws IOException; - + protected abstract void sendUrgentData(int data) throws IOException; + /** * Returns the local port this socket is bound to * * @return The local port */ - protected int getLocalPort() { return localport; } + protected int getLocalPort() + { + return localport; + } /** * Returns a String representing the remote host and port of @@ -276,10 +292,9 @@ public abstract class SocketImpl implements SocketOptions */ public String toString() { - return "[addr=" + ((address == null) ? "0.0.0.0/0.0.0.0" : - address.toString()) - + ",port=" + port - + ",localport=" + localport + "]"; + return "[addr=" + + ((address == null) ? "0.0.0.0/0.0.0.0" : address.toString()) + + ",port=" + port + ",localport=" + localport + "]"; } /** @@ -288,9 +303,9 @@ public abstract class SocketImpl implements SocketOptions * * @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 * * @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"); } } diff --git a/libjava/java/net/SocketImplFactory.java b/libjava/java/net/SocketImplFactory.java index 26074119ea12..84e92a521f16 100644 --- a/libjava/java/net/SocketImplFactory.java +++ b/libjava/java/net/SocketImplFactory.java @@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -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 exception statement from your version. */ - package java.net; + /** Written using on-line Java Platform 1.2 API Specification. * Status: Believed complete and correct. */ - /** * This interface defines one method which returns a SocketImpl * object. This should not be needed by ordinary applications. @@ -57,6 +56,4 @@ public interface SocketImplFactory * @return A SocketImpl object */ SocketImpl createSocketImpl(); - } // interface SocketImplFactory - diff --git a/libjava/java/net/SocketOptions.java b/libjava/java/net/SocketOptions.java index 149d7b73ff1a..7ccd887cc681 100644 --- a/libjava/java/net/SocketOptions.java +++ b/libjava/java/net/SocketOptions.java @@ -1,5 +1,5 @@ /* SocketOptions.java -- Implements options for sockets (duh!) - Copyright (C) 1998, 1999, 2000, 2001, + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -8,7 +8,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -38,15 +38,15 @@ exception statement from your version. */ package java.net; + /** * Written using on-line Java Platform 1.2 API Specification. * Status: Believed complete and correct. */ - /** - * This interface is used by SocketImpl and + * This interface is used by SocketImpl and * DatagramSocketImpl to implement options - * on sockets. + * on sockets. * * @since 1.2 * @@ -163,6 +163,4 @@ public interface SocketOptions * @exception SocketException If an error occurs */ Object getOption(int optionId) throws SocketException; - } // interface SocketOptions - diff --git a/libjava/java/net/SocketPermission.java b/libjava/java/net/SocketPermission.java index 35006173828b..e9d1402a7d42 100644 --- a/libjava/java/net/SocketPermission.java +++ b/libjava/java/net/SocketPermission.java @@ -1,5 +1,5 @@ /* 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. @@ -41,6 +41,7 @@ import java.io.Serializable; import java.security.Permission; import java.security.PermissionCollection; + /** * This class models a specific set of permssions for connecting to a * host. There are two elements to this, the host/port combination and @@ -64,18 +65,20 @@ import java.security.PermissionCollection; * value for a port (respectively) is used by default. Here are some * examples: *

* The permission list is a comma separated list of individual permissions. * These individual permissions are: *

- * accept
- * connect
- * listen
- * resolve
+ *

+ * accept
+ * connect
+ * listen
+ * resolve
+ * 
*

* The "listen" permission is only relevant if the host is localhost. If * any permission at all is specified, then resolve permission is implied to @@ -103,12 +106,12 @@ import java.security.PermissionCollection; * * @author Aaron M. Renn (arenn@urbanophile.com) */ -public final class SocketPermission extends Permission - implements Serializable +public final class SocketPermission extends Permission implements Serializable { static final long serialVersionUID = -7204263841984476862L; // FIXME: Needs serialization work, including readObject/writeObject methods. + /** * A hostname/port combination as described above */ @@ -120,7 +123,7 @@ public final class SocketPermission extends Permission private String actions; /** - * Initializes a new instance of SocketPermission with the + * Initializes a new instance of SocketPermission with the * specified host/port combination and actions string. * * @param hostport The hostname/port number combination @@ -136,18 +139,18 @@ public final class SocketPermission extends Permission /** * Tests this object for equality against another. This will be true if - * and only if the passed object is an instance of - * SocketPermission and both its hostname/port combination + * and only if the passed object is an instance of + * SocketPermission and both its hostname/port combination * and permissions string are identical. * * @param obj The object to test against for equality * - * @return true if object is equal to this object, + * @return true if object is equal to this object, * false otherwise. */ public boolean equals(Object obj) { - if (!(obj instanceof SocketPermission)) + if (! (obj instanceof SocketPermission)) return (false); if (((SocketPermission) obj).hostport.equals(hostport)) @@ -158,7 +161,7 @@ public final class SocketPermission extends Permission } /** - * Returns a hash code value for this object. Overrides the + * Returns a hash code value for this object. Overrides the * Permission.hashCode(). * * @return A hash code @@ -192,21 +195,21 @@ public final class SocketPermission extends Permission if (actions.indexOf("listen") != -1) if (found) - sb.append(",listen"); + sb.append(",listen"); else - { + { sb.append("listen"); found = true; - } + } if (actions.indexOf("accept") != -1) if (found) sb.append(",accept"); else - { + { sb.append("accept"); found = true; - } + } if (found) sb.append(",resolve"); @@ -231,25 +234,27 @@ public final class SocketPermission extends Permission /** * Returns true if the permission object passed it is implied by the - * this permission. This will be true if - *