mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-03-19 10:10:39 +08:00
Authenticator.java, [...]: Fixed javadocs, coding style and argument names all over.
2004-04-20 Michael Koch <konqueror@gmx.de> * java/net/Authenticator.java, java/net/BindException.java, java/net/ConnectException.java, java/net/ContentHandler.java, java/net/ContentHandlerFactory.java, java/net/DatagramPacket.java, java/net/DatagramSocket.java, java/net/DatagramSocketImpl.java, java/net/DatagramSocketImplFactory.java, java/net/FileNameMap.java, java/net/HttpURLConnection.java, java/net/Inet4Address.java, java/net/Inet6Address.java, java/net/InetAddress.java, java/net/InetSocketAddress.java, java/net/JarURLConnection.java, java/net/MalformedURLException.java, java/net/MulticastSocket.java, java/net/NetPermission.java, java/net/NetworkInterface.java, java/net/NoRouteToHostException.java, java/net/PasswordAuthentication.java, java/net/PortUnreachableException.java, java/net/ProtocolException.java, java/net/ServerSocket.java, java/net/Socket.java, java/net/SocketAddress.java, java/net/SocketException.java, java/net/SocketImpl.java, java/net/SocketImplFactory.java, java/net/SocketOptions.java, java/net/SocketPermission.java, java/net/SocketTimeoutException.java, java/net/URI.java, java/net/URISyntaxException.java, java/net/URL.java, java/net/URLClassLoader.java, java/net/URLConnection.java, java/net/URLDecoder.java, java/net/URLEncoder.java, java/net/URLStreamHandler.java, java/net/URLStreamHandlerFactory.java, java/net/UnknownHostException.java, java/net/UnknownServiceException.java: Fixed javadocs, coding style and argument names all over. From-SVN: r80900
This commit is contained in:
parent
cf6f7d5589
commit
f6d49f66ec
@ -1,3 +1,51 @@
|
||||
2004-04-20 Michael Koch <konqueror@gmx.de>
|
||||
|
||||
* java/net/Authenticator.java,
|
||||
java/net/BindException.java,
|
||||
java/net/ConnectException.java,
|
||||
java/net/ContentHandler.java,
|
||||
java/net/ContentHandlerFactory.java,
|
||||
java/net/DatagramPacket.java,
|
||||
java/net/DatagramSocket.java,
|
||||
java/net/DatagramSocketImpl.java,
|
||||
java/net/DatagramSocketImplFactory.java,
|
||||
java/net/FileNameMap.java,
|
||||
java/net/HttpURLConnection.java,
|
||||
java/net/Inet4Address.java,
|
||||
java/net/Inet6Address.java,
|
||||
java/net/InetAddress.java,
|
||||
java/net/InetSocketAddress.java,
|
||||
java/net/JarURLConnection.java,
|
||||
java/net/MalformedURLException.java,
|
||||
java/net/MulticastSocket.java,
|
||||
java/net/NetPermission.java,
|
||||
java/net/NetworkInterface.java,
|
||||
java/net/NoRouteToHostException.java,
|
||||
java/net/PasswordAuthentication.java,
|
||||
java/net/PortUnreachableException.java,
|
||||
java/net/ProtocolException.java,
|
||||
java/net/ServerSocket.java,
|
||||
java/net/Socket.java,
|
||||
java/net/SocketAddress.java,
|
||||
java/net/SocketException.java,
|
||||
java/net/SocketImpl.java,
|
||||
java/net/SocketImplFactory.java,
|
||||
java/net/SocketOptions.java,
|
||||
java/net/SocketPermission.java,
|
||||
java/net/SocketTimeoutException.java,
|
||||
java/net/URI.java,
|
||||
java/net/URISyntaxException.java,
|
||||
java/net/URL.java,
|
||||
java/net/URLClassLoader.java,
|
||||
java/net/URLConnection.java,
|
||||
java/net/URLDecoder.java,
|
||||
java/net/URLEncoder.java,
|
||||
java/net/URLStreamHandler.java,
|
||||
java/net/URLStreamHandlerFactory.java,
|
||||
java/net/UnknownHostException.java,
|
||||
java/net/UnknownServiceException.java:
|
||||
Fixed javadocs, coding style and argument names all over.
|
||||
|
||||
2004-04-20 Michael Koch <konqueror@gmx.de>
|
||||
|
||||
* java/lang/Byte.java,
|
||||
|
@ -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).
|
||||
* <p>
|
||||
* 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
|
||||
* <code>setDefault</code> 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
|
||||
* <code>setDefault</code> 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 <code>Authenticator</code> object (an
|
||||
* instance of a subclass of <code>Authenticator</code>) to use when
|
||||
* This method sets the default <code>Authenticator</code> object (an
|
||||
* instance of a subclass of <code>Authenticator</code>) 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 <code>Authenticator</code> 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 <code>Authenticator</code> object, the method then returns
|
||||
* <code>null</code>. Otherwise, the default authenticators's instance
|
||||
* default <code>Authenticator</code> object, the method then returns
|
||||
* <code>null</code>. Otherwise, the default authenticators's instance
|
||||
* variables are initialized and it's <code>getPasswordAuthentication</code>
|
||||
* 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 <code>PasswordAuthentication</code> object with the user's
|
||||
*
|
||||
* @return A <code>PasswordAuthentication</code> 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 <code>PasswordAuthentication</code> object with the user's
|
||||
* @return A <code>PasswordAuthentication</code> 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 <code>null</code> if not available.
|
||||
*
|
||||
* @return The name of the host requesting authentication, or
|
||||
* </code>null</code> if it is not available.
|
||||
* <code>null</code> if it is not available.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
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
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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 <code>getContent()</code> method in the
|
||||
* <code>URL</code> class or the <code>URLConnection</code> class will cause
|
||||
* an instance of a subclass of <code>ContentHandler</code> 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 <code>getContent()</code> method in the
|
||||
* <code>URL</code> class or the <code>URLConnection</code> class will cause
|
||||
* an instance of a subclass of <code>ContentHandler</code> 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 <code>InputStream</code> of the passed in URL
|
||||
* connection and uses the data downloaded to create an <code>Object</code>
|
||||
* represening the content. For example, if the URL is pointing to a GIF
|
||||
* file, this method might return an <code>Image</code> object. This method
|
||||
* This method reads from the <code>InputStream</code> of the passed in URL
|
||||
* connection and uses the data downloaded to create an <code>Object</code>
|
||||
* represening the content. For example, if the URL is pointing to a GIF
|
||||
* file, this method might return an <code>Image</code> object. This method
|
||||
* must be implemented by subclasses.
|
||||
*
|
||||
* @param urlc A <code>URLConnection</code> 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 <code>InputStream</code> of the passed in URL
|
||||
* connection and uses the data downloaded to create an <code>Object</code>
|
||||
* represening the content. For example, if the URL is pointing to a GIF
|
||||
* file, this method might return an <code>Image</code> object. This method
|
||||
* represening the content. For example, if the URL is pointing to a GIF
|
||||
* file, this method might return an <code>Image</code> 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, <code>null</code> is returned.
|
||||
*
|
||||
* @param urlc A <code>URLConnection</code> 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
|
||||
|
@ -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 <code>ContentHandler</code> objects.
|
||||
* It consists of one method that, when passed a MIME type, returns a
|
||||
* This interface maps MIME types to <code>ContentHandler</code> 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 <code>ContentHandler</code> for the passed in MIME type
|
||||
*/
|
||||
ContentHandler createContentHandler(String mimeType);
|
||||
|
||||
} // interface ContentHandlerFactory
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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 <code>DatagramSocket</code> from a specified
|
||||
* Creates a <code>DatagramSocket</code> from a specified
|
||||
* <code>DatagramSocketImpl</code> instance
|
||||
*
|
||||
* @param impl The <code>DatagramSocketImpl</code> the socket will be
|
||||
* @param impl The <code>DatagramSocketImpl</code> 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 <code>DatagramSocket</code> that binds to
|
||||
* Initializes a new instance of <code>DatagramSocket</code> 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 <code>DatagramSocket</code> that binds to
|
||||
* Initializes a new instance of <code>DatagramSocket</code> 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 <code>DatagramSocket</code> that binds to
|
||||
* Initializes a new instance of <code>DatagramSocket</code> 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 <code>DatagramSocket</code> that binds to
|
||||
* Initializes a new instance of <code>DatagramSocket</code> 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 <code>null</code>.
|
||||
*
|
||||
*
|
||||
* @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 <code>DatagramChannel</code> 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)
|
||||
|
@ -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 <code>InetAddress</code> to fill in with the information
|
||||
* @param i The <code>InetAddress</code> 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 <code>DatagramPacket</code> 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. <b>Use <code>getTimeToLive()</code></b> 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()
|
||||
{
|
||||
|
@ -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
|
||||
* <code>DatagramSocketImpl</code> object.
|
||||
* This should not be needed by ordinary applications.
|
||||
*
|
||||
@ -57,5 +57,4 @@ public interface DatagramSocketImplFactory
|
||||
* @return A DatagramSocketImpl object
|
||||
*/
|
||||
DatagramSocketImpl createDatagramSocketImpl();
|
||||
|
||||
} // interface DatagramSocketImplFactory
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 <code>getResponseCode()</code> and
|
||||
* <code>getResponseMessage()</code>.
|
||||
*/
|
||||
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 <code>InputStream</code> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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 <code>InetSocketAddress</code> 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 <code>InetSocketAddress</code>
|
||||
*
|
||||
@ -210,7 +208,7 @@ public class InetSocketAddress extends SocketAddress
|
||||
{
|
||||
return addr == null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the <code>InetSocketAddress</code> as string
|
||||
*
|
||||
|
@ -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:
|
||||
* <p>
|
||||
* jar:<standard URL pointing to jar file>!/file/within/jarfile
|
||||
* jar:<standard URL pointing to jar filei>!/file/within/jarfile
|
||||
* <p> for example:
|
||||
* <p>
|
||||
* 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();
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
* <p>
|
||||
* 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 <code>getTimeToLive</code> 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
|
||||
}
|
||||
|
@ -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 <code>BasicPermission</code>. 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 <code>BasicPermission</code>. 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:
|
||||
*
|
||||
*
|
||||
* <ul>
|
||||
* <li>setDefaultAuthenticator - Grants the ability to install a facility
|
||||
* to collect username and password information when requested by a
|
||||
* web site or proxy server.
|
||||
* to collect username and password information when requested by a
|
||||
* web site or proxy server.</li>
|
||||
* <li>requestPasswordAuthentication - Grants the ability to ask the
|
||||
* authentication facility for the user's password.
|
||||
* <li>specifyStreamHandler - Grants the permission to specify the
|
||||
* stream handler class used when loading from a URL.
|
||||
* authentication facility for the user's password.</li>
|
||||
* <li>specifyStreamHandler - Grants the permission to specify the
|
||||
* stream handler class used when loading from a URL.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
@ -75,8 +76,8 @@ public final class NetPermission extends BasicPermission
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>NetPermission</code> with the
|
||||
* specified name and perms. Note that the perms field is irrelevant and is
|
||||
* Initializes a new instance of <code>NetPermission</code> 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
|
||||
|
@ -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 <code>InetAddresses</code> are returned where the security manager
|
||||
* Only <code>InetAddresses</code> 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;
|
||||
|
@ -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.
|
||||
|
@ -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 <code>PasswordAuthentication</code> object from the
|
||||
* Creates a new <code>PasswordAuthentication</code> 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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 <code>Socket</code> class, most instance methods of this class
|
||||
* As with the <code>Socket</code> 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 <code>Socket</code>
|
||||
* instance representing that connection. This method will block until a
|
||||
* Accepts a new connection and returns a connected <code>Socket</code>
|
||||
* 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
|
||||
* <code>ServerSocket.accept()</code>. 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 <code>String</code>.
|
||||
* Returns the value of this socket as a <code>String</code>.
|
||||
*
|
||||
* @return This socket represented as a <code>String</code>.
|
||||
*/
|
||||
public String toString ()
|
||||
public String toString()
|
||||
{
|
||||
if (!isBound())
|
||||
if (! isBound())
|
||||
return "ServerSocket[unbound]";
|
||||
|
||||
return ("ServerSocket[addr=" + getInetAddress()
|
||||
@ -578,19 +587,21 @@ public class ServerSocket
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the <code>SocketImplFactory</code> for all
|
||||
* Sets the <code>SocketImplFactory</code> for all
|
||||
* <code>ServerSocket</code>'s. This may only be done
|
||||
* once per virtual machine. Subsequent attempts will generate an
|
||||
* exception. Note that a <code>SecurityManager</code> 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
|
||||
* <code>SecurityManager</code>.
|
||||
* @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;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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]
|
||||
|
@ -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
|
||||
|
@ -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 <code>String</code> 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");
|
||||
}
|
||||
}
|
||||
|
@ -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 <code>SocketImpl</code>
|
||||
* object. This should not be needed by ordinary applications.
|
||||
@ -57,6 +56,4 @@ public interface SocketImplFactory
|
||||
* @return A <code>SocketImpl</code> object
|
||||
*/
|
||||
SocketImpl createSocketImpl();
|
||||
|
||||
} // interface SocketImplFactory
|
||||
|
||||
|
@ -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 <code>SocketImpl</code> and
|
||||
* This interface is used by <code>SocketImpl</code> and
|
||||
* <code>DatagramSocketImpl</code> 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
|
||||
|
||||
|
@ -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:
|
||||
* <p><ul>
|
||||
* <li>8080 - Represents port 8080 only
|
||||
* <li>2000-3000 - Represents ports 2000 through 3000 inclusive
|
||||
* <li>-4000 - Represents ports 0 through 4000 inclusive
|
||||
* <li>1024- - Represents ports 1024 through 65535 inclusive
|
||||
* <li>8080 - Represents port 8080 only</li>
|
||||
* <li>2000-3000 - Represents ports 2000 through 3000 inclusive</li>
|
||||
* <li>-4000 - Represents ports 0 through 4000 inclusive</li>
|
||||
* <li>1024- - Represents ports 1024 through 65535 inclusive</li>
|
||||
* </ul><p>
|
||||
* The permission list is a comma separated list of individual permissions.
|
||||
* These individual permissions are:
|
||||
* <p>
|
||||
* accept<br>
|
||||
* connect<br>
|
||||
* listen<br>
|
||||
* resolve<br>
|
||||
* <pre>
|
||||
* accept
|
||||
* connect
|
||||
* listen
|
||||
* resolve
|
||||
* </pre>
|
||||
* <p>
|
||||
* 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 <code>SocketPermission</code> with the
|
||||
* Initializes a new instance of <code>SocketPermission</code> 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
|
||||
* <code>SocketPermission</code> and both its hostname/port combination
|
||||
* and only if the passed object is an instance of
|
||||
* <code>SocketPermission</code> and both its hostname/port combination
|
||||
* and permissions string are identical.
|
||||
*
|
||||
* @param obj The object to test against for equality
|
||||
*
|
||||
* @return <code>true</code> if object is equal to this object,
|
||||
* @return <code>true</code> if object is equal to this object,
|
||||
* <code>false</code> 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
|
||||
* <code>Permission.hashCode()</code>.
|
||||
*
|
||||
* @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
|
||||
* <p><ul>
|
||||
* <li>The argument is of type <code>SocketPermission</code>
|
||||
* <li>The actions list of the argument are in this object's actions
|
||||
* <li>The port range of the argument is within this objects port range
|
||||
* <li>The hostname is equal to or a subset of this objects hostname
|
||||
* this permission. This will be true if:
|
||||
*
|
||||
* <ul>
|
||||
* <li>The argument is of type <code>SocketPermission</code></li>
|
||||
* <li>The actions list of the argument are in this object's actions</li>
|
||||
* <li>The port range of the argument is within this objects port range</li>
|
||||
* <li>The hostname is equal to or a subset of this objects hostname</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* The argument's hostname will be a subset of this object's hostname if:
|
||||
* <p><ul>
|
||||
* <li>The argument's hostname or IP address is equal to this object's.
|
||||
* <li>The argument's canonical hostname is equal to this object's.
|
||||
*
|
||||
* <p>The argument's hostname will be a subset of this object's hostname if:</p>
|
||||
*
|
||||
* <ul>
|
||||
* <li>The argument's hostname or IP address is equal to this object's.</li>
|
||||
* <li>The argument's canonical hostname is equal to this object's.</li>
|
||||
* <li>The argument's canonical name matches this domains hostname with
|
||||
* wildcards
|
||||
* wildcards</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param perm The <code>Permission</code> to check against
|
||||
*
|
||||
* @return <code>true</code> if the <code>Permission</code> is implied by
|
||||
* @return <code>true</code> if the <code>Permission</code> is implied by
|
||||
* this object, <code>false</code> otherwise.
|
||||
*/
|
||||
public boolean implies(Permission perm)
|
||||
@ -266,72 +271,78 @@ public final class SocketPermission extends Permission
|
||||
String ourlist = getActions();
|
||||
String theirlist = p.getActions();
|
||||
|
||||
if (!ourlist.startsWith(theirlist))
|
||||
if (! ourlist.startsWith(theirlist))
|
||||
return (false);
|
||||
|
||||
// Now check ports
|
||||
int ourfirstport = 0, ourlastport = 0, theirfirstport = 0, theirlastport =
|
||||
0;
|
||||
int ourfirstport = 0;
|
||||
|
||||
// Now check ports
|
||||
int ourlastport = 0;
|
||||
|
||||
// Now check ports
|
||||
int theirfirstport = 0;
|
||||
|
||||
// Now check ports
|
||||
int theirlastport = 0;
|
||||
|
||||
// Get ours
|
||||
if (hostport.indexOf(":") == -1)
|
||||
{
|
||||
ourfirstport = 0;
|
||||
ourlastport = 65535;
|
||||
ourfirstport = 0;
|
||||
ourlastport = 65535;
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME: Needs bulletproofing.
|
||||
// This will dump if hostport if all sorts of bad data was passed to
|
||||
// the constructor
|
||||
String range = hostport.substring(hostport.indexOf(":") + 1);
|
||||
if (range.startsWith("-"))
|
||||
ourfirstport = 0;
|
||||
else if (range.indexOf("-") == -1)
|
||||
ourfirstport = Integer.parseInt(range);
|
||||
else
|
||||
ourfirstport =
|
||||
Integer.parseInt(range.substring(0, range.indexOf("-")));
|
||||
// FIXME: Needs bulletproofing.
|
||||
// This will dump if hostport if all sorts of bad data was passed to
|
||||
// the constructor
|
||||
String range = hostport.substring(hostport.indexOf(":") + 1);
|
||||
if (range.startsWith("-"))
|
||||
ourfirstport = 0;
|
||||
else if (range.indexOf("-") == -1)
|
||||
ourfirstport = Integer.parseInt(range);
|
||||
else
|
||||
ourfirstport =
|
||||
Integer.parseInt(range.substring(0, range.indexOf("-")));
|
||||
|
||||
if (range.endsWith("-"))
|
||||
ourlastport = 65535;
|
||||
else if (range.indexOf("-") == -1)
|
||||
ourlastport = Integer.parseInt(range);
|
||||
else
|
||||
ourlastport =
|
||||
Integer.parseInt(range.
|
||||
substring(range.indexOf("-") + 1,
|
||||
range.length()));
|
||||
if (range.endsWith("-"))
|
||||
ourlastport = 65535;
|
||||
else if (range.indexOf("-") == -1)
|
||||
ourlastport = Integer.parseInt(range);
|
||||
else
|
||||
ourlastport =
|
||||
Integer.parseInt(range.substring(range.indexOf("-") + 1,
|
||||
range.length()));
|
||||
}
|
||||
|
||||
// Get theirs
|
||||
if (p.hostport.indexOf(":") == -1)
|
||||
{
|
||||
theirfirstport = 0;
|
||||
ourlastport = 65535;
|
||||
theirfirstport = 0;
|
||||
ourlastport = 65535;
|
||||
}
|
||||
else
|
||||
{
|
||||
// This will dump if hostport if all sorts of bad data was passed to
|
||||
// the constructor
|
||||
String range = p.hostport.substring(hostport.indexOf(":") + 1);
|
||||
if (range.startsWith("-"))
|
||||
theirfirstport = 0;
|
||||
else if (range.indexOf("-") == -1)
|
||||
theirfirstport = Integer.parseInt(range);
|
||||
else
|
||||
theirfirstport =
|
||||
Integer.parseInt(range.substring(0, range.indexOf("-")));
|
||||
// This will dump if hostport if all sorts of bad data was passed to
|
||||
// the constructor
|
||||
String range = p.hostport.substring(hostport.indexOf(":") + 1);
|
||||
if (range.startsWith("-"))
|
||||
theirfirstport = 0;
|
||||
else if (range.indexOf("-") == -1)
|
||||
theirfirstport = Integer.parseInt(range);
|
||||
else
|
||||
theirfirstport =
|
||||
Integer.parseInt(range.substring(0, range.indexOf("-")));
|
||||
|
||||
if (range.endsWith("-"))
|
||||
theirlastport = 65535;
|
||||
else if (range.indexOf("-") == -1)
|
||||
theirlastport = Integer.parseInt(range);
|
||||
else
|
||||
theirlastport =
|
||||
Integer.parseInt(range.
|
||||
substring(range.indexOf("-") + 1,
|
||||
range.length()));
|
||||
if (range.endsWith("-"))
|
||||
theirlastport = 65535;
|
||||
else if (range.indexOf("-") == -1)
|
||||
theirlastport = Integer.parseInt(range);
|
||||
else
|
||||
theirlastport =
|
||||
Integer.parseInt(range.substring(range.indexOf("-") + 1,
|
||||
range.length()));
|
||||
}
|
||||
|
||||
// Now check them
|
||||
@ -339,7 +350,10 @@ public final class SocketPermission extends Permission
|
||||
return (false);
|
||||
|
||||
// Finally we can check the hosts
|
||||
String ourhost, theirhost;
|
||||
String ourhost;
|
||||
|
||||
// Finally we can check the hosts
|
||||
String theirhost;
|
||||
|
||||
// Get ours
|
||||
if (hostport.indexOf(":") == -1)
|
||||
@ -358,20 +372,23 @@ public final class SocketPermission extends Permission
|
||||
return (true);
|
||||
|
||||
// Try the canonical names
|
||||
String ourcanonical = null, theircanonical = null;
|
||||
String ourcanonical = null;
|
||||
|
||||
// Try the canonical names
|
||||
String theircanonical = null;
|
||||
try
|
||||
{
|
||||
ourcanonical = InetAddress.getByName(ourhost).getHostName();
|
||||
theircanonical = InetAddress.getByName(theirhost).getHostName();
|
||||
ourcanonical = InetAddress.getByName(ourhost).getHostName();
|
||||
theircanonical = InetAddress.getByName(theirhost).getHostName();
|
||||
}
|
||||
catch (UnknownHostException e)
|
||||
{
|
||||
// Who didn't resolve? Just assume current address is canonical enough
|
||||
// Is this ok to do?
|
||||
if (ourcanonical == null)
|
||||
ourcanonical = ourhost;
|
||||
if (theircanonical == null)
|
||||
theircanonical = theirhost;
|
||||
// Who didn't resolve? Just assume current address is canonical enough
|
||||
// Is this ok to do?
|
||||
if (ourcanonical == null)
|
||||
ourcanonical = ourhost;
|
||||
if (theircanonical == null)
|
||||
theircanonical = theirhost;
|
||||
}
|
||||
|
||||
if (ourcanonical.equals(theircanonical))
|
||||
@ -380,9 +397,9 @@ public final class SocketPermission extends Permission
|
||||
// Well, last chance. Try for a wildcard
|
||||
if (ourhost.indexOf("*.") != -1)
|
||||
{
|
||||
String wild_domain = ourhost.substring(ourhost.indexOf("*" + 1));
|
||||
if (theircanonical.endsWith(wild_domain))
|
||||
return (true);
|
||||
String wild_domain = ourhost.substring(ourhost.indexOf("*" + 1));
|
||||
if (theircanonical.endsWith(wild_domain))
|
||||
return (true);
|
||||
}
|
||||
|
||||
// Didn't make it
|
||||
|
@ -39,6 +39,7 @@ package java.net;
|
||||
|
||||
import java.io.InterruptedIOException;
|
||||
|
||||
|
||||
/**
|
||||
* This exception signals that a socket read or accept timed out.
|
||||
*
|
||||
|
@ -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
|
||||
@ -44,14 +44,14 @@ import java.io.Serializable;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
/**
|
||||
* @author Ito Kazumitsu (ito.kazumitsu@hitachi-cable.co.jp)
|
||||
* @author Dalibor Topic (robilad@kaffe.org)
|
||||
* @author Michael Koch (konqueror@gmx.de)
|
||||
* @since 1.4
|
||||
*/
|
||||
public final class URI
|
||||
implements Comparable, Serializable
|
||||
public final class URI implements Comparable, Serializable
|
||||
{
|
||||
static final long serialVersionUID = -6052424284110960213L;
|
||||
|
||||
@ -70,11 +70,14 @@ public final class URI
|
||||
private static final String RFC2396_DIGIT = "0123456789";
|
||||
private static final String RFC2396_LOWALPHA = "abcdefghijklmnopqrstuvwxyz";
|
||||
private static final String RFC2396_UPALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
private static final String RFC2396_ALPHA = RFC2396_LOWALPHA + RFC2396_UPALPHA;
|
||||
private static final String RFC2396_ALPHA =
|
||||
RFC2396_LOWALPHA + RFC2396_UPALPHA;
|
||||
private static final String RFC2396_ALPHANUM = RFC2396_DIGIT + RFC2396_ALPHA;
|
||||
private static final String RFC2396_MARK = "-_.!~*'()";
|
||||
private static final String RFC2396_UNRESERVED = RFC2396_ALPHANUM + RFC2396_MARK;
|
||||
private static final String RFC2396_REG_NAME = RFC2396_UNRESERVED + "$,;:@&=+";
|
||||
private static final String RFC2396_UNRESERVED =
|
||||
RFC2396_ALPHANUM + RFC2396_MARK;
|
||||
private static final String RFC2396_REG_NAME =
|
||||
RFC2396_UNRESERVED + "$,;:@&=+";
|
||||
private static final String RFC2396_PCHAR = RFC2396_UNRESERVED + ":@&=+$,";
|
||||
private static final String RFC2396_SEGMENT = RFC2396_PCHAR + ";";
|
||||
private static final String RFC2396_PATH_SEGMENTS = RFC2396_SEGMENT + "/";
|
||||
@ -108,7 +111,6 @@ public final class URI
|
||||
* Index of fragment component in parsed URI.
|
||||
*/
|
||||
private static final int FRAGMENT_GROUP = 10;
|
||||
|
||||
private String scheme;
|
||||
private String rawSchemeSpecificPart;
|
||||
private String schemeSpecificPart;
|
||||
@ -126,17 +128,17 @@ public final class URI
|
||||
private String rawFragment;
|
||||
private String fragment;
|
||||
|
||||
private void readObject (ObjectInputStream is)
|
||||
private void readObject(ObjectInputStream is)
|
||||
throws ClassNotFoundException, IOException
|
||||
{
|
||||
}
|
||||
|
||||
private void writeObject (ObjectOutputStream is)
|
||||
throws IOException
|
||||
private void writeObject(ObjectOutputStream is) throws IOException
|
||||
{
|
||||
}
|
||||
|
||||
private static String getURIGroup (Matcher match, int group) {
|
||||
private static String getURIGroup(Matcher match, int group)
|
||||
{
|
||||
String matched = match.group(group);
|
||||
return matched.length() == 0 ? null : matched;
|
||||
}
|
||||
@ -148,23 +150,22 @@ public final class URI
|
||||
*
|
||||
* @exception URISyntaxException If the given string violates RFC 2396
|
||||
*/
|
||||
private void parseURI (String str)
|
||||
throws URISyntaxException
|
||||
private void parseURI(String str) throws URISyntaxException
|
||||
{
|
||||
Pattern pattern = Pattern.compile(URI_REGEXP);
|
||||
Matcher matcher = pattern.matcher(str);
|
||||
if (matcher.matches())
|
||||
{
|
||||
scheme = getURIGroup(matcher, SCHEME_GROUP);
|
||||
rawSchemeSpecificPart = getURIGroup(matcher, SCHEME_SPEC_PART_GROUP);
|
||||
rawSchemeSpecificPart = getURIGroup(matcher, SCHEME_SPEC_PART_GROUP);
|
||||
rawAuthority = getURIGroup(matcher, AUTHORITY_GROUP);
|
||||
rawPath = getURIGroup(matcher, PATH_GROUP);
|
||||
rawQuery = getURIGroup(matcher, QUERY_GROUP);
|
||||
rawFragment = getURIGroup(matcher, FRAGMENT_GROUP);
|
||||
}
|
||||
else
|
||||
throw new URISyntaxException(str,
|
||||
"doesn't match URI regular expression");
|
||||
throw new URISyntaxException(str, "doesn't match URI regular expression");
|
||||
|
||||
// We must eagerly unquote the parts, because this is the only time
|
||||
// we may throw an exception.
|
||||
schemeSpecificPart = unquote(rawSchemeSpecificPart);
|
||||
@ -184,35 +185,39 @@ public final class URI
|
||||
* @exception URISyntaxException If the given string contains invalid
|
||||
* escape sequences.
|
||||
*/
|
||||
private static String unquote (String str)
|
||||
throws URISyntaxException
|
||||
private static String unquote(String str) throws URISyntaxException
|
||||
{
|
||||
if (str == null)
|
||||
return null;
|
||||
byte[] buf = new byte[str.length()];
|
||||
int pos = 0;
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
char c = str.charAt(i);
|
||||
if (c > 127)
|
||||
for (int i = 0; i < str.length(); i++)
|
||||
{
|
||||
char c = str.charAt(i);
|
||||
if (c > 127)
|
||||
throw new URISyntaxException(str, "Invalid character");
|
||||
if (c == '%') {
|
||||
if (i + 2 >= str.length())
|
||||
throw new URISyntaxException(str, "Invalid quoted character");
|
||||
String hex = "0123456789ABCDEF";
|
||||
int hi = hex.indexOf(str.charAt(++i));
|
||||
int lo = hex.indexOf(str.charAt(++i));
|
||||
if (lo < 0 || hi < 0)
|
||||
throw new URISyntaxException(str, "Invalid quoted character");
|
||||
buf[pos++] = (byte)(hi * 16 + lo);
|
||||
} else {
|
||||
buf[pos++] = (byte)c;
|
||||
if (c == '%')
|
||||
{
|
||||
if (i + 2 >= str.length())
|
||||
throw new URISyntaxException(str, "Invalid quoted character");
|
||||
String hex = "0123456789ABCDEF";
|
||||
int hi = hex.indexOf(str.charAt(++i));
|
||||
int lo = hex.indexOf(str.charAt(++i));
|
||||
if (lo < 0 || hi < 0)
|
||||
throw new URISyntaxException(str, "Invalid quoted character");
|
||||
buf[pos++] = (byte) (hi * 16 + lo);
|
||||
}
|
||||
else
|
||||
buf[pos++] = (byte) c;
|
||||
}
|
||||
try
|
||||
{
|
||||
return new String(buf, 0, pos, "utf-8");
|
||||
}
|
||||
catch (java.io.UnsupportedEncodingException x2)
|
||||
{
|
||||
throw (Error) new InternalError().initCause(x2);
|
||||
}
|
||||
}
|
||||
try {
|
||||
return new String(buf, 0, pos, "utf-8");
|
||||
} catch (java.io.UnsupportedEncodingException x2) {
|
||||
throw (Error)new InternalError().initCause(x2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -223,10 +228,11 @@ public final class URI
|
||||
* UTF-8 character.
|
||||
*
|
||||
* @param str The string to quote
|
||||
*
|
||||
*
|
||||
* @return The quoted string.
|
||||
*/
|
||||
private static String quote (String str) {
|
||||
private static String quote(String str)
|
||||
{
|
||||
// FIXME: unimplemented.
|
||||
return str;
|
||||
}
|
||||
@ -239,10 +245,11 @@ public final class URI
|
||||
* UTF-8 character.
|
||||
*
|
||||
* @param str The string to quote
|
||||
*
|
||||
*
|
||||
* @return The quoted string.
|
||||
*/
|
||||
private static String quoteAuthority (String str) {
|
||||
private static String quoteAuthority(String str)
|
||||
{
|
||||
// Technically, we should be using RFC2396_AUTHORITY, but
|
||||
// it contains no additional characters.
|
||||
return quote(str, RFC2396_REG_NAME);
|
||||
@ -257,37 +264,39 @@ public final class URI
|
||||
*
|
||||
* @param str The string to quote
|
||||
* @param legalCharacters The set of legal characters
|
||||
*
|
||||
*
|
||||
* @return The quoted string.
|
||||
*/
|
||||
private static String quote (String str, String legalCharacters)
|
||||
private static String quote(String str, String legalCharacters)
|
||||
{
|
||||
StringBuffer sb = new StringBuffer(str.length());
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
char c = str.charAt(i);
|
||||
if (legalCharacters.indexOf(c) == -1) {
|
||||
String hex = "0123456789ABCDEF";
|
||||
if (c <= 127) {
|
||||
sb.append('%')
|
||||
.append(hex.charAt(c / 16))
|
||||
.append(hex.charAt(c % 16));
|
||||
} else {
|
||||
try {
|
||||
// this is far from optimal, but it works
|
||||
byte[] utf8 = str.substring(i, i + 1).getBytes("utf-8");
|
||||
for (int j = 0; j < utf8.length; j++) {
|
||||
sb.append('%')
|
||||
.append(hex.charAt((utf8[j] & 0xff) / 16))
|
||||
.append(hex.charAt((utf8[j] & 0xff) % 16));
|
||||
}
|
||||
} catch (java.io.UnsupportedEncodingException x) {
|
||||
throw (Error)new InternalError().initCause(x);
|
||||
for (int i = 0; i < str.length(); i++)
|
||||
{
|
||||
char c = str.charAt(i);
|
||||
if (legalCharacters.indexOf(c) == -1)
|
||||
{
|
||||
String hex = "0123456789ABCDEF";
|
||||
if (c <= 127)
|
||||
sb.append('%').append(hex.charAt(c / 16)).append(hex.charAt(c % 16));
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
// this is far from optimal, but it works
|
||||
byte[] utf8 = str.substring(i, i + 1).getBytes("utf-8");
|
||||
for (int j = 0; j < utf8.length; j++)
|
||||
sb.append('%').append(hex.charAt((utf8[j] & 0xff) / 16))
|
||||
.append(hex.charAt((utf8[j] & 0xff) % 16));
|
||||
}
|
||||
catch (java.io.UnsupportedEncodingException x)
|
||||
{
|
||||
throw (Error) new InternalError().initCause(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sb.append(c);
|
||||
else
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@ -299,10 +308,11 @@ public final class URI
|
||||
* UTF-8 character.
|
||||
*
|
||||
* @param str The string to quote
|
||||
*
|
||||
*
|
||||
* @return The quoted string.
|
||||
*/
|
||||
private static String quoteHost (String str) {
|
||||
private static String quoteHost(String str)
|
||||
{
|
||||
// FIXME: unimplemented.
|
||||
return str;
|
||||
}
|
||||
@ -315,10 +325,11 @@ public final class URI
|
||||
* UTF-8 character.
|
||||
*
|
||||
* @param str The string to quote
|
||||
*
|
||||
*
|
||||
* @return The quoted string.
|
||||
*/
|
||||
private static String quotePath (String str) {
|
||||
private static String quotePath(String str)
|
||||
{
|
||||
// Technically, we should be using RFC2396_PATH, but
|
||||
// it contains no additional characters.
|
||||
return quote(str, RFC2396_PATH_SEGMENTS);
|
||||
@ -332,10 +343,11 @@ public final class URI
|
||||
* UTF-8 character.
|
||||
*
|
||||
* @param str The string to quote
|
||||
*
|
||||
*
|
||||
* @return The quoted string.
|
||||
*/
|
||||
private static String quoteUserInfo (String str) {
|
||||
private static String quoteUserInfo(String str)
|
||||
{
|
||||
// FIXME: unimplemented.
|
||||
return str;
|
||||
}
|
||||
@ -348,12 +360,11 @@ public final class URI
|
||||
* @exception URISyntaxException If the given string violates RFC 2396
|
||||
* @exception NullPointerException If str is null
|
||||
*/
|
||||
public URI (String str)
|
||||
throws URISyntaxException
|
||||
public URI(String str) throws URISyntaxException
|
||||
{
|
||||
parseURI(str);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an URI from the given components
|
||||
*
|
||||
@ -367,19 +378,19 @@ public final class URI
|
||||
*
|
||||
* @exception URISyntaxException If the given string violates RFC 2396
|
||||
*/
|
||||
public URI (String scheme, String userInfo, String host, int port,
|
||||
String path, String query, String fragment)
|
||||
public URI(String scheme, String userInfo, String host, int port,
|
||||
String path, String query, String fragment)
|
||||
throws URISyntaxException
|
||||
{
|
||||
this((scheme == null ? "" : scheme + ":" )
|
||||
+ (userInfo == null && host == null && port == -1 ? "" : "//")
|
||||
+ (userInfo == null ? "" : quoteUserInfo(userInfo) + "@")
|
||||
+ (host == null ? "" : quoteHost(host))
|
||||
+ (port == -1 ? "" : ":" + String.valueOf(port))
|
||||
+ (path == null ? "" : quotePath(path))
|
||||
+ (query == null ? "" : "?" + quote(query))
|
||||
+ (fragment == null ? "" : "#" + quote(fragment)));
|
||||
|
||||
this((scheme == null ? "" : scheme + ":")
|
||||
+ (userInfo == null && host == null && port == -1 ? "" : "//")
|
||||
+ (userInfo == null ? "" : quoteUserInfo(userInfo) + "@")
|
||||
+ (host == null ? "" : quoteHost(host))
|
||||
+ (port == -1 ? "" : ":" + String.valueOf(port))
|
||||
+ (path == null ? "" : quotePath(path))
|
||||
+ (query == null ? "" : "?" + quote(query))
|
||||
+ (fragment == null ? "" : "#" + quote(fragment)));
|
||||
|
||||
parseServerAuthority();
|
||||
}
|
||||
|
||||
@ -394,15 +405,14 @@ public final class URI
|
||||
*
|
||||
* @exception URISyntaxException If the given string violates RFC 2396
|
||||
*/
|
||||
public URI (String scheme, String authority, String path, String query,
|
||||
String fragment)
|
||||
throws URISyntaxException
|
||||
public URI(String scheme, String authority, String path, String query,
|
||||
String fragment) throws URISyntaxException
|
||||
{
|
||||
this((scheme == null ? "" : scheme + ":")
|
||||
+ (authority == null ? "" : "//" + quoteAuthority(authority))
|
||||
+ (path == null ? "" : quotePath(path))
|
||||
+ (query == null ? "" : "?" + quote(query))
|
||||
+ (fragment == null ? "" : "#" + quote(fragment)));
|
||||
+ (authority == null ? "" : "//" + quoteAuthority(authority))
|
||||
+ (path == null ? "" : quotePath(path))
|
||||
+ (query == null ? "" : "?" + quote(query))
|
||||
+ (fragment == null ? "" : "#" + quote(fragment)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -415,7 +425,7 @@ public final class URI
|
||||
*
|
||||
* @exception URISyntaxException If the given string violates RFC 2396
|
||||
*/
|
||||
public URI (String scheme, String host, String path, String fragment)
|
||||
public URI(String scheme, String host, String path, String fragment)
|
||||
throws URISyntaxException
|
||||
{
|
||||
this(scheme, null, host, -1, path, null, fragment);
|
||||
@ -430,12 +440,12 @@ public final class URI
|
||||
*
|
||||
* @exception URISyntaxException If the given string violates RFC 2396
|
||||
*/
|
||||
public URI (String scheme, String ssp, String fragment)
|
||||
public URI(String scheme, String ssp, String fragment)
|
||||
throws URISyntaxException
|
||||
{
|
||||
this((scheme == null ? "" : scheme + ":")
|
||||
+ (ssp == null ? "" : quote(ssp))
|
||||
+ (fragment == null ? "" : "#" + quote(fragment)));
|
||||
+ (ssp == null ? "" : quote(ssp))
|
||||
+ (fragment == null ? "" : "#" + quote(fragment)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -446,16 +456,16 @@ public final class URI
|
||||
* @exception IllegalArgumentException If the given string violates RFC 2396
|
||||
* @exception NullPointerException If str is null
|
||||
*/
|
||||
public static URI create (String str)
|
||||
public static URI create(String str)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new URI(str);
|
||||
}
|
||||
catch(URISyntaxException e)
|
||||
catch (URISyntaxException e)
|
||||
{
|
||||
throw (IllegalArgumentException)
|
||||
new IllegalArgumentException().initCause(e);
|
||||
throw (IllegalArgumentException) new IllegalArgumentException()
|
||||
.initCause(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -465,8 +475,7 @@ public final class URI
|
||||
*
|
||||
* @exception URISyntaxException If the given string violates RFC 2396
|
||||
*/
|
||||
public URI parseServerAuthority ()
|
||||
throws URISyntaxException
|
||||
public URI parseServerAuthority() throws URISyntaxException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -474,7 +483,7 @@ public final class URI
|
||||
/**
|
||||
* Returns a normalizes versions of the URI
|
||||
*/
|
||||
public URI normalize ()
|
||||
public URI normalize()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -489,8 +498,8 @@ public final class URI
|
||||
*
|
||||
* @exception NullPointerException If uri is null
|
||||
*/
|
||||
public URI resolve (URI uri)
|
||||
{
|
||||
public URI resolve(URI uri)
|
||||
{
|
||||
if (uri.isAbsolute())
|
||||
return uri;
|
||||
if (uri.isOpaque())
|
||||
@ -505,35 +514,34 @@ public final class URI
|
||||
|
||||
try
|
||||
{
|
||||
if (fragment != null &&
|
||||
path != null && path.equals("") &&
|
||||
scheme == null && authority == null && query == null)
|
||||
if (fragment != null && path != null && path.equals("")
|
||||
&& scheme == null && authority == null && query == null)
|
||||
return new URI(this.scheme, this.schemeSpecificPart, fragment);
|
||||
|
||||
if (authority == null)
|
||||
if (authority == null)
|
||||
{
|
||||
authority = this.authority;
|
||||
if (path == null)
|
||||
authority = this.authority;
|
||||
if (path == null)
|
||||
path = "";
|
||||
if (!(path.startsWith("/")))
|
||||
if (! (path.startsWith("/")))
|
||||
{
|
||||
StringBuffer basepath = new StringBuffer(this.path);
|
||||
int i = this.path.lastIndexOf('/');
|
||||
StringBuffer basepath = new StringBuffer(this.path);
|
||||
int i = this.path.lastIndexOf('/');
|
||||
|
||||
if (i >= 0)
|
||||
basepath.delete(i+1, basepath.length());
|
||||
if (i >= 0)
|
||||
basepath.delete(i + 1, basepath.length());
|
||||
|
||||
basepath.append(path);
|
||||
path = basepath.toString();
|
||||
// FIXME We must normalize the path here.
|
||||
// Normalization process omitted.
|
||||
basepath.append(path);
|
||||
path = basepath.toString();
|
||||
// FIXME We must normalize the path here.
|
||||
// Normalization process omitted.
|
||||
}
|
||||
}
|
||||
return new URI(this.scheme, authority, path, query, fragment);
|
||||
return new URI(this.scheme, authority, path, query, fragment);
|
||||
}
|
||||
catch (URISyntaxException e)
|
||||
{
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -548,8 +556,7 @@ public final class URI
|
||||
* violates RFC 2396
|
||||
* @exception NullPointerException If uri is null
|
||||
*/
|
||||
public URI resolve (String str)
|
||||
throws IllegalArgumentException
|
||||
public URI resolve(String str) throws IllegalArgumentException
|
||||
{
|
||||
return resolve(create(str));
|
||||
}
|
||||
@ -563,7 +570,7 @@ public final class URI
|
||||
*
|
||||
* @exception NullPointerException If uri is null
|
||||
*/
|
||||
public URI relativize (URI uri)
|
||||
public URI relativize(URI uri)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -575,8 +582,7 @@ public final class URI
|
||||
* not be found, or if some other error occurred while constructing the URL
|
||||
* @exception IllegalArgumentException If the URI is not absolute
|
||||
*/
|
||||
public URL toURL ()
|
||||
throws IllegalArgumentException, MalformedURLException
|
||||
public URL toURL() throws IllegalArgumentException, MalformedURLException
|
||||
{
|
||||
if (isAbsolute())
|
||||
return new URL(this.toString());
|
||||
@ -587,7 +593,7 @@ public final class URI
|
||||
/**
|
||||
* Returns the scheme of the URI
|
||||
*/
|
||||
public String getScheme ()
|
||||
public String getScheme()
|
||||
{
|
||||
return scheme;
|
||||
}
|
||||
@ -595,7 +601,7 @@ public final class URI
|
||||
/**
|
||||
* Tells whether this URI is absolute or not
|
||||
*/
|
||||
public boolean isAbsolute ()
|
||||
public boolean isAbsolute()
|
||||
{
|
||||
return (scheme != null);
|
||||
}
|
||||
@ -603,16 +609,16 @@ public final class URI
|
||||
/**
|
||||
* Tell whether this URI is opaque or not
|
||||
*/
|
||||
public boolean isOpaque ()
|
||||
public boolean isOpaque()
|
||||
{
|
||||
return ((scheme != null) && !(schemeSpecificPart.startsWith("/")));
|
||||
return ((scheme != null) && ! (schemeSpecificPart.startsWith("/")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw scheme specific part of this URI.
|
||||
* The scheme-specific part is never undefined, though it may be empty
|
||||
*/
|
||||
public String getRawSchemeSpecificPart ()
|
||||
public String getRawSchemeSpecificPart()
|
||||
{
|
||||
return rawSchemeSpecificPart;
|
||||
}
|
||||
@ -620,7 +626,7 @@ public final class URI
|
||||
/**
|
||||
* Returns the decoded scheme specific part of this URI.
|
||||
*/
|
||||
public String getSchemeSpecificPart ()
|
||||
public String getSchemeSpecificPart()
|
||||
{
|
||||
return schemeSpecificPart;
|
||||
}
|
||||
@ -628,7 +634,7 @@ public final class URI
|
||||
/**
|
||||
* Returns the rae authority part of this URI
|
||||
*/
|
||||
public String getRawAuthority ()
|
||||
public String getRawAuthority()
|
||||
{
|
||||
return rawAuthority;
|
||||
}
|
||||
@ -636,7 +642,7 @@ public final class URI
|
||||
/**
|
||||
* Returns the decoded authority part of this URI
|
||||
*/
|
||||
public String getAuthority ()
|
||||
public String getAuthority()
|
||||
{
|
||||
return authority;
|
||||
}
|
||||
@ -644,7 +650,7 @@ public final class URI
|
||||
/**
|
||||
* Returns the raw user info part of this URI
|
||||
*/
|
||||
public String getRawUserInfo ()
|
||||
public String getRawUserInfo()
|
||||
{
|
||||
return rawUserInfo;
|
||||
}
|
||||
@ -652,7 +658,7 @@ public final class URI
|
||||
/**
|
||||
* Returns the decoded user info part of this URI
|
||||
*/
|
||||
public String getUserInfo ()
|
||||
public String getUserInfo()
|
||||
{
|
||||
return userInfo;
|
||||
}
|
||||
@ -660,7 +666,7 @@ public final class URI
|
||||
/**
|
||||
* Returns the hostname of the URI
|
||||
*/
|
||||
public String getHost ()
|
||||
public String getHost()
|
||||
{
|
||||
return host;
|
||||
}
|
||||
@ -668,7 +674,7 @@ public final class URI
|
||||
/**
|
||||
* Returns the port number of the URI
|
||||
*/
|
||||
public int getPort ()
|
||||
public int getPort()
|
||||
{
|
||||
return port;
|
||||
}
|
||||
@ -676,7 +682,7 @@ public final class URI
|
||||
/**
|
||||
* Returns the raw path part of this URI
|
||||
*/
|
||||
public String getRawPath ()
|
||||
public String getRawPath()
|
||||
{
|
||||
return rawPath;
|
||||
}
|
||||
@ -684,7 +690,7 @@ public final class URI
|
||||
/**
|
||||
* Returns the path of the URI
|
||||
*/
|
||||
public String getPath ()
|
||||
public String getPath()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
@ -692,7 +698,7 @@ public final class URI
|
||||
/**
|
||||
* Returns the raw query part of this URI
|
||||
*/
|
||||
public String getRawQuery ()
|
||||
public String getRawQuery()
|
||||
{
|
||||
return rawQuery;
|
||||
}
|
||||
@ -700,7 +706,7 @@ public final class URI
|
||||
/**
|
||||
* Returns the query of the URI
|
||||
*/
|
||||
public String getQuery ()
|
||||
public String getQuery()
|
||||
{
|
||||
return query;
|
||||
}
|
||||
@ -708,7 +714,7 @@ public final class URI
|
||||
/**
|
||||
* Return the raw fragment part of this URI
|
||||
*/
|
||||
public String getRawFragment ()
|
||||
public String getRawFragment()
|
||||
{
|
||||
return rawFragment;
|
||||
}
|
||||
@ -716,7 +722,7 @@ public final class URI
|
||||
/**
|
||||
* Returns the fragment of the URI
|
||||
*/
|
||||
public String getFragment ()
|
||||
public String getFragment()
|
||||
{
|
||||
return fragment;
|
||||
}
|
||||
@ -734,7 +740,7 @@ public final class URI
|
||||
/**
|
||||
* Computes the hascode of the URI
|
||||
*/
|
||||
public int hashCode ()
|
||||
public int hashCode()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -746,8 +752,7 @@ public final class URI
|
||||
*
|
||||
* @exception ClassCastException If given object ist not an URI
|
||||
*/
|
||||
public int compareTo (Object obj)
|
||||
throws ClassCastException
|
||||
public int compareTo(Object obj) throws ClassCastException
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -755,19 +760,19 @@ public final class URI
|
||||
/**
|
||||
* Returns the URI as string
|
||||
*/
|
||||
public String toString ()
|
||||
public String toString()
|
||||
{
|
||||
return (getScheme() == null ? "" : getScheme() + ":")
|
||||
+ (getRawAuthority() == null ? "" : "//" + getRawAuthority())
|
||||
+ (getRawPath() == null ? "" : getRawPath())
|
||||
+ (getRawQuery() == null ? "" : "?" + getRawQuery())
|
||||
+ (getRawFragment() == null ? "" : "#" + getRawFragment());
|
||||
+ (getRawAuthority() == null ? "" : "//" + getRawAuthority())
|
||||
+ (getRawPath() == null ? "" : getRawPath())
|
||||
+ (getRawQuery() == null ? "" : "?" + getRawQuery())
|
||||
+ (getRawFragment() == null ? "" : "#" + getRawFragment());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URI as US-ASCII string
|
||||
*/
|
||||
public String toASCIIString ()
|
||||
public String toASCIIString()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ exception statement from your version. */
|
||||
|
||||
package java.net;
|
||||
|
||||
|
||||
/**
|
||||
* This exception is thrown when a String cannot be parsed as a URI.
|
||||
*
|
||||
@ -137,7 +138,7 @@ public class URISyntaxException extends Exception
|
||||
*/
|
||||
public String getMessage()
|
||||
{
|
||||
return super.getMessage() + (index >= 0 ? " at index " + index : "")
|
||||
+ ": " + input;
|
||||
return (super.getMessage() + (index >= 0 ? " at index " + index : "")
|
||||
+ ": " + input);
|
||||
}
|
||||
}
|
||||
|
@ -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,18 @@ this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.net;
|
||||
|
||||
import gnu.java.net.URLParseError;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
|
||||
/*
|
||||
* Written using on-line Java Platform 1.2 API Specification, as well
|
||||
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
|
||||
@ -56,7 +56,7 @@ import java.util.StringTokenizer;
|
||||
/**
|
||||
* This final class represents an Internet Uniform Resource Locator (URL).
|
||||
* For details on the syntax of URL's and what they can be used for,
|
||||
* refer to RFC 1738, available from <a
|
||||
* refer to RFC 1738, available from <a
|
||||
* href="http://ds.internic.net/rfcs/rfc1738.txt">
|
||||
* http://ds.internic.net/rfcs/rfc1738.txt</a>
|
||||
* <p>
|
||||
@ -74,7 +74,7 @@ import java.util.StringTokenizer;
|
||||
* This chaining is done via the system property java.protocol.handler.pkgs
|
||||
* If this property is set, it is assumed to be a "|" separated list of
|
||||
* package names in which to attempt locating protocol handlers. The
|
||||
* protocol handler is searched for by appending the string
|
||||
* protocol handler is searched for by appending the string
|
||||
* ".<protocol>.Handler" to each packed in the list until a hander is
|
||||
* found. If a protocol handler is not found in this list of packages, or if
|
||||
* the property does not exist, then the default protocol handler of
|
||||
@ -87,7 +87,7 @@ import java.util.StringTokenizer;
|
||||
* <p>
|
||||
* Here is an example of how URL searches for protocol handlers. Assume
|
||||
* the value of java.protocol.handler.pkgs is "com.foo|com.bar" and the
|
||||
* URL is "news://comp.lang.java.programmer". URL would looking the
|
||||
* URL is "news://comp.lang.java.programmer". URL would looking the
|
||||
* following places for protocol handlers:
|
||||
* <p><pre>
|
||||
* com.foo.news.Handler
|
||||
@ -122,7 +122,7 @@ public final class URL implements Serializable
|
||||
{
|
||||
private static final String DEFAULT_SEARCH_PATH =
|
||||
"gnu.java.net.protocol|sun.net.www.protocol";
|
||||
|
||||
|
||||
/**
|
||||
* The name of the protocol for this URL.
|
||||
* The protocol is always stored in lower case.
|
||||
@ -144,7 +144,7 @@ public final class URL implements Serializable
|
||||
* The port number of this protocol or -1 if the port number used is
|
||||
* the default for this protocol.
|
||||
*/
|
||||
private int port = -1; // Initialize for constructor using context.
|
||||
private int port = -1; // Initialize for constructor using context.
|
||||
|
||||
/**
|
||||
* The "file" portion of the URL. It is defined as <code>path[?query]</code>.
|
||||
@ -171,7 +171,6 @@ public final class URL implements Serializable
|
||||
* where we keep track of it.
|
||||
*/
|
||||
private static URLStreamHandlerFactory factory;
|
||||
|
||||
private static final long serialVersionUID = -7627629688361524110L;
|
||||
|
||||
/**
|
||||
@ -187,18 +186,18 @@ public final class URL implements Serializable
|
||||
|
||||
static
|
||||
{
|
||||
String s = System.getProperty ("gnu.java.net.nocache_protocol_handlers");
|
||||
|
||||
String s = System.getProperty("gnu.java.net.nocache_protocol_handlers");
|
||||
|
||||
if (s == null)
|
||||
cache_handlers = true;
|
||||
cache_handlers = true;
|
||||
else
|
||||
cache_handlers = false;
|
||||
cache_handlers = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a URL and loads a protocol handler for the values passed as
|
||||
* arguments.
|
||||
*
|
||||
*
|
||||
* @param protocol The protocol for this URL ("http", "ftp", etc)
|
||||
* @param host The hostname or IP address to connect to
|
||||
* @param port The port number to use, or -1 to use the protocol's
|
||||
@ -231,11 +230,10 @@ public final class URL implements Serializable
|
||||
this(protocol, host, -1, file, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method initializes a new instance of <code>URL</code> with the
|
||||
* specified protocol, host, port, and file. Additionally, this method
|
||||
* allows the caller to specify a protocol handler to use instead of
|
||||
* allows the caller to specify a protocol handler to use instead of
|
||||
* the default. If this handler is specified, the caller must have
|
||||
* the "specifyStreamHandler" permission (see <code>NetPermission</code>)
|
||||
* or a <code>SecurityException</code> will be thrown.
|
||||
@ -254,9 +252,8 @@ public final class URL implements Serializable
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
public URL (String protocol, String host, int port, String file,
|
||||
URLStreamHandler ph)
|
||||
throws MalformedURLException
|
||||
public URL(String protocol, String host, int port, String file,
|
||||
URLStreamHandler ph) throws MalformedURLException
|
||||
{
|
||||
if (protocol == null)
|
||||
throw new MalformedURLException("null protocol");
|
||||
@ -266,16 +263,16 @@ public final class URL implements Serializable
|
||||
{
|
||||
SecurityManager s = System.getSecurityManager();
|
||||
if (s != null)
|
||||
s.checkPermission (new NetPermission ("specifyStreamHandler"));
|
||||
s.checkPermission(new NetPermission("specifyStreamHandler"));
|
||||
|
||||
this.ph = ph;
|
||||
this.ph = ph;
|
||||
}
|
||||
else
|
||||
this.ph = getURLStreamHandler(protocol);
|
||||
|
||||
if (this.ph == null)
|
||||
throw new MalformedURLException (
|
||||
"Protocol handler not found: " + protocol);
|
||||
throw new MalformedURLException("Protocol handler not found: "
|
||||
+ protocol);
|
||||
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
@ -292,7 +289,7 @@ public final class URL implements Serializable
|
||||
this.file = file.substring(0, hashAt);
|
||||
this.ref = file.substring(hashAt + 1);
|
||||
}
|
||||
hashCode = hashCode(); // Used for serialization.
|
||||
hashCode = hashCode(); // Used for serialization.
|
||||
}
|
||||
|
||||
/**
|
||||
@ -325,7 +322,7 @@ public final class URL implements Serializable
|
||||
* @param context The context on which to parse the specification
|
||||
* @param spec The string to parse an URL
|
||||
*
|
||||
* @exception MalformedURLException If a protocol handler cannot be found
|
||||
* @exception MalformedURLException If a protocol handler cannot be found
|
||||
* for the URL cannot be parsed
|
||||
*/
|
||||
public URL(URL context, String spec) throws MalformedURLException
|
||||
@ -340,7 +337,7 @@ public final class URL implements Serializable
|
||||
* not present the URL are inheritied from the context URL. This allows
|
||||
* relative URL's to be easily constructed. If the context argument is
|
||||
* null, then a complete URL must be specified in the URL string.
|
||||
* If the protocol parsed out of the URL is different
|
||||
* If the protocol parsed out of the URL is different
|
||||
* from the context URL's protocol, then then URL String is also
|
||||
* expected to be a complete URL.
|
||||
* <p>
|
||||
@ -372,7 +369,7 @@ public final class URL implements Serializable
|
||||
* The relative URL need not specify all the components of a URL.
|
||||
* If the protocol, host name, or port number is missing, the value
|
||||
* is inherited from the context. A bare file component is appended
|
||||
* to the context's file. The optional anchor is not inherited.
|
||||
* to the context's file. The optional anchor is not inherited.
|
||||
*/
|
||||
|
||||
// If this is an absolute URL, then ignore context completely.
|
||||
@ -380,13 +377,13 @@ public final class URL implements Serializable
|
||||
// right after the "://". The second colon is for an optional port value
|
||||
// and implies that the host from the context is used if available.
|
||||
int colon;
|
||||
if ((colon = spec.indexOf("://", 1)) > 0 &&
|
||||
! spec.regionMatches(colon, "://:", 0, 4))
|
||||
if ((colon = spec.indexOf("://", 1)) > 0
|
||||
&& ! spec.regionMatches(colon, "://:", 0, 4))
|
||||
context = null;
|
||||
|
||||
int slash;
|
||||
if ((colon = spec.indexOf(':')) > 0 &&
|
||||
(colon < (slash = spec.indexOf('/')) || slash < 0))
|
||||
if ((colon = spec.indexOf(':')) > 0
|
||||
&& (colon < (slash = spec.indexOf('/')) || slash < 0))
|
||||
{
|
||||
// Protocol specified in spec string.
|
||||
protocol = spec.substring(0, colon).toLowerCase();
|
||||
@ -412,26 +409,27 @@ public final class URL implements Serializable
|
||||
file = context.file;
|
||||
if (file == null || file.length() == 0)
|
||||
file = "/";
|
||||
authority = context.authority;
|
||||
authority = context.authority;
|
||||
}
|
||||
else // Protocol NOT specified in spec. and no context available.
|
||||
throw new
|
||||
MalformedURLException("Absolute URL required with null context");
|
||||
else // Protocol NOT specified in spec. and no context available.
|
||||
|
||||
|
||||
throw new MalformedURLException("Absolute URL required with null context");
|
||||
|
||||
if (ph != null)
|
||||
{
|
||||
SecurityManager s = System.getSecurityManager ();
|
||||
SecurityManager s = System.getSecurityManager();
|
||||
if (s != null)
|
||||
s.checkPermission (new NetPermission ("specifyStreamHandler"));
|
||||
s.checkPermission(new NetPermission("specifyStreamHandler"));
|
||||
|
||||
this.ph = ph;
|
||||
this.ph = ph;
|
||||
}
|
||||
else
|
||||
this.ph = getURLStreamHandler(protocol);
|
||||
|
||||
if (this.ph == null)
|
||||
throw new MalformedURLException("Protocol handler not found: "
|
||||
+ protocol);
|
||||
+ protocol);
|
||||
|
||||
// JDK 1.2 doc for parseURL specifically states that any '#' ref
|
||||
// is to be excluded by passing the 'limit' as the indexOf the '#'
|
||||
@ -441,35 +439,35 @@ public final class URL implements Serializable
|
||||
try
|
||||
{
|
||||
this.ph.parseURL(this, spec, colon + 1,
|
||||
hashAt < 0 ? spec.length() : hashAt);
|
||||
hashAt < 0 ? spec.length() : hashAt);
|
||||
}
|
||||
catch (URLParseError e)
|
||||
{
|
||||
throw new MalformedURLException(e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
if (hashAt >= 0)
|
||||
ref = spec.substring(hashAt + 1);
|
||||
|
||||
hashCode = hashCode(); // Used for serialization.
|
||||
hashCode = hashCode(); // Used for serialization.
|
||||
}
|
||||
|
||||
/**
|
||||
* Test another URL for equality with this one. This will be true only if
|
||||
* the argument is non-null and all of the fields in the URL's match
|
||||
* the argument is non-null and all of the fields in the URL's match
|
||||
* exactly (ie, protocol, host, port, file, and ref). Overrides
|
||||
* Object.equals(), implemented by calling the equals method of the handler.
|
||||
*
|
||||
* @param url The URL to compare with
|
||||
* @param obj The URL to compare with
|
||||
*
|
||||
* @return true if the URL is equal, false otherwise
|
||||
*/
|
||||
public boolean equals (Object obj)
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (! (obj instanceof URL))
|
||||
return false;
|
||||
|
||||
return ph.equals (this, (URL) obj);
|
||||
return ph.equals(this, (URL) obj);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -519,7 +517,7 @@ public final class URL implements Serializable
|
||||
* character.
|
||||
*
|
||||
* @return The path specified in this URL.
|
||||
*
|
||||
*
|
||||
* @since 1.3
|
||||
*/
|
||||
public String getPath()
|
||||
@ -532,7 +530,7 @@ public final class URL implements Serializable
|
||||
* Returns the authority of the URL
|
||||
*
|
||||
* @return The authority specified in this URL.
|
||||
*
|
||||
*
|
||||
* @since 1.3
|
||||
*/
|
||||
public String getAuthority()
|
||||
@ -602,7 +600,7 @@ public final class URL implements Serializable
|
||||
*
|
||||
* @return the user at a particular host or null when no user defined.
|
||||
*/
|
||||
public String getUserInfo ()
|
||||
public String getUserInfo()
|
||||
{
|
||||
int at = (host == null) ? -1 : host.indexOf('@');
|
||||
return at < 0 ? null : host.substring(0, at);
|
||||
@ -614,7 +612,7 @@ public final class URL implements Serializable
|
||||
*
|
||||
* @return the query part of the file, or null when there is no query part.
|
||||
*/
|
||||
public String getQuery ()
|
||||
public String getQuery()
|
||||
{
|
||||
int quest = (file == null) ? -1 : file.indexOf('?');
|
||||
return quest < 0 ? null : file.substring(quest + 1, file.length());
|
||||
@ -628,9 +626,9 @@ public final class URL implements Serializable
|
||||
public int hashCode()
|
||||
{
|
||||
if (hashCode != 0)
|
||||
return hashCode; // Use cached value if available.
|
||||
return hashCode; // Use cached value if available.
|
||||
else
|
||||
return ph.hashCode (this);
|
||||
return ph.hashCode(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -652,7 +650,7 @@ public final class URL implements Serializable
|
||||
* from that connection
|
||||
*
|
||||
* @return An <code>InputStream</code> for this URL.
|
||||
*
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
public final InputStream openStream() throws IOException
|
||||
@ -670,9 +668,9 @@ public final class URL implements Serializable
|
||||
*
|
||||
* @return true if URL matches this URL's file, false otherwise
|
||||
*/
|
||||
public boolean sameFile(URL other)
|
||||
public boolean sameFile(URL url)
|
||||
{
|
||||
return ph.sameFile(this, other);
|
||||
return ph.sameFile(this, url);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -688,7 +686,7 @@ public final class URL implements Serializable
|
||||
* @param ref The anchor portion of this URL.
|
||||
*/
|
||||
protected void set(String protocol, String host, int port, String file,
|
||||
String ref)
|
||||
String ref)
|
||||
{
|
||||
// TBD: Theoretically, a poorly written StreamHandler could pass an
|
||||
// invalid protocol. It will cause the handler to be set to null
|
||||
@ -701,7 +699,7 @@ public final class URL implements Serializable
|
||||
this.host = host;
|
||||
this.file = file;
|
||||
this.ref = ref;
|
||||
hashCode = hashCode(); // Used for serialization.
|
||||
hashCode = hashCode(); // Used for serialization.
|
||||
}
|
||||
|
||||
/**
|
||||
@ -720,9 +718,8 @@ public final class URL implements Serializable
|
||||
*
|
||||
* @since 1.3
|
||||
*/
|
||||
protected void set(String protocol, String host, int port,
|
||||
String authority, String userInfo,
|
||||
String path, String query, String ref)
|
||||
protected void set(String protocol, String host, int port, String authority,
|
||||
String userInfo, String path, String query, String ref)
|
||||
{
|
||||
// TBD: Theoretically, a poorly written StreamHandler could pass an
|
||||
// invalid protocol. It will cause the handler to be set to null
|
||||
@ -740,7 +737,7 @@ public final class URL implements Serializable
|
||||
else
|
||||
this.file = path + "?" + query;
|
||||
this.ref = ref;
|
||||
hashCode = hashCode(); // Used for serialization.
|
||||
hashCode = hashCode(); // Used for serialization.
|
||||
}
|
||||
|
||||
/**
|
||||
@ -754,8 +751,7 @@ public final class URL implements Serializable
|
||||
* @exception SecurityException If a security manager exists and its
|
||||
* checkSetFactory method doesn't allow the operation
|
||||
*/
|
||||
public static synchronized void
|
||||
setURLStreamHandlerFactory(URLStreamHandlerFactory fac)
|
||||
public static synchronized void setURLStreamHandlerFactory(URLStreamHandlerFactory fac)
|
||||
{
|
||||
if (factory != null)
|
||||
throw new Error("URLStreamHandlerFactory already set");
|
||||
@ -782,7 +778,7 @@ public final class URL implements Serializable
|
||||
|
||||
/**
|
||||
* Returns a String representing this URL. Identical to toExternalForm().
|
||||
* The value returned is created by the protocol handler's
|
||||
* The value returned is created by the protocol handler's
|
||||
* toExternalForm method. Overrides Object.toString()
|
||||
*
|
||||
* @return A string for this URL
|
||||
@ -801,16 +797,15 @@ public final class URL implements Serializable
|
||||
*
|
||||
* @return A URLStreamHandler for this protocol, or null when not found.
|
||||
*/
|
||||
private static synchronized URLStreamHandler
|
||||
getURLStreamHandler (String protocol)
|
||||
private static synchronized URLStreamHandler getURLStreamHandler(String protocol)
|
||||
{
|
||||
URLStreamHandler ph = null;
|
||||
|
||||
// First, see if a protocol handler is in our cache.
|
||||
if (cache_handlers)
|
||||
{
|
||||
if ((ph = (URLStreamHandler) ph_cache.get (protocol)) != null)
|
||||
return ph;
|
||||
if ((ph = (URLStreamHandler) ph_cache.get(protocol)) != null)
|
||||
return ph;
|
||||
}
|
||||
|
||||
// If a non-default factory has been set, use it to find the protocol.
|
||||
@ -850,42 +845,41 @@ public final class URL implements Serializable
|
||||
|
||||
// Tack our default package on at the ends.
|
||||
if (ph_search_path != null)
|
||||
ph_search_path += "|" + DEFAULT_SEARCH_PATH;
|
||||
ph_search_path += "|" + DEFAULT_SEARCH_PATH;
|
||||
else
|
||||
ph_search_path = DEFAULT_SEARCH_PATH;
|
||||
ph_search_path = DEFAULT_SEARCH_PATH;
|
||||
|
||||
// Finally loop through our search path looking for a match.
|
||||
StringTokenizer pkgPrefix = new StringTokenizer (ph_search_path, "|");
|
||||
|
||||
StringTokenizer pkgPrefix = new StringTokenizer(ph_search_path, "|");
|
||||
|
||||
do
|
||||
{
|
||||
String clsName = (pkgPrefix.nextToken() + "."
|
||||
+ protocol + ".Handler");
|
||||
|
||||
try
|
||||
{
|
||||
Object obj = Class.forName (clsName).newInstance();
|
||||
|
||||
if (!(obj instanceof URLStreamHandler))
|
||||
continue;
|
||||
else
|
||||
ph = (URLStreamHandler) obj;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Can't instantiate; handler still null,
|
||||
{
|
||||
String clsName =
|
||||
(pkgPrefix.nextToken() + "." + protocol + ".Handler");
|
||||
|
||||
try
|
||||
{
|
||||
Object obj = Class.forName(clsName).newInstance();
|
||||
|
||||
if (! (obj instanceof URLStreamHandler))
|
||||
continue;
|
||||
else
|
||||
ph = (URLStreamHandler) obj;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Can't instantiate; handler still null,
|
||||
// go on to next element.
|
||||
}
|
||||
}
|
||||
while ((! (ph instanceof URLStreamHandler))
|
||||
&& pkgPrefix.hasMoreTokens());
|
||||
}
|
||||
}
|
||||
while ((! (ph instanceof URLStreamHandler))
|
||||
&& pkgPrefix.hasMoreTokens());
|
||||
}
|
||||
|
||||
// Update the hashtable with the new protocol handler.
|
||||
if (ph != null
|
||||
&& cache_handlers)
|
||||
if (ph != null && cache_handlers)
|
||||
if (ph instanceof URLStreamHandler)
|
||||
ph_cache.put (protocol, ph);
|
||||
ph_cache.put(protocol, ph);
|
||||
else
|
||||
ph = null;
|
||||
|
||||
|
@ -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 java.io.ByteArrayOutputStream;
|
||||
@ -43,24 +42,25 @@ import java.io.EOFException;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FilePermission;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.AccessController;
|
||||
import java.io.InputStream;
|
||||
import java.security.AccessControlContext;
|
||||
import java.security.AccessController;
|
||||
import java.security.CodeSource;
|
||||
import java.security.SecureClassLoader;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.PermissionCollection;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.SecureClassLoader;
|
||||
import java.security.cert.Certificate;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
import java.util.HashMap;
|
||||
import java.util.Vector;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
import gnu.gcj.runtime.SharedLibHelper;
|
||||
|
||||
|
||||
/**
|
||||
* A secure class loader that can load classes and resources from
|
||||
* multiple locations. Given an array of <code>URL</code>s this class
|
||||
@ -118,7 +118,6 @@ import gnu.gcj.runtime.SharedLibHelper;
|
||||
* @author Mark Wielaard (mark@klomp.org)
|
||||
* @author Wu Gansha (gansha.wu@intel.com)
|
||||
*/
|
||||
|
||||
public class URLClassLoader extends SecureClassLoader
|
||||
{
|
||||
// Class Variables
|
||||
@ -130,7 +129,7 @@ public class URLClassLoader extends SecureClassLoader
|
||||
* XXX - Keeps these loaders forever which prevents garbage collection.
|
||||
*/
|
||||
private static HashMap urlloaders = new HashMap();
|
||||
|
||||
|
||||
/**
|
||||
* A cache to store mappings between handler factory and its
|
||||
* private protocol handler cache (also a HashMap), so we can avoid
|
||||
@ -144,12 +143,12 @@ public class URLClassLoader extends SecureClassLoader
|
||||
private final Vector urls = new Vector();
|
||||
|
||||
/**
|
||||
* Store pre-parsed information for each url into this vector
|
||||
* each element is a URL loader, corresponding to the URL of
|
||||
* Store pre-parsed information for each url into this vector
|
||||
* each element is a URL loader, corresponding to the URL of
|
||||
* the same index in "urls"
|
||||
*/
|
||||
private final Vector urlinfos = new Vector();
|
||||
|
||||
|
||||
/** Factory used to get the protocol handlers of the URLs */
|
||||
private final URLStreamHandlerFactory factory;
|
||||
|
||||
@ -161,12 +160,12 @@ public class URLClassLoader extends SecureClassLoader
|
||||
private final AccessControlContext securityContext;
|
||||
|
||||
// Helper classes
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* A <code>URLLoader</code> contains all logic to load resources from a
|
||||
* given base <code>URL</code>.
|
||||
*/
|
||||
static abstract class URLLoader
|
||||
abstract static class URLLoader
|
||||
{
|
||||
/**
|
||||
* Our classloader to get info from if needed.
|
||||
@ -223,14 +222,14 @@ public class URLClassLoader extends SecureClassLoader
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* A <code>Resource</code> represents a resource in some
|
||||
* <code>URLLoader</code>. It also contains all information (e.g.,
|
||||
* <code>URL</code>, <code>CodeSource</code>, <code>Manifest</code> and
|
||||
* <code>InputStream</code>) that is necessary for loading resources
|
||||
* and creating classes from a <code>URL</code>.
|
||||
*/
|
||||
static abstract class Resource
|
||||
abstract static class Resource
|
||||
{
|
||||
final URLLoader loader;
|
||||
final String name;
|
||||
@ -285,10 +284,10 @@ public class URLClassLoader extends SecureClassLoader
|
||||
* A <code>JarURLLoader</code> is a type of <code>URLLoader</code>
|
||||
* only loading from jar url.
|
||||
*/
|
||||
final static class JarURLLoader extends URLLoader
|
||||
static final class JarURLLoader extends URLLoader
|
||||
{
|
||||
final JarFile jarfile; // The jar file for this url
|
||||
final URL baseJarURL; // Base jar: url for all resources loaded from jar
|
||||
final URL baseJarURL; // Base jar: url for all resources loaded from jar
|
||||
|
||||
public JarURLLoader(URLClassLoader classloader, URL baseURL)
|
||||
{
|
||||
@ -305,13 +304,17 @@ public class URLClassLoader extends SecureClassLoader
|
||||
URL baseJarURL = null;
|
||||
JarFile jarfile = null;
|
||||
try
|
||||
{
|
||||
baseJarURL
|
||||
= new URL(null, jarURL, classloader.getURLStreamHandler("jar"));
|
||||
jarfile
|
||||
= ((JarURLConnection) baseJarURL.openConnection()).getJarFile();
|
||||
}
|
||||
catch (IOException ioe) { /* ignored */ }
|
||||
{
|
||||
baseJarURL =
|
||||
new URL(null, jarURL, classloader.getURLStreamHandler("jar"));
|
||||
|
||||
jarfile =
|
||||
((JarURLConnection) baseJarURL.openConnection()).getJarFile();
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
/* ignored */
|
||||
}
|
||||
|
||||
this.baseJarURL = baseJarURL;
|
||||
this.jarfile = jarfile;
|
||||
@ -324,10 +327,10 @@ public class URLClassLoader extends SecureClassLoader
|
||||
return null;
|
||||
|
||||
if (name.startsWith("/"))
|
||||
name = name.substring(1);
|
||||
name = name.substring(1);
|
||||
|
||||
JarEntry je = jarfile.getJarEntry(name);
|
||||
if(je != null)
|
||||
if (je != null)
|
||||
return new JarURLResource(this, name, je);
|
||||
else
|
||||
return null;
|
||||
@ -336,17 +339,17 @@ public class URLClassLoader extends SecureClassLoader
|
||||
Manifest getManifest()
|
||||
{
|
||||
try
|
||||
{
|
||||
{
|
||||
return (jarfile == null) ? null : jarfile.getManifest();
|
||||
}
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final static class JarURLResource extends Resource
|
||||
static final class JarURLResource extends Resource
|
||||
{
|
||||
private final JarEntry entry;
|
||||
|
||||
@ -358,12 +361,12 @@ public class URLClassLoader extends SecureClassLoader
|
||||
|
||||
InputStream getInputStream() throws IOException
|
||||
{
|
||||
return ((JarURLLoader)loader).jarfile.getInputStream(entry);
|
||||
return ((JarURLLoader) loader).jarfile.getInputStream(entry);
|
||||
}
|
||||
|
||||
int getLength()
|
||||
{
|
||||
return (int)entry.getSize();
|
||||
return (int) entry.getSize();
|
||||
}
|
||||
|
||||
Certificate[] getCertificates()
|
||||
@ -374,25 +377,25 @@ public class URLClassLoader extends SecureClassLoader
|
||||
URL getURL()
|
||||
{
|
||||
try
|
||||
{
|
||||
return new URL(((JarURLLoader)loader).baseJarURL, name,
|
||||
loader.classloader.getURLStreamHandler("jar"));
|
||||
}
|
||||
catch(MalformedURLException e)
|
||||
{
|
||||
{
|
||||
return new URL(((JarURLLoader) loader).baseJarURL, name,
|
||||
loader.classloader.getURLStreamHandler("jar"));
|
||||
}
|
||||
catch (MalformedURLException e)
|
||||
{
|
||||
InternalError ie = new InternalError();
|
||||
ie.initCause(e);
|
||||
throw ie;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loader for remote directories.
|
||||
*/
|
||||
final static class RemoteURLLoader extends URLLoader
|
||||
static final class RemoteURLLoader extends URLLoader
|
||||
{
|
||||
final private String protocol;
|
||||
private final String protocol;
|
||||
|
||||
RemoteURLLoader(URLClassLoader classloader, URL url)
|
||||
{
|
||||
@ -407,9 +410,9 @@ public class URLClassLoader extends SecureClassLoader
|
||||
Resource getResource(String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
URL url = new URL(baseURL, name,
|
||||
classloader.getURLStreamHandler(protocol));
|
||||
{
|
||||
URL url =
|
||||
new URL(baseURL, name, classloader.getURLStreamHandler(protocol));
|
||||
URLConnection connection = url.openConnection();
|
||||
|
||||
// Open the connection and check the stream
|
||||
@ -420,9 +423,9 @@ public class URLClassLoader extends SecureClassLoader
|
||||
// We can do some extra checking if it is a http request
|
||||
if (connection instanceof HttpURLConnection)
|
||||
{
|
||||
int response
|
||||
= ((HttpURLConnection)connection).getResponseCode();
|
||||
if (response/100 != 2)
|
||||
int response =
|
||||
((HttpURLConnection) connection).getResponseCode();
|
||||
if (response / 100 != 2)
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -430,25 +433,25 @@ public class URLClassLoader extends SecureClassLoader
|
||||
return new RemoteResource(this, name, url, stream, length);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A resource from some remote location.
|
||||
*/
|
||||
final static class RemoteResource extends Resource
|
||||
static final class RemoteResource extends Resource
|
||||
{
|
||||
final private URL url;
|
||||
final private InputStream stream;
|
||||
final private int length;
|
||||
private final URL url;
|
||||
private final InputStream stream;
|
||||
private final int length;
|
||||
|
||||
RemoteResource(RemoteURLLoader loader, String name, URL url,
|
||||
InputStream stream, int length)
|
||||
InputStream stream, int length)
|
||||
{
|
||||
super(loader, name);
|
||||
this.url = url;
|
||||
@ -533,9 +536,9 @@ public class URLClassLoader extends SecureClassLoader
|
||||
* A <code>FileURLLoader</code> is a type of <code>URLLoader</code>
|
||||
* only loading from file url.
|
||||
*/
|
||||
final static class FileURLLoader extends URLLoader
|
||||
static final class FileURLLoader extends URLLoader
|
||||
{
|
||||
File dir; //the file for this file url
|
||||
File dir; //the file for this file url
|
||||
|
||||
FileURLLoader(URLClassLoader classloader, URL url)
|
||||
{
|
||||
@ -547,13 +550,13 @@ public class URLClassLoader extends SecureClassLoader
|
||||
Resource getResource(String name)
|
||||
{
|
||||
File file = new File(dir, name);
|
||||
if (file.exists() && !file.isDirectory())
|
||||
if (file.exists() && ! file.isDirectory())
|
||||
return new FileResource(this, name, file);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
final static class FileResource extends Resource
|
||||
static final class FileResource extends Resource
|
||||
{
|
||||
final File file;
|
||||
|
||||
@ -567,28 +570,28 @@ public class URLClassLoader extends SecureClassLoader
|
||||
{
|
||||
return new FileInputStream(file);
|
||||
}
|
||||
|
||||
|
||||
public int getLength()
|
||||
{
|
||||
return (int)file.length();
|
||||
return (int) file.length();
|
||||
}
|
||||
|
||||
public URL getURL()
|
||||
{
|
||||
try
|
||||
{
|
||||
{
|
||||
return new URL(loader.baseURL, name,
|
||||
loader.classloader.getURLStreamHandler("file"));
|
||||
}
|
||||
catch(MalformedURLException e)
|
||||
{
|
||||
loader.classloader.getURLStreamHandler("file"));
|
||||
}
|
||||
catch (MalformedURLException e)
|
||||
{
|
||||
InternalError ie = new InternalError();
|
||||
ie.initCause(e);
|
||||
throw ie;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
/**
|
||||
@ -642,7 +645,7 @@ public class URLClassLoader extends SecureClassLoader
|
||||
* load classes and resources (after using the supplied parent ClassLoader).
|
||||
* @exception SecurityException if the SecurityManager disallows the
|
||||
* creation of a ClassLoader.
|
||||
* @exception SecurityException
|
||||
* @exception SecurityException
|
||||
* @param urls Locations that should be searched by this ClassLoader when
|
||||
* resolving Classes or Resources.
|
||||
* @param parent The parent class loader used before trying this class
|
||||
@ -672,7 +675,7 @@ public class URLClassLoader extends SecureClassLoader
|
||||
* @param securityContext the security context of the unprivileged code.
|
||||
*/
|
||||
private URLClassLoader(ClassLoader parent,
|
||||
AccessControlContext securityContext)
|
||||
AccessControlContext securityContext)
|
||||
{
|
||||
super(parent);
|
||||
this.factory = null;
|
||||
@ -690,7 +693,7 @@ public class URLClassLoader extends SecureClassLoader
|
||||
* protocol handlers of the supplied URLs.
|
||||
* @exception SecurityException if the SecurityManager disallows the
|
||||
* creation of a ClassLoader.
|
||||
* @exception SecurityException
|
||||
* @exception SecurityException
|
||||
* @param urls Locations that should be searched by this ClassLoader when
|
||||
* resolving Classes or Resources.
|
||||
* @param parent The parent class loader used before trying this class
|
||||
@ -698,9 +701,8 @@ public class URLClassLoader extends SecureClassLoader
|
||||
* @param factory Used to get the protocol handler for the URLs.
|
||||
* @see SecureClassLoader
|
||||
*/
|
||||
public URLClassLoader(URL[] urls,
|
||||
ClassLoader parent,
|
||||
URLStreamHandlerFactory factory)
|
||||
public URLClassLoader(URL[] urls, ClassLoader parent,
|
||||
URLStreamHandlerFactory factory)
|
||||
throws SecurityException
|
||||
{
|
||||
super(parent);
|
||||
@ -711,7 +713,7 @@ public class URLClassLoader extends SecureClassLoader
|
||||
// If this factory is still not in factoryCache, add it,
|
||||
// since we only support three protocols so far, 5 is enough
|
||||
// for cache initial size
|
||||
synchronized(factoryCache)
|
||||
synchronized (factoryCache)
|
||||
{
|
||||
if (factory != null && factoryCache.get(factory) == null)
|
||||
factoryCache.put(factory, new HashMap(5));
|
||||
@ -731,14 +733,14 @@ public class URLClassLoader extends SecureClassLoader
|
||||
|
||||
private void addURLImpl(URL newUrl)
|
||||
{
|
||||
synchronized(urlloaders)
|
||||
synchronized (urlloaders)
|
||||
{
|
||||
if (newUrl == null)
|
||||
return; // Silently ignore...
|
||||
|
||||
|
||||
// Check global cache to see if there're already url loader
|
||||
// for this url.
|
||||
URLLoader loader = (URLLoader)urlloaders.get(newUrl);
|
||||
URLLoader loader = (URLLoader) urlloaders.get(newUrl);
|
||||
if (loader == null)
|
||||
{
|
||||
String file = newUrl.getFile();
|
||||
@ -769,12 +771,10 @@ public class URLClassLoader extends SecureClassLoader
|
||||
private void addURLs(URL[] newUrls)
|
||||
{
|
||||
for (int i = 0; i < newUrls.length; i++)
|
||||
{
|
||||
addURLImpl(newUrls[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Defines a Package based on the given name and the supplied manifest
|
||||
* information. The manifest indicates the tile, version and
|
||||
* vendor information of the specification and implementation and wheter the
|
||||
@ -789,22 +789,16 @@ public class URLClassLoader extends SecureClassLoader
|
||||
* @param url the code source url to seal the package
|
||||
* @return the defined Package
|
||||
*/
|
||||
protected Package definePackage(String name, Manifest manifest, URL url)
|
||||
protected Package definePackage(String name, Manifest manifest, URL url)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
Attributes attr = manifest.getMainAttributes();
|
||||
String specTitle =
|
||||
attr.getValue(Attributes.Name.SPECIFICATION_TITLE);
|
||||
String specVersion =
|
||||
attr.getValue(Attributes.Name.SPECIFICATION_VERSION);
|
||||
String specVendor =
|
||||
attr.getValue(Attributes.Name.SPECIFICATION_VENDOR);
|
||||
String implTitle =
|
||||
attr.getValue(Attributes.Name.IMPLEMENTATION_TITLE);
|
||||
String implVersion =
|
||||
attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
|
||||
String implVendor =
|
||||
attr.getValue(Attributes.Name.IMPLEMENTATION_VENDOR);
|
||||
String specTitle = attr.getValue(Attributes.Name.SPECIFICATION_TITLE);
|
||||
String specVersion = attr.getValue(Attributes.Name.SPECIFICATION_VERSION);
|
||||
String specVendor = attr.getValue(Attributes.Name.SPECIFICATION_VENDOR);
|
||||
String implTitle = attr.getValue(Attributes.Name.IMPLEMENTATION_TITLE);
|
||||
String implVersion = attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
|
||||
String implVendor = attr.getValue(Attributes.Name.IMPLEMENTATION_VENDOR);
|
||||
|
||||
// Look if the Manifest indicates that this package is sealed
|
||||
// XXX - most likely not completely correct!
|
||||
@ -813,13 +807,11 @@ public class URLClassLoader extends SecureClassLoader
|
||||
// But how do we get that jar manifest here?
|
||||
String sealed = attr.getValue(Attributes.Name.SEALED);
|
||||
if ("false".equals(sealed))
|
||||
{
|
||||
// make sure that the URL is null so the package is not sealed
|
||||
url = null;
|
||||
}
|
||||
|
||||
return definePackage(name, specTitle, specVersion, specVendor,
|
||||
implTitle, implVersion, implVendor, url);
|
||||
return definePackage(name, specTitle, specVersion, specVendor, implTitle,
|
||||
implVersion, implVendor, url);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -857,7 +849,7 @@ public class URLClassLoader extends SecureClassLoader
|
||||
// construct the class (and watch out for those nasty IOExceptions)
|
||||
try
|
||||
{
|
||||
byte [] data;
|
||||
byte[] data;
|
||||
InputStream in = resource.getInputStream();
|
||||
int length = resource.getLength();
|
||||
if (length != -1)
|
||||
@ -894,24 +886,24 @@ public class URLClassLoader extends SecureClassLoader
|
||||
|
||||
// Now get the CodeSource
|
||||
final CodeSource source = resource.getCodeSource();
|
||||
|
||||
|
||||
// Find out package name
|
||||
String packageName = null;
|
||||
int lastDot = className.lastIndexOf('.');
|
||||
if (lastDot != -1)
|
||||
packageName = className.substring(0, lastDot);
|
||||
|
||||
|
||||
if (packageName != null && getPackage(packageName) == null)
|
||||
{
|
||||
// define the package
|
||||
Manifest manifest = resource.loader.getManifest();
|
||||
if (manifest == null)
|
||||
definePackage(packageName,
|
||||
null, null, null, null, null, null, null);
|
||||
definePackage(packageName, null, null, null, null, null, null,
|
||||
null);
|
||||
else
|
||||
definePackage(packageName, manifest, resource.loader.baseURL);
|
||||
}
|
||||
|
||||
|
||||
// And finally construct the class!
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null && securityContext != null)
|
||||
@ -928,9 +920,7 @@ public class URLClassLoader extends SecureClassLoader
|
||||
}, securityContext);
|
||||
}
|
||||
else
|
||||
return defineClass(className, classData,
|
||||
0, classData.length,
|
||||
source);
|
||||
return defineClass(className, classData, 0, classData.length, source);
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
@ -950,10 +940,10 @@ public class URLClassLoader extends SecureClassLoader
|
||||
int max = urls.size();
|
||||
for (int i = 0; i < max; i++)
|
||||
{
|
||||
URLLoader loader = (URLLoader)urlinfos.elementAt(i);
|
||||
URLLoader loader = (URLLoader) urlinfos.elementAt(i);
|
||||
if (loader == null)
|
||||
continue;
|
||||
|
||||
|
||||
Resource resource = loader.getResource(resourceName);
|
||||
if (resource != null)
|
||||
return resource;
|
||||
@ -972,7 +962,7 @@ public class URLClassLoader extends SecureClassLoader
|
||||
Resource resource = findURLResource(resourceName);
|
||||
if (resource != null)
|
||||
return resource.getURL();
|
||||
|
||||
|
||||
// Resource not found
|
||||
return null;
|
||||
}
|
||||
@ -993,9 +983,9 @@ public class URLClassLoader extends SecureClassLoader
|
||||
synchronized (factoryCache)
|
||||
{
|
||||
// Check if there're handler for the same protocol in cache.
|
||||
HashMap cache = (HashMap)factoryCache.get(factory);
|
||||
handler = (URLStreamHandler)cache.get(protocol);
|
||||
if(handler == null)
|
||||
HashMap cache = (HashMap) factoryCache.get(factory);
|
||||
handler = (URLStreamHandler) cache.get(protocol);
|
||||
if (handler == null)
|
||||
{
|
||||
// Add it to cache.
|
||||
handler = factory.createURLStreamHandler(protocol);
|
||||
@ -1014,13 +1004,14 @@ public class URLClassLoader extends SecureClassLoader
|
||||
* @return a (possible empty) enumeration of URLs where the resource can be
|
||||
* found
|
||||
*/
|
||||
public Enumeration findResources(String resourceName) throws IOException
|
||||
public Enumeration findResources(String resourceName)
|
||||
throws IOException
|
||||
{
|
||||
Vector resources = new Vector();
|
||||
int max = urls.size();
|
||||
for (int i = 0; i < max; i++)
|
||||
{
|
||||
URLLoader loader = (URLLoader)urlinfos.elementAt(i);
|
||||
URLLoader loader = (URLLoader) urlinfos.elementAt(i);
|
||||
Resource resource = loader.getResource(resourceName);
|
||||
if (resource != null)
|
||||
resources.add(resource.getURL());
|
||||
@ -1052,16 +1043,16 @@ public class URLClassLoader extends SecureClassLoader
|
||||
{
|
||||
// XXX - This implementation does exactly as the Javadoc describes.
|
||||
// But maybe we should/could use URLConnection.getPermissions()?
|
||||
|
||||
// First get the permissions that would normally be granted
|
||||
PermissionCollection permissions = super.getPermissions(source);
|
||||
|
||||
|
||||
// Now add any extra permissions depending on the URL location.
|
||||
URL url = source.getLocation();
|
||||
String protocol = url.getProtocol();
|
||||
if (protocol.equals("file"))
|
||||
{
|
||||
String file = url.getFile();
|
||||
|
||||
// If the file end in / it must be an directory.
|
||||
if (file.endsWith("/") || file.endsWith(File.separator))
|
||||
{
|
||||
@ -1086,7 +1077,7 @@ public class URLClassLoader extends SecureClassLoader
|
||||
|
||||
return permissions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all the locations that this class loader currently uses the
|
||||
* resolve classes and resource. This includes both the initially supplied
|
||||
@ -1109,7 +1100,7 @@ public class URLClassLoader extends SecureClassLoader
|
||||
* @exception SecurityException when the calling code does not have
|
||||
* permission to access the given <code>URL</code>s
|
||||
*/
|
||||
public static URLClassLoader newInstance(URL urls[])
|
||||
public static URLClassLoader newInstance(URL[] urls)
|
||||
throws SecurityException
|
||||
{
|
||||
return newInstance(urls, null);
|
||||
@ -1127,8 +1118,7 @@ public class URLClassLoader extends SecureClassLoader
|
||||
* @exception SecurityException when the calling code does not have
|
||||
* permission to access the given <code>URL</code>s
|
||||
*/
|
||||
public static URLClassLoader newInstance(URL urls[],
|
||||
final ClassLoader parent)
|
||||
public static URLClassLoader newInstance(URL[] urls, final ClassLoader parent)
|
||||
throws SecurityException
|
||||
{
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
@ -1137,21 +1127,21 @@ public class URLClassLoader extends SecureClassLoader
|
||||
else
|
||||
{
|
||||
final Object securityContext = sm.getSecurityContext();
|
||||
|
||||
// XXX - What to do with anything else then an AccessControlContext?
|
||||
if (!(securityContext instanceof AccessControlContext))
|
||||
throw new SecurityException
|
||||
("securityContext must be AccessControlContext: "
|
||||
+ securityContext);
|
||||
|
||||
if (! (securityContext instanceof AccessControlContext))
|
||||
throw new SecurityException("securityContext must be AccessControlContext: "
|
||||
+ securityContext);
|
||||
|
||||
URLClassLoader loader =
|
||||
(URLClassLoader)AccessController.doPrivileged(new PrivilegedAction()
|
||||
{
|
||||
public Object run()
|
||||
(URLClassLoader) AccessController.doPrivileged(new PrivilegedAction()
|
||||
{
|
||||
return new URLClassLoader
|
||||
(parent, (AccessControlContext)securityContext);
|
||||
}
|
||||
});
|
||||
public Object run()
|
||||
{
|
||||
return new URLClassLoader(parent,
|
||||
(AccessControlContext) securityContext);
|
||||
}
|
||||
});
|
||||
loader.addURLs(urls);
|
||||
return loader;
|
||||
}
|
||||
|
@ -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,10 @@ this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.net;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.security.AllPermission;
|
||||
import java.security.Permission;
|
||||
@ -53,13 +52,13 @@ import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
import gnu.gcj.io.MimeTypes;
|
||||
|
||||
|
||||
/**
|
||||
* Written using on-line Java Platform 1.2 API Specification, as well
|
||||
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
|
||||
* Status: One guessContentTypeFrom... methods not implemented.
|
||||
* getContent method assumes content type from response; see comment there.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class models a connection that retrieves the information pointed
|
||||
* to by a URL object. This is typically a connection to a remote node
|
||||
@ -99,18 +98,18 @@ public abstract class URLConnection
|
||||
* instance and store it here.
|
||||
*/
|
||||
private static FileNameMap fileNameMap;
|
||||
|
||||
|
||||
/**
|
||||
* This is the ContentHandlerFactory set by the caller, if any
|
||||
*/
|
||||
private static ContentHandlerFactory factory;
|
||||
|
||||
|
||||
/**
|
||||
* This is the default value that will be used to determine whether or
|
||||
* not user interaction should be allowed.
|
||||
*/
|
||||
private static boolean defaultAllowUserInteraction = false;
|
||||
|
||||
|
||||
/**
|
||||
* This is the default flag indicating whether or not to use caches to
|
||||
* store the data returned from a server
|
||||
@ -128,17 +127,17 @@ public abstract class URLConnection
|
||||
* destination specified in the URL
|
||||
*/
|
||||
protected boolean connected = false;
|
||||
|
||||
|
||||
/**
|
||||
* Indicates whether or not input can be read from this URL
|
||||
*/
|
||||
protected boolean doInput = true;
|
||||
|
||||
|
||||
/**
|
||||
* Indicates whether or not output can be sent to this URL
|
||||
*/
|
||||
protected boolean doOutput = false;
|
||||
|
||||
|
||||
/**
|
||||
* If this flag is set, the protocol is allowed to cache data whenever
|
||||
* it can (caching is not guaranteed). If it is not set, the protocol
|
||||
@ -188,6 +187,8 @@ public abstract class URLConnection
|
||||
/**
|
||||
* Establishes the actual connection to the URL associated with this
|
||||
* connection object
|
||||
*
|
||||
* @exception IOException if an error occurs
|
||||
*/
|
||||
public abstract void connect() throws IOException;
|
||||
|
||||
@ -230,7 +231,7 @@ public abstract class URLConnection
|
||||
/**
|
||||
* Returns the value of the content-encoding field or null if it is not
|
||||
* known or not present.
|
||||
*
|
||||
*
|
||||
* @return The content-encoding field
|
||||
*/
|
||||
public String getContentEncoding()
|
||||
@ -295,7 +296,7 @@ public abstract class URLConnection
|
||||
* Returns a String representing the value of the header field having
|
||||
* the named key. Returns null if the header field does not exist.
|
||||
*
|
||||
* @param The key of the header field
|
||||
* @param name The key of the header field
|
||||
*
|
||||
* @return The value of the header field as a String
|
||||
*/
|
||||
@ -307,7 +308,9 @@ public abstract class URLConnection
|
||||
|
||||
/**
|
||||
* Returns a map of all sent header fields
|
||||
*
|
||||
*
|
||||
* @return all header fields
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public Map getHeaderFields()
|
||||
@ -330,18 +333,18 @@ public abstract class URLConnection
|
||||
*/
|
||||
public int getHeaderFieldInt(String name, int defaultValue)
|
||||
{
|
||||
String value = getHeaderField (name);
|
||||
|
||||
String value = getHeaderField(name);
|
||||
|
||||
if (value == null)
|
||||
return defaultValue;
|
||||
|
||||
try
|
||||
{
|
||||
return Integer.parseInt (value);
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
return defaultValue;
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
@ -357,25 +360,25 @@ public abstract class URLConnection
|
||||
* @return Returns the date value of the header filed or the default value
|
||||
* if the field is missing or malformed
|
||||
*/
|
||||
public long getHeaderFieldDate (String name, long defaultValue)
|
||||
public long getHeaderFieldDate(String name, long defaultValue)
|
||||
{
|
||||
if (! dateformats_initialized)
|
||||
initializeDateFormats ();
|
||||
|
||||
initializeDateFormats();
|
||||
|
||||
long result = defaultValue;
|
||||
String str = getHeaderField (name);
|
||||
|
||||
String str = getHeaderField(name);
|
||||
|
||||
if (str != null)
|
||||
{
|
||||
Date date;
|
||||
if ((date = dateFormat1.parse (str, new ParsePosition (0))) != null)
|
||||
result = date.getTime ();
|
||||
else if ((date = dateFormat2.parse (str, new ParsePosition (0))) != null)
|
||||
result = date.getTime ();
|
||||
else if ((date = dateFormat3.parse (str, new ParsePosition (0))) != null)
|
||||
result = date.getTime ();
|
||||
if ((date = dateFormat1.parse(str, new ParsePosition(0))) != null)
|
||||
result = date.getTime();
|
||||
else if ((date = dateFormat2.parse(str, new ParsePosition(0))) != null)
|
||||
result = date.getTime();
|
||||
else if ((date = dateFormat3.parse(str, new ParsePosition(0))) != null)
|
||||
result = date.getTime();
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -385,12 +388,12 @@ public abstract class URLConnection
|
||||
* getHeaderField(int) method allows access to the corresponding value for
|
||||
* this tag.
|
||||
*
|
||||
* @param index The index into the header field list to retrieve the key for.
|
||||
* @param index The index into the header field list to retrieve the key for.
|
||||
*
|
||||
* @return The header field key or null if index is past the end
|
||||
* of the headers.
|
||||
*/
|
||||
public String getHeaderFieldKey (int index)
|
||||
public String getHeaderFieldKey(int index)
|
||||
{
|
||||
// Subclasses for specific protocols override this.
|
||||
return null;
|
||||
@ -407,7 +410,7 @@ public abstract class URLConnection
|
||||
* This class first determines the MIME type of the content, then creates
|
||||
* a ContentHandler object to process the input. If the ContentHandlerFactory
|
||||
* is set, then that object is called to load a content handler, otherwise
|
||||
* a class called gnu.java.net.content.<content_type> is tried.
|
||||
* a class called gnu.java.net.content.<content_type> is tried.
|
||||
* The default class will also be used if the content handler factory returns
|
||||
* a null content handler.
|
||||
*
|
||||
@ -436,6 +439,8 @@ public abstract class URLConnection
|
||||
/**
|
||||
* Retrieves the content of this URLConnection
|
||||
*
|
||||
* @param classes The allowed classes for the content
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
* @exception UnknownServiceException If the protocol does not support the
|
||||
* content type
|
||||
@ -443,7 +448,7 @@ public abstract class URLConnection
|
||||
public Object getContent(Class[] classes) throws IOException
|
||||
{
|
||||
// FIXME: implement this
|
||||
return getContent ();
|
||||
return getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -480,8 +485,8 @@ public abstract class URLConnection
|
||||
public InputStream getInputStream() throws IOException
|
||||
{
|
||||
// Subclasses for specific protocols override this.
|
||||
throw new UnknownServiceException("Protocol " + url.getProtocol() +
|
||||
" does not support input.");
|
||||
throw new UnknownServiceException("Protocol " + url.getProtocol()
|
||||
+ " does not support input.");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -496,14 +501,14 @@ public abstract class URLConnection
|
||||
public OutputStream getOutputStream() throws IOException
|
||||
{
|
||||
// Subclasses for specific protocols override this.
|
||||
throw new UnknownServiceException("Protocol " + url.getProtocol() +
|
||||
" does not support output.");
|
||||
throw new UnknownServiceException("Protocol " + url.getProtocol()
|
||||
+ " does not support output.");
|
||||
}
|
||||
|
||||
/**
|
||||
* The methods prints the value of this object as a String by calling the
|
||||
* toString() method of its associated URL. Overrides Object.toString()
|
||||
*
|
||||
*
|
||||
* @return A String representation of this object
|
||||
*/
|
||||
public String toString()
|
||||
@ -515,7 +520,7 @@ public abstract class URLConnection
|
||||
* Returns the value of a flag indicating whether or not input is going
|
||||
* to be done for this connection. This default to true unless the
|
||||
* doOutput flag is set to false, in which case this defaults to false.
|
||||
*
|
||||
*
|
||||
* @param input <code>true</code> if input is to be done,
|
||||
* <code>false</code> otherwise
|
||||
*
|
||||
@ -524,7 +529,7 @@ public abstract class URLConnection
|
||||
public void setDoInput(boolean input)
|
||||
{
|
||||
if (connected)
|
||||
throw new IllegalStateException ("Already connected");
|
||||
throw new IllegalStateException("Already connected");
|
||||
|
||||
doInput = input;
|
||||
}
|
||||
@ -553,7 +558,7 @@ public abstract class URLConnection
|
||||
public void setDoOutput(boolean output)
|
||||
{
|
||||
if (connected)
|
||||
throw new IllegalStateException ("Already connected");
|
||||
throw new IllegalStateException("Already connected");
|
||||
|
||||
doOutput = output;
|
||||
}
|
||||
@ -628,7 +633,7 @@ public abstract class URLConnection
|
||||
public void setUseCaches(boolean usecaches)
|
||||
{
|
||||
if (connected)
|
||||
throw new IllegalStateException ("Already connected");
|
||||
throw new IllegalStateException("Already connected");
|
||||
|
||||
useCaches = usecaches;
|
||||
}
|
||||
@ -659,7 +664,7 @@ public abstract class URLConnection
|
||||
public void setIfModifiedSince(long ifmodifiedsince)
|
||||
{
|
||||
if (connected)
|
||||
throw new IllegalStateException ("Already connected");
|
||||
throw new IllegalStateException("Already connected");
|
||||
|
||||
ifModifiedSince = ifmodifiedsince;
|
||||
}
|
||||
@ -695,9 +700,9 @@ public abstract class URLConnection
|
||||
*
|
||||
* @param use true to use caches if possible by default, false otherwise
|
||||
*/
|
||||
public void setDefaultUseCaches(boolean defaultusecaches)
|
||||
public void setDefaultUseCaches(boolean use)
|
||||
{
|
||||
defaultUseCaches = defaultusecaches;
|
||||
defaultUseCaches = use;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -705,23 +710,23 @@ public abstract class URLConnection
|
||||
*
|
||||
* @param key The name of the property
|
||||
* @param value The value of the property
|
||||
*
|
||||
*
|
||||
* @exception IllegalStateException If already connected
|
||||
* @exception NullPointerException If key is null
|
||||
*
|
||||
* @see URLConnection#getRequestProperty(String key)
|
||||
* @see URLConnection#addRequestProperty(String key, String value)
|
||||
*
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public void setRequestProperty(String key, String value)
|
||||
{
|
||||
if (connected)
|
||||
throw new IllegalStateException ("Already connected");
|
||||
throw new IllegalStateException("Already connected");
|
||||
|
||||
if (key == null)
|
||||
throw new NullPointerException ("key is null");
|
||||
|
||||
throw new NullPointerException("key is null");
|
||||
|
||||
// Do nothing unless overridden by subclasses that support setting
|
||||
// header fields in the request.
|
||||
}
|
||||
@ -735,20 +740,20 @@ public abstract class URLConnection
|
||||
*
|
||||
* @exception IllegalStateException If already connected
|
||||
* @exception NullPointerException If key is null
|
||||
*
|
||||
*
|
||||
* @see URLConnection#getRequestProperty(String key)
|
||||
* @see URLConnection#setRequestProperty(String key, String value)
|
||||
*
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public void addRequestProperty(String key, String value)
|
||||
{
|
||||
if (connected)
|
||||
throw new IllegalStateException ("Already connected");
|
||||
throw new IllegalStateException("Already connected");
|
||||
|
||||
if (key == null)
|
||||
throw new NullPointerException ("key is null");
|
||||
|
||||
throw new NullPointerException("key is null");
|
||||
|
||||
// Do nothing unless overridden by subclasses that support adding
|
||||
// header fields in the request.
|
||||
}
|
||||
@ -768,7 +773,7 @@ public abstract class URLConnection
|
||||
public String getRequestProperty(String key)
|
||||
{
|
||||
if (connected)
|
||||
throw new IllegalStateException ("Already connected");
|
||||
throw new IllegalStateException("Already connected");
|
||||
|
||||
// Overridden by subclasses that support reading header fields from the
|
||||
// request.
|
||||
@ -787,7 +792,7 @@ public abstract class URLConnection
|
||||
public Map getRequestProperties()
|
||||
{
|
||||
if (connected)
|
||||
throw new IllegalStateException ("Already connected");
|
||||
throw new IllegalStateException("Already connected");
|
||||
|
||||
// Overridden by subclasses that support reading header fields from the
|
||||
// request.
|
||||
@ -807,7 +812,7 @@ public abstract class URLConnection
|
||||
*
|
||||
* @see URLConnection#setRequestProperty(String key, String value)
|
||||
*/
|
||||
public static void setDefaultRequestProperty (String key, String value)
|
||||
public static void setDefaultRequestProperty(String key, String value)
|
||||
{
|
||||
// This method does nothing since JDK 1.3.
|
||||
}
|
||||
@ -820,7 +825,7 @@ public abstract class URLConnection
|
||||
* @param key The request property to return the default value of
|
||||
*
|
||||
* @return The value of the default property or null if not available
|
||||
*
|
||||
*
|
||||
* @deprecated 1.3 The method getRequestProperty should be used instead.
|
||||
* This method does nothing now.
|
||||
*
|
||||
@ -844,10 +849,9 @@ public abstract class URLConnection
|
||||
* @exception SecurityException If a security manager exists and its
|
||||
* checkSetFactory method doesn't allow the operation
|
||||
*/
|
||||
public static synchronized void setContentHandlerFactory
|
||||
(ContentHandlerFactory fac)
|
||||
public static synchronized void setContentHandlerFactory(ContentHandlerFactory factory)
|
||||
{
|
||||
if (factory != null)
|
||||
if (URLConnection.factory != null)
|
||||
throw new Error("ContentHandlerFactory already set");
|
||||
|
||||
// Throw an exception if an extant security mgr precludes
|
||||
@ -856,7 +860,7 @@ public abstract class URLConnection
|
||||
if (s != null)
|
||||
s.checkSetFactory();
|
||||
|
||||
factory = fac;
|
||||
URLConnection.factory = factory;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -895,7 +899,7 @@ public abstract class URLConnection
|
||||
* Returns the MIME type of a stream based on the first few characters
|
||||
* at the beginning of the stream. This routine can be used to determine
|
||||
* the MIME type if a server is believed to be returning an incorrect
|
||||
* MIME type. This method returns "application/octet-stream" if it
|
||||
* MIME type. This method returns "application/octet-stream" if it
|
||||
* cannot determine the MIME type.
|
||||
* <p>
|
||||
* NOTE: Overriding MIME types sent from the server can be obnoxious
|
||||
@ -937,7 +941,7 @@ public abstract class URLConnection
|
||||
*
|
||||
* @exception SecurityException If a security manager exists and its
|
||||
* checkSetFactory method doesn't allow the operation
|
||||
*
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
public static void setFileNameMap(FileNameMap map)
|
||||
@ -1040,10 +1044,10 @@ public abstract class URLConnection
|
||||
return;
|
||||
|
||||
Locale locale = new Locale("En", "Us", "Unix");
|
||||
dateFormat1 = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'",
|
||||
locale);
|
||||
dateFormat2 = new SimpleDateFormat("EEEE, dd-MMM-yy hh:mm:ss 'GMT'",
|
||||
locale);
|
||||
dateFormat1 =
|
||||
new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'", locale);
|
||||
dateFormat2 =
|
||||
new SimpleDateFormat("EEEE, dd-MMM-yy hh:mm:ss 'GMT'", locale);
|
||||
dateFormat3 = new SimpleDateFormat("EEE MMM d hh:mm:ss yyyy", locale);
|
||||
dateformats_initialized = true;
|
||||
}
|
||||
|
@ -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
|
||||
@ -39,8 +39,9 @@ package java.net;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
|
||||
/**
|
||||
* This utility class contains static methods that converts a
|
||||
* This utility class contains static methods that converts a
|
||||
* string encoded in the x-www-form-urlencoded format to the original
|
||||
* text. The x-www-form-urlencoded format replaces certain disallowed
|
||||
* characters with encoded equivalents. All upper case and lower case
|
||||
@ -65,7 +66,7 @@ public class URLDecoder
|
||||
/**
|
||||
* Public contructor. Note that this class has only static methods.
|
||||
*/
|
||||
public URLDecoder ()
|
||||
public URLDecoder()
|
||||
{
|
||||
}
|
||||
|
||||
@ -84,12 +85,12 @@ public class URLDecoder
|
||||
{
|
||||
try
|
||||
{
|
||||
return decode(s, "UTF-8");
|
||||
return decode(s, "UTF-8");
|
||||
}
|
||||
catch (UnsupportedEncodingException uee)
|
||||
{
|
||||
// Should never happen since UTF-8 encoding should always be supported
|
||||
return s;
|
||||
// Should never happen since UTF-8 encoding should always be supported
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,7 +121,7 @@ public class URLDecoder
|
||||
{
|
||||
// First convert all '+' characters to spaces.
|
||||
String str = s.replace('+', ' ');
|
||||
|
||||
|
||||
// Then go through the whole string looking for byte encoded characters
|
||||
int i;
|
||||
int start = 0;
|
||||
@ -134,12 +135,12 @@ public class URLDecoder
|
||||
start = i;
|
||||
|
||||
// Get all consecutive encoded bytes
|
||||
while ((i+2 < length) && (str.charAt(i) == '%'))
|
||||
while ((i + 2 < length) && (str.charAt(i) == '%'))
|
||||
i += 3;
|
||||
|
||||
// Decode all these bytes
|
||||
if ((bytes == null) || (bytes.length < ((i-start)/3)))
|
||||
bytes = new byte[((i-start)/3)];
|
||||
if ((bytes == null) || (bytes.length < ((i - start) / 3)))
|
||||
bytes = new byte[((i - start) / 3)];
|
||||
|
||||
int index = 0;
|
||||
try
|
||||
@ -147,7 +148,7 @@ public class URLDecoder
|
||||
while (start < i)
|
||||
{
|
||||
String sub = str.substring(start + 1, start + 3);
|
||||
bytes[index] = (byte)Integer.parseInt(sub, 16);
|
||||
bytes[index] = (byte) Integer.parseInt(sub, 16);
|
||||
index++;
|
||||
start += 3;
|
||||
}
|
||||
@ -176,5 +177,4 @@ public class URLDecoder
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
} // class URLDecoder
|
||||
|
@ -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
|
||||
@ -39,29 +39,30 @@ package java.net;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
|
||||
/*
|
||||
* Written using on-line Java Platform 1.2/1.4 API Specification, as well
|
||||
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
|
||||
* Status: Believed complete and correct.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This utility class contains static methods that converts a
|
||||
* string into a fully encoded URL string in x-www-form-urlencoded
|
||||
* format. This format replaces certain disallowed characters with
|
||||
* encoded equivalents. All upper case and lower case letters in the
|
||||
* US alphabet remain as is, the space character (' ') is replaced with
|
||||
* '+' sign, and all other characters are converted to a "%XX" format
|
||||
* where XX is the hexadecimal representation of that character in a
|
||||
* certain encoding (by default, the platform encoding, though the
|
||||
* standard is "UTF-8").
|
||||
* <p>
|
||||
* This method is very useful for encoding strings to be sent to CGI scripts
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Warren Levy <warrenl@cygnus.com>
|
||||
* @author Mark Wielaard (mark@klomp.org)
|
||||
*/
|
||||
/**
|
||||
* This utility class contains static methods that converts a
|
||||
* string into a fully encoded URL string in x-www-form-urlencoded
|
||||
* format. This format replaces certain disallowed characters with
|
||||
* encoded equivalents. All upper case and lower case letters in the
|
||||
* US alphabet remain as is, the space character (' ') is replaced with
|
||||
* '+' sign, and all other characters are converted to a "%XX" format
|
||||
* where XX is the hexadecimal representation of that character in a
|
||||
* certain encoding (by default, the platform encoding, though the
|
||||
* standard is "UTF-8").
|
||||
* <p>
|
||||
* This method is very useful for encoding strings to be sent to CGI scripts
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Warren Levy <warrenl@cygnus.com>
|
||||
* @author Mark Wielaard (mark@klomp.org)
|
||||
*/
|
||||
public class URLEncoder
|
||||
{
|
||||
/**
|
||||
@ -82,11 +83,11 @@ public class URLEncoder
|
||||
{
|
||||
// We default to 8859_1 for compatibility with the same
|
||||
// default elsewhere in the library.
|
||||
return encode(s, System.getProperty("file.encoding", "8859_1"));
|
||||
return encode(s, System.getProperty("file.encoding", "8859_1"));
|
||||
}
|
||||
catch (UnsupportedEncodingException uee)
|
||||
{
|
||||
// Should never happen since default should always be supported
|
||||
// Should never happen since default should always be supported
|
||||
return s;
|
||||
}
|
||||
}
|
||||
@ -114,42 +115,42 @@ public class URLEncoder
|
||||
|
||||
StringBuffer result = new StringBuffer(length);
|
||||
while (true)
|
||||
{
|
||||
while ( i < length && isSafe(s.charAt(i)) )
|
||||
i++;
|
||||
|
||||
// Safe character can just be added
|
||||
result.append(s.substring(start, i));
|
||||
|
||||
// Are we done?
|
||||
if (i >= length)
|
||||
return result.toString();
|
||||
else if (s.charAt(i) == ' ')
|
||||
{
|
||||
result.append('+'); // Replace space char with plus symbol.
|
||||
{
|
||||
while (i < length && isSafe(s.charAt(i)))
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get all unsafe characters
|
||||
start = i;
|
||||
char c;
|
||||
while ( i < length && (c = s.charAt(i)) != ' ' && !isSafe(c) )
|
||||
i++;
|
||||
|
||||
// Convert them to %XY encoded strings
|
||||
String unsafe = s.substring(start,i);
|
||||
byte bytes[] = unsafe.getBytes(encoding);
|
||||
for (int j = 0; j < bytes.length; j++)
|
||||
{
|
||||
result.append('%');
|
||||
int val = bytes[j];
|
||||
result.append(hex.charAt((val & 0xf0) >> 4));
|
||||
result.append(hex.charAt(val & 0x0f));
|
||||
}
|
||||
}
|
||||
start = i;
|
||||
}
|
||||
// Safe character can just be added
|
||||
result.append(s.substring(start, i));
|
||||
|
||||
// Are we done?
|
||||
if (i >= length)
|
||||
return result.toString();
|
||||
else if (s.charAt(i) == ' ')
|
||||
{
|
||||
result.append('+'); // Replace space char with plus symbol.
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get all unsafe characters
|
||||
start = i;
|
||||
char c;
|
||||
while (i < length && (c = s.charAt(i)) != ' ' && ! isSafe(c))
|
||||
i++;
|
||||
|
||||
// Convert them to %XY encoded strings
|
||||
String unsafe = s.substring(start, i);
|
||||
byte[] bytes = unsafe.getBytes(encoding);
|
||||
for (int j = 0; j < bytes.length; j++)
|
||||
{
|
||||
result.append('%');
|
||||
int val = bytes[j];
|
||||
result.append(hex.charAt((val & 0xf0) >> 4));
|
||||
result.append(hex.charAt(val & 0x0f));
|
||||
}
|
||||
}
|
||||
start = i;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -160,17 +161,18 @@ public class URLEncoder
|
||||
*/
|
||||
private static boolean isSafe(char c)
|
||||
{
|
||||
return ((c >= 'a' && c <= 'z') ||
|
||||
(c >= 'A' && c <= 'Z') ||
|
||||
(c >= '0' && c <= '9') ||
|
||||
c == '-' || c == '_' || c == '.' || c == '*');
|
||||
return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
|
||||
|| (c >= '0' && c <= '9') || c == '-' || c == '_' || c == '.'
|
||||
|| c == '*');
|
||||
}
|
||||
|
||||
/**
|
||||
* Private constructor that does nothing. Included to avoid a default
|
||||
* public constructor being created by the compiler.
|
||||
*/
|
||||
private URLEncoder() { }
|
||||
private URLEncoder()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to convert to hex. We don't use Integer.toHexString, since
|
||||
@ -179,4 +181,4 @@ public class URLEncoder
|
||||
* leading 0.
|
||||
*/
|
||||
private static final String hex = "0123456789ABCDEF";
|
||||
} // class URLEncoder
|
||||
}
|
||||
|
@ -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.io.IOException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/*
|
||||
* Written using on-line Java Platform 1.2 API Specification, as well
|
||||
@ -57,7 +57,7 @@ import java.io.File;
|
||||
* A protocol handler implementation should override the openConnection()
|
||||
* method, and optionally override the parseURL() and toExternalForm()
|
||||
* methods if necessary. (The default implementations will parse/write all
|
||||
* URL's in the same form as http URL's). A protocol specific subclass
|
||||
* URL's in the same form as http URL's). A protocol specific subclass
|
||||
* of URLConnection will most likely need to be created as well.
|
||||
* <p>
|
||||
* Note that the instance methods in this class are called as if they
|
||||
@ -71,7 +71,7 @@ import java.io.File;
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Warren Levy (warrenl@cygnus.com)
|
||||
*
|
||||
*
|
||||
* @see URL
|
||||
*/
|
||||
public abstract class URLStreamHandler
|
||||
@ -79,7 +79,7 @@ public abstract class URLStreamHandler
|
||||
/**
|
||||
* Creates a URLStreamHander
|
||||
*/
|
||||
public URLStreamHandler ()
|
||||
public URLStreamHandler()
|
||||
{
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ public abstract class URLStreamHandler
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
protected abstract URLConnection openConnection(URL u)
|
||||
protected abstract URLConnection openConnection(URL url)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
@ -109,8 +109,8 @@ public abstract class URLStreamHandler
|
||||
* position of the "#" character, which separates the "file" portion of
|
||||
* the URL from the "anchor" portion.
|
||||
* <p>
|
||||
* This method assumes URL's are formatted like http protocol URL's, so
|
||||
* subclasses that implement protocols with URL's the follow a different
|
||||
* This method assumes URL's are formatted like http protocol URL's, so
|
||||
* subclasses that implement protocols with URL's the follow a different
|
||||
* syntax should override this method. The lone exception is that if
|
||||
* the protocol name set in the URL is "file", this method will accept
|
||||
* an empty hostname (i.e., "file:///"), which is legal for that protocol
|
||||
@ -126,28 +126,29 @@ public abstract class URLStreamHandler
|
||||
int port = url.getPort();
|
||||
String file = url.getFile();
|
||||
String ref = url.getRef();
|
||||
|
||||
if (spec.regionMatches (start, "//", 0, 2))
|
||||
|
||||
if (spec.regionMatches(start, "//", 0, 2))
|
||||
{
|
||||
String genuineHost;
|
||||
int hostEnd;
|
||||
int colon, at_host;
|
||||
int colon;
|
||||
int at_host;
|
||||
|
||||
start += 2;
|
||||
int slash = spec.indexOf ('/', start);
|
||||
if (slash >= 0)
|
||||
int slash = spec.indexOf('/', start);
|
||||
if (slash >= 0)
|
||||
hostEnd = slash;
|
||||
else
|
||||
else
|
||||
hostEnd = end;
|
||||
|
||||
host = spec.substring (start, hostEnd);
|
||||
|
||||
host = spec.substring(start, hostEnd);
|
||||
|
||||
// We first need a genuine host name (with userinfo).
|
||||
// So we check for '@': if it's present check the port in the
|
||||
// section after '@' in the other case check it in the full string.
|
||||
// P.S.: We don't care having '@' at the beginning of the string.
|
||||
if ((at_host = host.indexOf ('@')) >= 0)
|
||||
genuineHost = host.substring (at_host);
|
||||
if ((at_host = host.indexOf('@')) >= 0)
|
||||
genuineHost = host.substring(at_host);
|
||||
else
|
||||
genuineHost = host;
|
||||
|
||||
@ -157,70 +158,70 @@ public abstract class URLStreamHandler
|
||||
// this is undocumented and likely an unintended side effect in 1.2
|
||||
// so we'll be simple here and stick with "". Note that
|
||||
// "http://" or "http:///" produce a "" host in JDK 1.2.
|
||||
if ((colon = genuineHost.indexOf (':')) >= 0)
|
||||
if ((colon = genuineHost.indexOf(':')) >= 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
port = Integer.parseInt (genuineHost.substring (colon + 1));
|
||||
port = Integer.parseInt(genuineHost.substring(colon + 1));
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
; // Ignore invalid port values; port is already set to u's
|
||||
// port.
|
||||
}
|
||||
|
||||
// Now we must cut the port number in the original string.
|
||||
if (at_host >= 0)
|
||||
host = host.substring (0, at_host + colon);
|
||||
host = host.substring(0, at_host + colon);
|
||||
else
|
||||
host = host.substring (0, colon);
|
||||
host = host.substring(0, colon);
|
||||
}
|
||||
file = null;
|
||||
start = hostEnd;
|
||||
}
|
||||
else if (host == null)
|
||||
}
|
||||
else if (host == null)
|
||||
host = "";
|
||||
|
||||
if (file == null || file.length() == 0
|
||||
|| (start < end && spec.charAt(start) == '/'))
|
||||
|| (start < end && spec.charAt(start) == '/'))
|
||||
{
|
||||
// No file context available; just spec for file.
|
||||
// Or this is an absolute path name; ignore any file context.
|
||||
file = spec.substring(start, end);
|
||||
ref = null;
|
||||
}
|
||||
}
|
||||
else if (start < end)
|
||||
{
|
||||
// Context is available, but only override it if there is a new file.
|
||||
char sepChar = '/';
|
||||
int lastSlash = file.lastIndexOf (sepChar);
|
||||
if (lastSlash < 0 && File.separatorChar != sepChar
|
||||
&& url.getProtocol ().equals ("file"))
|
||||
{
|
||||
// On Windows, even '\' is allowed in a "file" URL.
|
||||
sepChar = File.separatorChar;
|
||||
lastSlash = file.lastIndexOf (sepChar);
|
||||
}
|
||||
|
||||
file = file.substring(0, lastSlash)
|
||||
+ sepChar + spec.substring (start, end);
|
||||
// Context is available, but only override it if there is a new file.
|
||||
char sepChar = '/';
|
||||
int lastSlash = file.lastIndexOf(sepChar);
|
||||
if (lastSlash < 0 && File.separatorChar != sepChar
|
||||
&& url.getProtocol().equals("file"))
|
||||
{
|
||||
// On Windows, even '\' is allowed in a "file" URL.
|
||||
sepChar = File.separatorChar;
|
||||
lastSlash = file.lastIndexOf(sepChar);
|
||||
}
|
||||
|
||||
if (url.getProtocol ().equals ("file"))
|
||||
{
|
||||
// For "file" URLs constructed relative to a context, we
|
||||
// need to canonicalise the file path.
|
||||
try
|
||||
{
|
||||
file =
|
||||
file.substring(0, lastSlash) + sepChar + spec.substring(start, end);
|
||||
|
||||
if (url.getProtocol().equals("file"))
|
||||
{
|
||||
// For "file" URLs constructed relative to a context, we
|
||||
// need to canonicalise the file path.
|
||||
try
|
||||
{
|
||||
boolean endsWithSlash = file.charAt(file.length() - 1) == '/';
|
||||
file = new File (file).getCanonicalPath ();
|
||||
if (endsWithSlash
|
||||
&& file.charAt(file.length() - 1) != '/')
|
||||
file = new File(file).getCanonicalPath();
|
||||
if (endsWithSlash && file.charAt(file.length() - 1) != '/')
|
||||
file += '/';
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ref = null;
|
||||
}
|
||||
@ -240,10 +241,9 @@ public abstract class URLStreamHandler
|
||||
// XXX - Classpath used to call PlatformHelper.toCanonicalForm() on
|
||||
// the file part. It seems like overhead, but supposedly there is some
|
||||
// benefit in windows based systems (it also lowercased the string).
|
||||
|
||||
setURL(url, url.getProtocol(), host, port, file, ref);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Canonicalize a filename.
|
||||
*/
|
||||
@ -251,7 +251,6 @@ public abstract class URLStreamHandler
|
||||
{
|
||||
// XXX - GNU Classpath has an implementation that might be more appropriate
|
||||
// for Windows based systems (gnu.java.io.PlatformHelper.toCanonicalForm)
|
||||
|
||||
int index;
|
||||
|
||||
// Replace "/./" with "/". This probably isn't very efficient in
|
||||
@ -270,7 +269,7 @@ public abstract class URLStreamHandler
|
||||
else
|
||||
break;
|
||||
}
|
||||
return file;
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -278,7 +277,7 @@ public abstract class URLStreamHandler
|
||||
*
|
||||
* @param url1 The first url
|
||||
* @param url2 The second url to compare with the first
|
||||
*
|
||||
*
|
||||
* @return True if both URLs point to the same file, false otherwise.
|
||||
*
|
||||
* @specnote Now protected
|
||||
@ -287,19 +286,21 @@ public abstract class URLStreamHandler
|
||||
{
|
||||
if (url1 == url2)
|
||||
return true;
|
||||
|
||||
// This comparison is very conservative. It assumes that any
|
||||
// field can be null.
|
||||
if (url1 == null || url2 == null)
|
||||
return false;
|
||||
int p1 = url1.getPort ();
|
||||
int p1 = url1.getPort();
|
||||
if (p1 == -1)
|
||||
p1 = url1.ph.getDefaultPort ();
|
||||
int p2 = url2.getPort ();
|
||||
p1 = url1.ph.getDefaultPort();
|
||||
int p2 = url2.getPort();
|
||||
if (p2 == -1)
|
||||
p2 = url2.ph.getDefaultPort ();
|
||||
p2 = url2.ph.getDefaultPort();
|
||||
if (p1 != p2)
|
||||
return false;
|
||||
String s1, s2;
|
||||
String s1;
|
||||
String s2;
|
||||
s1 = url1.getProtocol();
|
||||
s2 = url2.getProtocol();
|
||||
if (s1 != s2 && (s1 == null || ! s1.equals(s2)))
|
||||
@ -333,7 +334,7 @@ public abstract class URLStreamHandler
|
||||
* #setURL(URL,String,String,int,String,String,String,String);
|
||||
*/
|
||||
protected void setURL(URL u, String protocol, String host, int port,
|
||||
String file, String ref)
|
||||
String file, String ref)
|
||||
{
|
||||
u.set(protocol, host, port, file, ref);
|
||||
}
|
||||
@ -355,8 +356,8 @@ public abstract class URLStreamHandler
|
||||
* different from this one
|
||||
*/
|
||||
protected void setURL(URL u, String protocol, String host, int port,
|
||||
String authority, String userInfo, String path,
|
||||
String query, String ref)
|
||||
String authority, String userInfo, String path,
|
||||
String query, String ref)
|
||||
{
|
||||
u.set(protocol, host, port, authority, userInfo, path, query, ref);
|
||||
}
|
||||
@ -372,32 +373,29 @@ public abstract class URLStreamHandler
|
||||
*
|
||||
* @return True if both given URLs are equal, false otherwise.
|
||||
*/
|
||||
protected boolean equals (URL url1, URL url2)
|
||||
protected boolean equals(URL url1, URL url2)
|
||||
{
|
||||
// This comparison is very conservative. It assumes that any
|
||||
// field can be null.
|
||||
return (url1.getPort () == url2.getPort ()
|
||||
&& ((url1.getProtocol () == null && url2.getProtocol () == null)
|
||||
|| (url1.getProtocol () != null
|
||||
&& url1.getProtocol ().equals (url2.getProtocol ())))
|
||||
&& ((url1.getUserInfo () == null && url2.getUserInfo () == null)
|
||||
|| (url1.getUserInfo () != null
|
||||
&& url1.getUserInfo ().equals(url2.getUserInfo ())))
|
||||
&& ((url1.getAuthority () == null && url2.getAuthority () == null)
|
||||
|| (url1.getAuthority () != null
|
||||
&& url1.getAuthority ().equals(url2.getAuthority ())))
|
||||
&& ((url1.getHost () == null && url2.getHost () == null)
|
||||
|| (url1.getHost () != null
|
||||
&& url1.getHost ().equals(url2.getHost ())))
|
||||
&& ((url1.getPath () == null && url2.getPath () == null)
|
||||
|| (url1.getPath () != null
|
||||
&& url1.getPath ().equals (url2.getPath ())))
|
||||
&& ((url1.getQuery () == null && url2.getQuery () == null)
|
||||
|| (url1.getQuery () != null
|
||||
&& url1.getQuery ().equals(url2.getQuery ())))
|
||||
&& ((url1.getRef () == null && url2.getRef () == null)
|
||||
|| (url1.getRef () != null
|
||||
&& url1.getRef ().equals(url2.getRef ()))));
|
||||
return (url1.getPort() == url2.getPort()
|
||||
&& ((url1.getProtocol() == null && url2.getProtocol() == null)
|
||||
|| (url1.getProtocol() != null
|
||||
&& url1.getProtocol().equals(url2.getProtocol())))
|
||||
&& ((url1.getUserInfo() == null && url2.getUserInfo() == null)
|
||||
|| (url1.getUserInfo() != null
|
||||
&& url1.getUserInfo().equals(url2.getUserInfo())))
|
||||
&& ((url1.getAuthority() == null && url2.getAuthority() == null)
|
||||
|| (url1.getAuthority() != null
|
||||
&& url1.getAuthority().equals(url2.getAuthority())))
|
||||
&& ((url1.getHost() == null && url2.getHost() == null)
|
||||
|| (url1.getHost() != null && url1.getHost().equals(url2.getHost())))
|
||||
&& ((url1.getPath() == null && url2.getPath() == null)
|
||||
|| (url1.getPath() != null && url1.getPath().equals(url2.getPath())))
|
||||
&& ((url1.getQuery() == null && url2.getQuery() == null)
|
||||
|| (url1.getQuery() != null
|
||||
&& url1.getQuery().equals(url2.getQuery())))
|
||||
&& ((url1.getRef() == null && url2.getRef() == null)
|
||||
|| (url1.getRef() != null && url1.getRef().equals(url2.getRef()))));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -410,19 +408,19 @@ public abstract class URLStreamHandler
|
||||
*
|
||||
* @exception UnknownHostException If an unknown host is found
|
||||
*/
|
||||
protected boolean hostsEqual (URL url1, URL url2)
|
||||
protected boolean hostsEqual(URL url1, URL url2)
|
||||
{
|
||||
InetAddress addr1 = getHostAddress (url1);
|
||||
InetAddress addr2 = getHostAddress (url2);
|
||||
InetAddress addr1 = getHostAddress(url1);
|
||||
InetAddress addr2 = getHostAddress(url2);
|
||||
|
||||
if (addr1 != null && addr2 != null)
|
||||
return addr1.equals (addr2);
|
||||
return addr1.equals(addr2);
|
||||
|
||||
String host1 = url1.getHost();
|
||||
String host2 = url2.getHost();
|
||||
|
||||
|
||||
if (host1 != null && host2 != null)
|
||||
return host1.equalsIgnoreCase (host2);
|
||||
return host1.equalsIgnoreCase(host2);
|
||||
|
||||
return host1 == null && host2 == null;
|
||||
}
|
||||
@ -435,16 +433,16 @@ public abstract class URLStreamHandler
|
||||
*
|
||||
* @return The address of the hostname in url.
|
||||
*/
|
||||
protected InetAddress getHostAddress (URL url)
|
||||
protected InetAddress getHostAddress(URL url)
|
||||
{
|
||||
String hostname = url.getHost ();
|
||||
String hostname = url.getHost();
|
||||
|
||||
if (hostname.equals(""))
|
||||
return null;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
return InetAddress.getByName (hostname);
|
||||
return InetAddress.getByName(hostname);
|
||||
}
|
||||
catch (UnknownHostException e)
|
||||
{
|
||||
@ -458,7 +456,7 @@ public abstract class URLStreamHandler
|
||||
*
|
||||
* @return The default port number.
|
||||
*/
|
||||
protected int getDefaultPort ()
|
||||
protected int getDefaultPort()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -468,15 +466,14 @@ public abstract class URLStreamHandler
|
||||
* other protocols that have different requirements for hashCode calculation.
|
||||
*
|
||||
* @param url The URL to calc the hashcode for.
|
||||
*
|
||||
*
|
||||
* @return The hashcode for the given URL.
|
||||
*/
|
||||
protected int hashCode (URL url)
|
||||
protected int hashCode(URL url)
|
||||
{
|
||||
return url.getProtocol ().hashCode () +
|
||||
((url.getHost () == null) ? 0 : url.getHost ().hashCode ()) +
|
||||
url.getFile ().hashCode() +
|
||||
url.getPort ();
|
||||
return url.getProtocol().hashCode()
|
||||
+ ((url.getHost() == null) ? 0 : url.getHost().hashCode())
|
||||
+ url.getFile().hashCode() + url.getPort();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -488,23 +485,27 @@ public abstract class URLStreamHandler
|
||||
*
|
||||
* @return A string representation of the url
|
||||
*/
|
||||
protected String toExternalForm(URL u)
|
||||
protected String toExternalForm(URL url)
|
||||
{
|
||||
String protocol, host, file, ref, user;
|
||||
String protocol;
|
||||
String host;
|
||||
String file;
|
||||
String ref;
|
||||
String user;
|
||||
int port;
|
||||
|
||||
protocol = u.getProtocol();
|
||||
protocol = url.getProtocol();
|
||||
|
||||
// JDK 1.2 online doc infers that host could be null because it
|
||||
// explicitly states that file cannot be null, but is silent on host.
|
||||
host = u.getHost();
|
||||
host = url.getHost();
|
||||
if (host == null)
|
||||
host = "";
|
||||
|
||||
port = u.getPort();
|
||||
file = u.getFile();
|
||||
ref = u.getRef();
|
||||
user = u.getUserInfo();
|
||||
port = url.getPort();
|
||||
file = url.getFile();
|
||||
ref = url.getRef();
|
||||
user = url.getUserInfo();
|
||||
|
||||
// Guess a reasonable size for the string buffer so we have to resize
|
||||
// at most once.
|
||||
@ -520,13 +521,13 @@ public abstract class URLStreamHandler
|
||||
if (host.length() != 0)
|
||||
{
|
||||
sb.append("//");
|
||||
if (user != null && !"".equals(user))
|
||||
if (user != null && ! "".equals(user))
|
||||
sb.append(user).append('@');
|
||||
sb.append(host);
|
||||
|
||||
// Append port if port was in URL spec.
|
||||
if (port >= 0)
|
||||
sb.append(':').append(port);
|
||||
// Append port if port was in URL spec.
|
||||
if (port >= 0)
|
||||
sb.append(':').append(port);
|
||||
}
|
||||
|
||||
sb.append(file);
|
||||
|
@ -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,15 +37,15 @@ 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 contains one method which maps the protocol portion of
|
||||
* a URL (eg, "http" in "http://www.urbanophile.com/arenn/") to a
|
||||
* a URL (eg, "http" in "http://www.urbanophile.com/arenn/") to a
|
||||
* <code>URLStreamHandler</code> object.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
@ -54,14 +54,12 @@ package java.net;
|
||||
public interface URLStreamHandlerFactory
|
||||
{
|
||||
/**
|
||||
* This method maps the protocol portion of a URL to a
|
||||
* This method maps the protocol portion of a URL to a
|
||||
* <code>URLStreamHandler</code> object.
|
||||
*
|
||||
* @param protocol The protocol name to map ("http", "ftp", etc).
|
||||
*
|
||||
* @return The <code>URLStreamHandler</code> for the specified protocol
|
||||
*/
|
||||
URLStreamHandler createURLStreamHandler (String protocol);
|
||||
|
||||
URLStreamHandler createURLStreamHandler(String protocol);
|
||||
} // interface URLStreamHandlerFactory
|
||||
|
||||
|
@ -39,6 +39,7 @@ package java.net;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* This exception indicates that an attempt was made to reference a hostname
|
||||
* or IP address that is not valid. This could possibly indicate that a
|
||||
|
@ -39,6 +39,7 @@ package java.net;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* Contrary to what you might think, this does not indicate that the
|
||||
* TCP/IP service name specified was invalid. Instead it indicates that
|
||||
|
Loading…
x
Reference in New Issue
Block a user