This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
java.net more and more
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Wed, 25 Sep 2002 11:06:55 +0200
- Subject: java.net more and more
Hello list,
I have commited the following patch and one new file.
Michael
--
Homepage: http://www.worldforge.org/
GPG-key: http://konqueror.dyndns.org/~mkoch/michael.gpg
/* 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();
}
}
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.1449
diff -u -b -r1.1449 ChangeLog
--- ChangeLog 25 Sep 2002 05:05:05 -0000 1.1449
+++ ChangeLog 25 Sep 2002 09:02:17 -0000
@@ -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.
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.244
diff -u -b -r1.244 Makefile.am
--- Makefile.am 23 Sep 2002 03:52:52 -0000 1.244
+++ Makefile.am 25 Sep 2002 09:02:19 -0000
@@ -1924,6 +1924,7 @@
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 \
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.in,v
retrieving revision 1.264
diff -u -b -r1.264 Makefile.in
--- Makefile.in 23 Sep 2002 03:52:52 -0000 1.264
+++ Makefile.in 25 Sep 2002 09:02:22 -0000
@@ -1686,6 +1686,7 @@
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 @@
.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 \
Index: java/net/DatagramSocket.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/DatagramSocket.java,v
retrieving revision 1.13
diff -u -b -r1.13 DatagramSocket.java
--- java/net/DatagramSocket.java 21 Sep 2002 06:59:20 -0000 1.13
+++ java/net/DatagramSocket.java 25 Sep 2002 09:02:23 -0000
@@ -9,8 +9,10 @@
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 @@
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 @@
* @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 @@
* @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 @@
* @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 @@
* @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 @@
}
/**
+ * 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 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 @@
* @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 @@
* @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
{
@@ -258,6 +323,10 @@
// 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 @@
* @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 @@
}
/**
+ * 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 @@
}
/**
+ * 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 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 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 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 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 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 @@
* @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 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 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 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 @@
* @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 @@
* @param size The new send buffer size.
*
* @exception SocketException If an error occurs.
+ * @exception IllegalArgumentException If size is 0 or negative
*
* @since 1.2
*/
@@ -525,5 +669,28 @@
throw new IllegalArgumentException("Buffer size is less than 0");
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;
}
}
Index: java/net/HttpURLConnection.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/HttpURLConnection.java,v
retrieving revision 1.5
diff -u -b -r1.5 HttpURLConnection.java
--- java/net/HttpURLConnection.java 27 Aug 2002 17:47:26 -0000 1.5
+++ java/net/HttpURLConnection.java 25 Sep 2002 09:02:23 -0000
@@ -12,6 +12,7 @@
package java.net;
import java.io.*;
+import java.security.Permission;
/**
* @author Warren Levy <warrenl@cygnus.com>
@@ -64,7 +65,8 @@
/* 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 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 @@
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 @@
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 @@
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)
Index: java/net/JarURLConnection.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/JarURLConnection.java,v
retrieving revision 1.8
diff -u -b -r1.8 JarURLConnection.java
--- java/net/JarURLConnection.java 13 Sep 2002 11:39:47 -0000 1.8
+++ java/net/JarURLConnection.java 25 Sep 2002 09:02:23 -0000
@@ -50,7 +50,14 @@
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 @@
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 @@
{
jarfile = getJarFile ();
}
- catch (java.io.IOException x)
+ catch (IOException x)
{
/* ignore */
}
@@ -197,7 +209,12 @@
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
Index: java/net/ServerSocket.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/ServerSocket.java,v
retrieving revision 1.14
diff -u -b -r1.14 ServerSocket.java
--- java/net/ServerSocket.java 21 Sep 2002 06:59:20 -0000 1.14
+++ java/net/ServerSocket.java 25 Sep 2002 09:02:23 -0000
@@ -38,6 +38,7 @@
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 @@
* 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 @@
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 @@
* @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 @@
* @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 @@
* @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 @@
* @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 @@
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 @@
*
* @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,6 +278,12 @@
* 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
{
@@ -270,11 +301,17 @@
* @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 @@
*
* @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 @@
* @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
*/
Index: java/net/Socket.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/Socket.java,v
retrieving revision 1.13
diff -u -b -r1.13 Socket.java
--- java/net/Socket.java 21 Sep 2002 06:59:20 -0000 1.13
+++ java/net/Socket.java 25 Sep 2002 09:02:24 -0000
@@ -129,6 +129,8 @@
* @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 @@
* @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 @@
* @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 @@
* 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 @@
* <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 @@
* @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 @@
*
* @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 @@
* @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 @@
* @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 @@
}
/**
+ * 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 @@
* 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 @@
* @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 @@
* @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
*/
@@ -846,5 +909,85 @@
public SocketChannel getChannel()
{
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));
}
}
Index: java/net/URLStreamHandler.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URLStreamHandler.java,v
retrieving revision 1.7
diff -u -b -r1.7 URLStreamHandler.java
--- java/net/URLStreamHandler.java 23 Feb 2002 00:15:48 -0000 1.7
+++ java/net/URLStreamHandler.java 25 Sep 2002 09:02:24 -0000
@@ -10,6 +10,8 @@
package java.net;
+import java.io.IOException;
+
/**
* @author Warren Levy <warrenl@cygnus.com>
* @date March 4, 1999.
@@ -24,8 +26,16 @@
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 @@
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 @@
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;