aboutsummaryrefslogtreecommitdiff
path: root/libjava
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2002-09-25 09:05:53 +0000
committerMichael Koch <mkoch@gcc.gnu.org>2002-09-25 09:05:53 +0000
commitdf79dc1a89017f6b70525fcafc94c1ec476fead0 (patch)
treeeba53548213d388013da79db4a20b091267a80e9 /libjava
parent33c31b33b58b9a17c94ba1451f79723dabee1961 (diff)
downloadgcc-df79dc1a89017f6b70525fcafc94c1ec476fead0.zip
gcc-df79dc1a89017f6b70525fcafc94c1ec476fead0.tar.gz
gcc-df79dc1a89017f6b70525fcafc94c1ec476fead0.tar.bz2
2002-09-25 Michael Koch <konqueror@gmx.de>
* java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
Diffstat (limited to 'libjava')
-rw-r--r--libjava/ChangeLog66
-rw-r--r--libjava/Makefile.am1
-rw-r--r--libjava/Makefile.in2
-rw-r--r--libjava/java/net/DatagramSocket.java185
-rw-r--r--libjava/java/net/HttpURLConnection.java46
-rw-r--r--libjava/java/net/JarURLConnection.java25
-rw-r--r--libjava/java/net/ServerSocket.java60
-rw-r--r--libjava/java/net/Socket.java145
-rw-r--r--libjava/java/net/URLStreamHandler.java45
-rw-r--r--libjava/java/nio/channels/IllegalBlockingModeException.java56
10 files changed, 602 insertions, 29 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 62339d0..50e8dd8 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,5 +1,71 @@
2002-09-25 Michael Koch <konqueror@gmx.de>
+ * java/net/DatagramSocket.java
+ (DatagramSocket): Exception documentation added.
+ (bind): Exception documentation added, addded SecurityManager check,
+ added SocketAddress type check.
+ (getSoTimeout): Check impl.
+ (receive): Fix SecurityManager check, check impl, documentation added.
+ (send): Check channel mode, documentation added.
+ (connect): New method.
+ (disconnect): Implemented.
+ (getLocalSocketAddress): New method.
+ (getReceiveBufferSize): Check impl.
+ (setReuseAddress): Check impl.
+ (getReuseAddress): Check impl.
+ (setBroadcast): Check impl.
+ (getBroadcast): Check impl.
+ (setTrafficClass): Check impl, Documentation cleared.
+ (getTrafficClass): Check impl.
+ (getSendBufferSize): Check impl.
+ (setReceiveBufferSize): Check impl, documentation added.
+ (setSendBufferSize): Documentation added.
+ (setDatagramSocketImplFactory): New method.
+ * java/net/HttpURLConnection.java
+ (HTTP_INTERNAL_ERROR): The correct code is 500.
+ (HTTP_NOT_IMPLEMENTED): Added new constant.
+ (setFollowRedirects): Documentation added.
+ (getInstanceFollowRedirects): New method.
+ (setInstanceFollowRedirects): New method.
+ (setRequestMethod): Documentation added.
+ (getResponseCode): Documentation added.
+ (getResponseMessage): Documentation added.
+ * java/net/JarURLConnection.java
+ (JarURLConnection): protected since JDK 1.4.
+ (getJarEntry): java.io.IOException to IOException, documentation added.
+ (getJarFile): Documentation added.
+ * java/net/ServerSocket.java
+ (ServerSocket): Private to public, exception added.
+ (ServerSocket): java.io.IOException to IOException, documentation added.
+ (bind): Check socket address type, documentation added.
+ (bind): java.io.IOException to IOException, documentation added.
+ (accept): Documentation added.
+ (implAccept): Check ch is not non-blocking, documentation added.
+ (setSoTimeout): Documentation fixed.
+ (setReceiveBufferSize): Documentation added.
+ * java/net/Socket.java
+ (Socket): Documentation added.
+ (bind): Documentation added.
+ (connect): Check socket address type, documentation added.
+ (getRemoteSocketAddress): New method.
+ (getLocalSocketAddress): New method.
+ (setSoLinger): Documentation added.
+ (getReuseAddress): New method.
+ (setReuseAddress): New method.
+ (getTrafficClass): New method.
+ (setTrafficClass): New method.
+ * java/net/URLStreamHandler.java
+ (openConnection): java.io.IOException to IOException.
+ (parseURL): Documentation added.
+ (sameFile): public to protected, documentation added.
+ (setURL): Documentation added.
+ * java/nio/IllegalBlockingModeException.java: New file.
+ * Makefile.am (ordinary_java_source_files):
+ added java/nio/IllegalBlockingModeException.java
+ * Makefile.in: Regenerated.
+
+2002-09-25 Michael Koch <konqueror@gmx.de>
+
* java/net/DatagramPacket
(DatagramPacket): Exception documentation added.
(setData): Likewise.
diff --git a/libjava/Makefile.am b/libjava/Makefile.am
index fbffae4..4fd11df 100644
--- a/libjava/Makefile.am
+++ b/libjava/Makefile.am
@@ -1924,6 +1924,7 @@ java/net/URLStreamHandlerFactory.java \
java/net/UnknownHostException.java \
java/net/UnknownServiceException.java \
java/nio/channels/DatagramChannel.java \
+java/nio/channels/IllegalBlockingModeException.java \
java/nio/channels/ServerSocketChannel.java \
java/nio/channels/SocketChannel.java \
java/security/AccessControlContext.java \
diff --git a/libjava/Makefile.in b/libjava/Makefile.in
index 686b0f0..c0bde3f 100644
--- a/libjava/Makefile.in
+++ b/libjava/Makefile.in
@@ -1686,6 +1686,7 @@ java/net/URLStreamHandlerFactory.java \
java/net/UnknownHostException.java \
java/net/UnknownServiceException.java \
java/nio/channels/DatagramChannel.java \
+java/nio/channels/IllegalBlockingModeException.java \
java/nio/channels/ServerSocketChannel.java \
java/nio/channels/SocketChannel.java \
java/security/AccessControlContext.java \
@@ -2902,6 +2903,7 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \
.deps/java/net/natPlainDatagramSocketImpl.P \
.deps/java/net/natPlainSocketImpl.P \
.deps/java/nio/channels/DatagramChannel.P \
+.deps/java/nio/channels/IllegalBlockingModeException.P \
.deps/java/nio/channels/ServerSocketChannel.P \
.deps/java/nio/channels/SocketChannel.P \
.deps/java/rmi/AccessException.P .deps/java/rmi/AlreadyBoundException.P \
diff --git a/libjava/java/net/DatagramSocket.java b/libjava/java/net/DatagramSocket.java
index da97d61..eef638d 100644
--- a/libjava/java/net/DatagramSocket.java
+++ b/libjava/java/net/DatagramSocket.java
@@ -9,8 +9,10 @@ Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
package java.net;
+
import java.io.IOException;
import java.nio.channels.DatagramChannel;
+import java.nio.channels.IllegalBlockingModeException;
/**
* @author Warren Levy <warrenl@cygnus.com>
@@ -25,10 +27,23 @@ import java.nio.channels.DatagramChannel;
public class DatagramSocket
{
+ /**
+ * This is the user DatagramSocketImplFactory for this class. If this
+ * variable is null, a default factory is used.
+ */
+ static DatagramSocketImplFactory factory;
+
DatagramSocketImpl impl;
DatagramChannel ch;
+ /**
+ * Creates a DatagramSocket
+ *
+ * @exception SocketException If an error occurs
+ * @exception SecurityException If a security manager exists and
+ * its checkListen method doesn't allow the operation
+ */
public DatagramSocket() throws SocketException
{
this(0, null);
@@ -52,6 +67,8 @@ public class DatagramSocket
* @param bindaddr The socket address to bind to
*
* @exception SocketException If an error occurs
+ * @exception SecurityException If a security manager exists and
+ * its checkListen method doesn't allow the operation
*
* @since 1.4
*/
@@ -68,6 +85,8 @@ public class DatagramSocket
* @param port The port number to bind to
*
* @exception SocketException If an error occurs
+ * @exception SecurityException If a security manager exists and
+ * its checkListen method doesn't allow the operation
*/
public DatagramSocket(int port) throws SocketException
{
@@ -81,6 +100,8 @@ public class DatagramSocket
* @param laddr The local address to bind to
*
* @exception SocketException If an error occurs
+ * @exception SecurityException If a security manager exists and
+ * its checkListen method doesn't allow the operation
*/
public DatagramSocket(int port, InetAddress laddr) throws SocketException
{
@@ -121,13 +142,24 @@ public class DatagramSocket
* @param address The socket address to bind to
*
* @exception SocketException If an error occurs
+ * @exception SecurityException If a security manager exists and
+ * its checkListen method doesn't allow the operation
+ * @exception IllegalArgumentException If address type is not supported
*
* @since 1.4
*/
public void bind (SocketAddress address)
throws SocketException
{
+ if (! (address instanceof InetSocketAddress))
+ throw new IllegalArgumentException ();
+
InetSocketAddress tmp = (InetSocketAddress) address;
+
+ SecurityManager s = System.getSecurityManager ();
+ if (s != null)
+ s.checkListen(tmp.getPort ());
+
impl.bind (tmp.getPort (), tmp.getAddress ());
}
@@ -140,6 +172,16 @@ public class DatagramSocket
}
/**
+ * Checks if the datagram socket is closed
+ *
+ * @since 1.4
+ */
+ public boolean isClosed()
+ {
+ return !impl.getFileDescriptor().valid();
+ }
+
+ /**
* Gets a datagram channel assoziated with the socket
*
* @since 1.4
@@ -213,6 +255,9 @@ public class DatagramSocket
*/
public synchronized int getSoTimeout() throws SocketException
{
+ if (impl == null)
+ throw new SocketException ("Cannot initialize Socket implementation");
+
Object timeout = impl.getOption(SocketOptions.SO_TIMEOUT);
if (timeout instanceof Integer)
return ((Integer)timeout).intValue();
@@ -226,12 +271,25 @@ public class DatagramSocket
* @param p The datagram packet to put the incoming data into
*
* @exception IOException If an error occurs
+ * @exception SocketTimeoutException If setSoTimeout was previously called
+ * and the timeout has expired
+ * @exception PortUnreachableException If the socket is connected to a
+ * currently unreachable destination. Note, there is no guarantee that the
+ * exception will be thrown
+ * @exception IllegalBlockingModeException If this socket has an associated
+ * channel, and the channel is in non-blocking mode
*/
public synchronized void receive(DatagramPacket p) throws IOException
{
SecurityManager s = System.getSecurityManager();
if (s != null)
- s.checkAccept(p.getAddress().getHostAddress(), p.getPort());
+ s.checkAccept (p.getAddress().getHostName (), p.getPort ());
+
+ if (impl == null)
+ throw new IOException ("Cannot initialize Socket implementation");
+
+ if (ch != null && !ch.isBlocking ())
+ throw new IllegalBlockingModeException ();
impl.receive(p);
}
@@ -242,6 +300,13 @@ public class DatagramSocket
* @param p The datagram packet to send
*
* @exception IOException If an error occurs
+ * @exception SecurityException If a security manager exists and its
+ * checkMulticast or checkConnect method doesn't allow the send
+ * @exception PortUnreachableException If the socket is connected to a
+ * currently unreachable destination. Note, there is no guarantee that the
+ * exception will be thrown
+ * @exception IllegalBlockingModeException If this socket has an associated
+ * channel, and the channel is in non-blocking mode
*/
public void send(DatagramPacket p) throws IOException
{
@@ -249,15 +314,19 @@ public class DatagramSocket
SecurityManager s = System.getSecurityManager();
if (s != null)
{
- 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());
}
-
+
// FIXME: if this is a subclass of MulticastSocket,
// use getTimeToLive for TTL val.
+
+ if (ch != null && !ch.isBlocking ())
+ throw new IllegalBlockingModeException ();
+
impl.send(p);
}
@@ -285,6 +354,10 @@ public class DatagramSocket
* @param port The port to connect to
*
* @exception SocketException If an error occurs
+ * @exception IllegalArgumentException If address is null
+ * or the port number is illegal
+ * @exception SecurityException If the caller is not allowed to send
+ * datagrams to and receive datagrams from the address and port
*
* @since 1.2
*/
@@ -295,13 +368,33 @@ public class DatagramSocket
}
/**
+ * Connects the datagram socket to a specified socket address.
+ *
+ * @param address The socket address to connect to
+ *
+ * @exception SocketException If an error occurs
+ * @exception IllegalArgumentException If address type is not supported
+ *
+ * @since 1.4
+ */
+ public void connect (SocketAddress address) throws SocketException
+ {
+ if ( !(address instanceof InetSocketAddress) )
+ throw new IllegalArgumentException (
+ "SocketAddress is not InetSocketAddress");
+
+ InetSocketAddress tmp = (InetSocketAddress) address;
+ connect( tmp.getAddress(), tmp.getPort());
+ }
+
+ /**
* Disconnects the datagram socket
*
* @since 1.2
*/
public void disconnect()
{
- //impl.disconnect();
+ impl.disconnect();
}
/**
@@ -346,6 +439,28 @@ public class DatagramSocket
}
/**
+ * Returns the local SocketAddress this socket is bound to
+ * or null if it is not bound
+ *
+ * @since 1.4
+ */
+ public SocketAddress getLocalSocketAddress()
+ {
+ InetAddress addr;
+
+ try
+ {
+ addr = (InetAddress) impl.getOption (SocketOptions.SO_BINDADDR);
+ }
+ catch (SocketException e)
+ {
+ return null;
+ }
+
+ return new InetSocketAddress (addr, impl.localPort);
+ }
+
+ /**
* 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.
@@ -358,6 +473,9 @@ public class DatagramSocket
*/
public int getReceiveBufferSize() throws SocketException
{
+ if (impl == null)
+ throw new SocketException ("Cannot initialize Socket implementation");
+
Object obj = impl.getOption(SocketOptions.SO_RCVBUF);
if (obj instanceof Integer)
@@ -377,6 +495,9 @@ public class DatagramSocket
*/
public void setReuseAddress(boolean on) throws SocketException
{
+ if (impl == null)
+ throw new SocketException ("Cannot initialize Socket implementation");
+
impl.setOption (SocketOptions.SO_REUSEADDR, new Boolean (on));
}
@@ -389,6 +510,9 @@ public class DatagramSocket
*/
public boolean getReuseAddress() throws SocketException
{
+ if (impl == null)
+ throw new SocketException ("Cannot initialize Socket implementation");
+
Object obj = impl.getOption (SocketOptions.SO_REUSEADDR);
if (obj instanceof Boolean)
@@ -408,6 +532,9 @@ public class DatagramSocket
*/
public void setBroadcast(boolean on) throws SocketException
{
+ if (impl == null)
+ throw new SocketException ("Cannot initialize Socket implementation");
+
impl.setOption (SocketOptions.SO_BROADCAST, new Boolean (on));
}
@@ -420,6 +547,9 @@ public class DatagramSocket
*/
public boolean getBroadcast() throws SocketException
{
+ if (impl == null)
+ throw new SocketException ("Cannot initialize Socket implementation");
+
Object obj = impl.getOption (SocketOptions.SO_BROADCAST);
if (obj instanceof Boolean)
@@ -434,7 +564,7 @@ public class DatagramSocket
* @param tc The traffic class
*
* @exception SocketException If an error occurs
- * @exception IllegalArgumentException If tc < 0 or rc > 255
+ * @exception IllegalArgumentException If tc value is illegal
*
* @see DatagramSocket:getTrafficClass
*
@@ -443,6 +573,9 @@ public class DatagramSocket
public void setTrafficClass(int tc)
throws SocketException
{
+ if (impl == null)
+ throw new SocketException ("Cannot initialize Socket implementation");
+
if (tc < 0 || tc > 255)
throw new IllegalArgumentException();
@@ -460,6 +593,9 @@ public class DatagramSocket
*/
public int getTrafficClass() throws SocketException
{
+ if (impl == null)
+ throw new SocketException( "Cannot initialize Socket implementation");
+
Object obj = impl.getOption(SocketOptions.IP_TOS);
if (obj instanceof Integer)
@@ -481,6 +617,9 @@ public class DatagramSocket
*/
public int getSendBufferSize() throws SocketException
{
+ if (impl == null)
+ throw new SocketException ("Cannot initialize Socket implementation");
+
Object obj = impl.getOption(SocketOptions.SO_SNDBUF);
if (obj instanceof Integer)
@@ -497,11 +636,15 @@ public class DatagramSocket
* @param size The new receive buffer size.
*
* @exception SocketException If an error occurs.
+ * @exception IllegalArgumentException If size is 0 or negative
*
* @since 1.2
*/
public void setReceiveBufferSize(int size) throws SocketException
{
+ if (impl == null)
+ throw new SocketException ("Cannot initialize Socket implementation");
+
if (size < 0)
throw new IllegalArgumentException("Buffer size is less than 0");
@@ -516,6 +659,7 @@ public class DatagramSocket
* @param size The new send buffer size.
*
* @exception SocketException If an error occurs.
+ * @exception IllegalArgumentException If size is 0 or negative
*
* @since 1.2
*/
@@ -526,4 +670,27 @@ public class DatagramSocket
impl.setOption(SocketOptions.SO_SNDBUF, new Integer(size));
}
+
+ /**
+ * Sets the datagram socket implementation factory for the application
+ *
+ * @param fac The factory to set
+ *
+ * @exception IOException If an error occurs
+ * @exception SocketException If the factory is already defined
+ * @exception SecurityException If a security manager exists and its
+ * checkSetFactory method doesn't allow the operation
+ */
+ public static void setDatagramSocketImplFactory
+ (DatagramSocketImplFactory fac) throws IOException
+ {
+ if (factory != null)
+ throw new SocketException ("DatagramSocketImplFactory already defined");
+
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkSetFactory();
+
+ factory = fac;
+ }
}
diff --git a/libjava/java/net/HttpURLConnection.java b/libjava/java/net/HttpURLConnection.java
index c106ed2..5072b60 100644
--- a/libjava/java/net/HttpURLConnection.java
+++ b/libjava/java/net/HttpURLConnection.java
@@ -12,6 +12,7 @@ details. */
package java.net;
import java.io.*;
+import java.security.Permission;
/**
* @author Warren Levy <warrenl@cygnus.com>
@@ -64,7 +65,8 @@ public abstract class HttpURLConnection extends URLConnection
/* HTTP Server Error Response Codes */
public static final int HTTP_SERVER_ERROR = 500;
- public static final int HTTP_INTERNAL_ERROR = 501;
+ public static final int HTTP_INTERNAL_ERROR = 500;
+ public static final int HTTP_NOT_IMPLEMENTED = 501;
public static final int HTTP_BAD_GATEWAY = 502;
public static final int HTTP_UNAVAILABLE = 503;
public static final int HTTP_GATEWAY_TIMEOUT = 504;
@@ -88,6 +90,13 @@ public abstract class HttpURLConnection extends URLConnection
public abstract boolean usingProxy();
+ /**
+ * Sets whether HTTP redirects (requests with response code 3xx) should be
+ * automatically followed by this class. True by default
+ *
+ * @exception SecurityException If a security manager exists and its
+ * checkSetFactory method doesn't allow the operation
+ */
public static void setFollowRedirects(boolean set)
{
// Throw an exception if an extant security mgr precludes
@@ -104,6 +113,30 @@ public abstract class HttpURLConnection extends URLConnection
return followRedirects;
}
+ /**
+ * Returns the value of this HttpURLConnection's instanceFollowRedirects
+ * field
+ */
+ public boolean getInstanceFollowRedirects ()
+ {
+ return instanceFollowRedirects;
+ }
+
+ /**
+ * Sets the value of this HttpURLConnection's instanceFollowRedirects field
+ */
+ public void setInstanceFollowRedirects (boolean follow)
+ {
+ instanceFollowRedirects = follow;
+ }
+
+ /**
+ * Set the method for the URL request, one of:
+ * GET POST HEAD OPTIONS PUT DELETE TRACE are legal
+ *
+ * @exception ProtocolException If the method cannot be reset or if the
+ * requested method isn't valid for HTTP
+ */
public void setRequestMethod(String method) throws ProtocolException
{
if (connected)
@@ -123,6 +156,11 @@ public abstract class HttpURLConnection extends URLConnection
return method;
}
+ /**
+ * Gets the status code from an HTTP response message
+ *
+ * @exception IOException If an error occurs
+ */
public int getResponseCode() throws IOException
{
if (!gotResponseVals)
@@ -130,6 +168,12 @@ public abstract class HttpURLConnection extends URLConnection
return responseCode;
}
+ /**
+ * Gets the HTTP response message, if any, returned along with the
+ * response code from a server
+ *
+ * @exception IOException If an error occurs
+ */
public String getResponseMessage() throws IOException
{
if (!gotResponseVals)
diff --git a/libjava/java/net/JarURLConnection.java b/libjava/java/net/JarURLConnection.java
index c5597d6..8f75622 100644
--- a/libjava/java/net/JarURLConnection.java
+++ b/libjava/java/net/JarURLConnection.java
@@ -50,7 +50,14 @@ public abstract class JarURLConnection extends URLConnection
return element;
}
- public JarURLConnection(URL url)
+ /**
+ * Creates a new JarURLConnection
+ *
+ * @exception MalformedURLException If url is invalid
+ *
+ * @specnote This constructor is protected since JDK 1.4
+ */
+ protected JarURLConnection(URL url)
throws MalformedURLException
{
super(url);
@@ -153,7 +160,12 @@ public abstract class JarURLConnection extends URLConnection
return null;
}
- public JarEntry getJarEntry () throws java.io.IOException
+ /**
+ * Return the JAR entry object for this connection, if any
+ *
+ * @exception IOException If an error occurs
+ */
+ public JarEntry getJarEntry () throws IOException
{
JarFile jarfile = null;
@@ -167,7 +179,7 @@ public abstract class JarURLConnection extends URLConnection
{
jarfile = getJarFile ();
}
- catch (java.io.IOException x)
+ catch (IOException x)
{
/* ignore */
}
@@ -197,7 +209,12 @@ public abstract class JarURLConnection extends URLConnection
return null;
}
- public abstract JarFile getJarFile() throws java.io.IOException;
+ /**
+ * Return the JAR file for this connection
+ *
+ * @exception IOException If an error occurs
+ */
+ public abstract JarFile getJarFile() throws IOException;
// Steal and borrow from protocol/file/Connection.java
diff --git a/libjava/java/net/ServerSocket.java b/libjava/java/net/ServerSocket.java
index b706acc..36f93e8 100644
--- a/libjava/java/net/ServerSocket.java
+++ b/libjava/java/net/ServerSocket.java
@@ -38,6 +38,7 @@ exception statement from your version. */
package java.net;
import java.io.IOException;
+import java.nio.channels.IllegalBlockingModeException;
import java.nio.channels.ServerSocketChannel;
/* Written using on-line Java Platform 1.2 API Specification.
@@ -50,7 +51,7 @@ import java.nio.channels.ServerSocketChannel;
* listens for and accepts connections. At that point the client and
* server sockets are ready to communicate with one another utilizing
* whatever application layer protocol they desire.
- * <p>
+ *
* As with the <code>Socket</code> class, most instance methods of this class
* simply redirect their calls to an implementation class.
*
@@ -82,9 +83,13 @@ public class ServerSocket
private ServerSocketChannel ch;
/**
- * Private constructor that simply sets the implementation.
+ * Constructor that simply sets the implementation.
+ *
+ * @exception IOException If an error occurs
+ *
+ * @specnote This constructor is public since JDK 1.4
*/
- private ServerSocket()
+ public ServerSocket() throws IOException
{
if (factory != null)
impl = factory.createSocketImpl();
@@ -100,9 +105,11 @@ public class ServerSocket
* @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 java.io.IOException
+ throws IOException
{
this(port, 50);
}
@@ -117,9 +124,11 @@ public class ServerSocket
* @param backlog The length of the pending connection queue
*
* @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, int backlog)
- throws java.io.IOException
+ throws IOException
{
this(port, backlog, null);
}
@@ -136,11 +145,13 @@ public class ServerSocket
* @param bindAddr The address to bind to, or null to bind to all addresses
*
* @exception IOException If an error occurs
+ * @exception SecurityException If a security manager exists and its
+ * checkListen method doesn't allow the operation
*
* @since 1.1
*/
public ServerSocket (int port, int backlog, InetAddress bindAddr)
- throws java.io.IOException
+ throws IOException
{
this();
if (impl == null)
@@ -164,6 +175,9 @@ public class ServerSocket
* @param endpoint The socket address to bind to
*
* @exception IOException If an error occurs
+ * @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
*/
@@ -173,6 +187,9 @@ public class ServerSocket
if (impl == null)
throw new IOException ("Cannot initialize Socket implementation");
+ if (! (endpoint instanceof InetSocketAddress))
+ throw new IllegalArgumentException ("Address type not supported");
+
InetSocketAddress tmp = (InetSocketAddress) endpoint;
SecurityManager s = System.getSecurityManager ();
@@ -187,14 +204,22 @@ public class ServerSocket
*
* @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
+ * checkListen method doesn't allow the operation
+ *
+ * @since 1.4
*/
- public void bind (SocketAddress endpoint, int backlog)
- throws java.io.IOException
+ public void bind (SocketAddress endpoint, int backlog) throws IOException
{
if (impl == null)
throw new IOException ("Cannot initialize Socket implementation");
+ if (! (endpoint instanceof InetSocketAddress))
+ throw new IllegalArgumentException ("Address type not supported");
+
InetSocketAddress tmp = (InetSocketAddress) endpoint;
SecurityManager s = System.getSecurityManager ();
@@ -253,8 +278,14 @@ public class ServerSocket
* connection is available.
*
* @exception IOException If an error occurs
+ * @exception SecurityException If a security manager exists and its
+ * checkListen method doesn't allow the operation
+ * @exception IllegalBlockingModeException If this socket has an associated
+ * channel, and the channel is in non-blocking mode
+ * @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
{
Socket s = new Socket();
implAccept (s);
@@ -270,11 +301,17 @@ public class ServerSocket
* @param socket The socket that is used for the accepted connection
*
* @exception IOException If an error occurs
+ * @exception IllegalBlockingModeException If this socket has an associated
+ * channel, and the channel is in non-blocking mode
*
* @since 1.1
*/
- protected final void implAccept (Socket s) throws IOException
+ protected final void implAccept (Socket s)
+ throws IOException
{
+ if (ch != null && !ch.isBlocking())
+ throw new IllegalBlockingModeException();
+
impl.accept(s.impl);
}
@@ -329,7 +366,7 @@ public class ServerSocket
*
* @param timeout The new SO_TIMEOUT value
*
- * @exception IOException If an error occurs
+ * @exception SocketException If an error occurs
*
* @since 1.1
*/
@@ -408,6 +445,7 @@ public class ServerSocket
* @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
*/
diff --git a/libjava/java/net/Socket.java b/libjava/java/net/Socket.java
index 25f077b..9f01b78 100644
--- a/libjava/java/net/Socket.java
+++ b/libjava/java/net/Socket.java
@@ -129,6 +129,8 @@ public class Socket
* @exception UnknownHostException If the hostname cannot be resolved to a
* network address.
* @exception IOException If an error occurs
+ * @exception SecurityException If a security manager exists and its
+ * checkConnect method doesn't allow the operation
*/
public Socket (String host, int port)
throws UnknownHostException, IOException
@@ -144,6 +146,8 @@ public class Socket
* @param port The port number to connect to
*
* @exception IOException If an error occurs
+ * @exception SecurityException If a security manager exists and its
+ * checkConnect method doesn't allow the operation
*/
public Socket (InetAddress address, int port)
throws IOException
@@ -183,6 +187,8 @@ public class Socket
* @param localPort The local port to connect to
*
* @exception IOException If an error occurs
+ * @exception SecurityException If a security manager exists and its
+ * checkConnect method doesn't allow the operation
*/
public Socket (InetAddress address, int port,
InetAddress localAddr, int localPort) throws IOException
@@ -202,6 +208,8 @@ public class Socket
* for a datagram socket
*
* @exception IOException If an error occurs
+ * @exception SecurityException If a security manager exists and its
+ * checkConnect method doesn't allow the operation
*
* @deprecated Use the <code>DatagramSocket</code> class to create
* datagram oriented sockets.
@@ -223,6 +231,8 @@ public class Socket
* <code>false</code> to create a datagram socket.
*
* @exception IOException If an error occurs
+ * @exception SecurityException If a security manager exists and its
+ * checkConnect method doesn't allow the operation
*
* @deprecated Use the <code>DatagramSocket</code> class to create
* datagram oriented sockets.
@@ -246,6 +256,8 @@ public class Socket
* @param stream true for a stream socket, false for a datagram socket
*
* @exception IOException If an error occurs
+ * @exception SecurityException If a security manager exists and its
+ * checkConnect method doesn't allow the operation
*/
private Socket(InetAddress raddr, int rport, InetAddress laddr, int lport,
boolean stream) throws IOException
@@ -275,7 +287,10 @@ public class Socket
*
* @param bindpoint The address/port to bind to
*
- * @exception If an error occurs
+ * @exception IOException If an error occurs
+ * @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
*/
@@ -294,12 +309,17 @@ public class Socket
* @param endpoint The address to connect to
*
* @exception IOException If an error occurs
+ * @exception IllegalArgumentException If the addess type is not supported
+ * @exception IllegalBlockingModeException FIXME
*
* @since 1.4
*/
public void connect (SocketAddress endpoint)
throws IOException
{
+ if (! (endpoint instanceof InetSocketAddress))
+ throw new IllegalArgumentException ("Address type not supported");
+
impl.connect (endpoint, 0);
}
@@ -311,12 +331,18 @@ public class Socket
* @param endpoint The address to connect to
*
* @exception IOException If an error occurs
+ * @exception IllegalArgumentException If the address type is not supported
+ * @exception IllegalBlockingModeException FIXME
+ * @exception SocketTimeoutException If the timeout is reached
*
* @since 1.4
*/
public void connect (SocketAddress endpoint, int timeout)
throws IOException
{
+ if (! (endpoint instanceof InetSocketAddress))
+ throw new IllegalArgumentException ("Address type not supported");
+
impl.connect (endpoint, timeout);
}
@@ -399,6 +425,40 @@ public class Socket
}
/**
+ * If the socket is already bound this returns the local SocketAddress,
+ * otherwise null
+ *
+ * @since 1.4
+ */
+ public SocketAddress getLocalSocketAddress()
+ {
+ InetAddress addr;
+
+ try
+ {
+ addr = (InetAddress) impl.getOption (SocketOptions.SO_BINDADDR);
+ }
+ catch (SocketException e)
+ {
+ return null;
+ }
+
+ return new InetSocketAddress (addr, impl.getLocalPort());
+ }
+
+ /**
+ * If the socket is already connected this returns the remote SocketAddress,
+ * otherwise null
+ *
+ * @since 1.4
+ */
+ public SocketAddress getRemoteSocketAddress()
+ {
+ // FIXME: Implement this
+ return null;
+ }
+
+ /**
* Returns an InputStream for reading from this socket.
*
* @return The InputStream object
@@ -479,6 +539,7 @@ public class Socket
* SO_LINGER not set.
*
* @exception SocketException If an error occurs or Socket not connected
+ * @exception IllegalArgumentException If linger is negative
*/
public void setSoLinger(boolean on, int linger) throws SocketException
{
@@ -640,6 +701,7 @@ public class Socket
* @param size The new send buffer size.
*
* @exception SocketException If an error occurs or Socket not connected
+ * @exception IllegalArgumentException FIXME
*
* @since 1.2
*/
@@ -686,6 +748,7 @@ public class Socket
* @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.2
*/
@@ -847,4 +910,84 @@ public class Socket
{
return ch;
}
+
+ /**
+ * Checks if the SO_REUSEADDR option is enabled
+ *
+ * @exception SocketException If an error occurs
+ *
+ * @since 1.4
+ */
+ public boolean getReuseAddress () throws SocketException
+ {
+ if (impl == null)
+ throw new SocketException ("Cannot initialize Socket implementation");
+
+ Object reuseaddr = impl.getOption (SocketOptions.SO_REUSEADDR);
+
+ if (!(reuseaddr instanceof Boolean))
+ throw new SocketException ("Internal Error");
+
+ return ((Boolean) reuseaddr).booleanValue ();
+ }
+
+ /**
+ * Enables/Disables the SO_REUSEADDR option
+ *
+ * @exception SocketException If an error occurs
+ *
+ * @since 1.4
+ */
+ public void setReuseAddress (boolean on) throws SocketException
+ {
+ if (impl == null)
+ throw new SocketException ("Cannot initialize Socket implementation");
+
+ impl.setOption (SocketOptions.SO_REUSEADDR, new Boolean (on));
+ }
+
+ /**
+ * Returns the current traffic class
+ *
+ * @exception SocketException If an error occurs
+ *
+ * @see Socket:setTrafficClass
+ *
+ * @since 1.4
+ */
+ public int getTrafficClass () throws SocketException
+ {
+ if (impl == null)
+ throw new SocketException ("Cannot initialize Socket implementation");
+
+ Object obj = impl.getOption(SocketOptions.IP_TOS);
+
+ if (obj instanceof Integer)
+ return ((Integer) obj).intValue ();
+ else
+ throw new SocketException ("Unexpected type");
+ }
+
+ /**
+ * Sets the traffic class value
+ *
+ * @param tc The traffic class
+ *
+ * @exception SocketException If an error occurs
+ * @exception IllegalArgumentException If tc value is illegal
+ *
+ * @see Socket:getTrafficClass
+ *
+ * @since 1.4
+ */
+ public void setTrafficClass (int tc) throws SocketException
+ {
+ if (impl == null)
+ throw new SocketException ("Cannot initialize Socket implementation");
+
+ if (tc < 0 || tc > 255)
+ throw new IllegalArgumentException();
+
+ impl.setOption (SocketOptions.IP_TOS, new Integer (tc));
+ }
}
diff --git a/libjava/java/net/URLStreamHandler.java b/libjava/java/net/URLStreamHandler.java
index bb3d8e8..ea21ee9 100644
--- a/libjava/java/net/URLStreamHandler.java
+++ b/libjava/java/net/URLStreamHandler.java
@@ -10,6 +10,8 @@ details. */
package java.net;
+import java.io.IOException;
+
/**
* @author Warren Levy <warrenl@cygnus.com>
* @date March 4, 1999.
@@ -24,8 +26,16 @@ package java.net;
public abstract class URLStreamHandler
{
protected abstract URLConnection openConnection(URL u)
- throws java.io.IOException;
-
+ throws IOException;
+
+ /**
+ * Pasrses the given URL
+ *
+ * @param u The URL to parse
+ * @param spec The specification to use
+ * @param start FIXME
+ * @param limit FIXME
+ */
protected void parseURL(URL u, String spec, int start, int limit)
{
String host = u.getHost();
@@ -119,7 +129,15 @@ public abstract class URLStreamHandler
return file;
}
- public boolean sameFile(URL url1, URL url2)
+ /**
+ * Compares two URLs, excluding the fragment component
+ *
+ * @param url1 The first url
+ * @param url2 The second url to compare with the first
+ *
+ * @specnote Now protected
+ */
+ protected boolean sameFile(URL url1, URL url2)
{
if (url1 == url2)
return true;
@@ -143,12 +161,33 @@ public abstract class URLStreamHandler
return true;
}
+ /**
+ * Sets the fields of the URL argument to the indicated values
+ *
+ * @param u The URL to modify
+ * @param protocol The protocol to set
+ * @param host The host name to et
+ * @param port The port number to set
+ * @param file The filename to set
+ * @param ref The reference
+ *
+ * @exception SecurityException If the protocol handler of the URL is
+ * different from this one
+ *
+ * @deprecated 1.2 Please use
+ * #setURL(URL,String,String,int,String,String,String,String);
+ */
protected void setURL(URL u, String protocol, String host, int port,
String file, String ref)
{
u.set(protocol, host, port, file, ref);
}
+ /**
+ * Converts an URL of a specific protocol to a string
+ *
+ * @param u The URL to convert
+ */
protected String toExternalForm(URL u)
{
String resStr, host, file, ref;
diff --git a/libjava/java/nio/channels/IllegalBlockingModeException.java b/libjava/java/nio/channels/IllegalBlockingModeException.java
new file mode 100644
index 0000000..dca8110
--- /dev/null
+++ b/libjava/java/nio/channels/IllegalBlockingModeException.java
@@ -0,0 +1,56 @@
+/* IllegalBlockingModeException.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+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
+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.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+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.nio.channels;
+
+/**
+ * @author Michael Koch <konqueror@gmx.de>
+ * @since 1.4
+ *
+ * Written using JDK 1.4.1 Online API from Sun
+ * Status: JDK 1.4 complete
+ */
+public class IllegalBlockingModeException extends IllegalStateException
+{
+ /**
+ * Creates the exception
+ */
+ public IllegalBlockingModeException()
+ {
+ super();
+ }
+}