gcc/libjava/java/net/URLStreamHandler.java

292 lines
8.1 KiB
Java
Raw Normal View History

1999-04-07 14:42:40 +00:00
// URLStreamHandler.java - Superclass of all stream protocol handlers.
/* Copyright (C) 1999, 2002 Free Software Foundation
1999-04-07 14:42:40 +00:00
This file is part of libgcj.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
package java.net;
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 09:05:53 +00:00
import java.io.IOException;
1999-04-07 14:42:40 +00:00
/**
* @author Warren Levy <warrenl@cygnus.com>
* @date March 4, 1999.
*/
/**
* 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.
*/
public abstract class URLStreamHandler
{
2002-09-30 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (receive): Check with SecurityManager AFTER the packet is received, check if connected to multicast address, documentation added. (send): Only check SecurityManager if connected, check address of packet to send. (connect): Implemented, documentation added. * java/net/Inet6Address.java: New file (not added yet to Makefile.am). * java/net/InetSocketAddress.java (whole file): Reindented. (hostname): New attribute. (InetSocketAddress): Initialize new attribute. (getAddress): Documentation added. (getHostName): Documentation added. (getPort): Documentation added. (hashCode): Documentation added. (isUnresolved): Documentation added. (toString): Conform to output of JDK 1.4.1, documentation added. * java/net/MulticastSocket.java (joinGroup): Removed FIXME, documentation added. (leaveGroup): Removed FIXME, documentation added. (send): Documentation added. * java/net/Socket.java (inputShutdown): New variable. (outputShutdown): New variable. (Socket): Initialize new variables. (getRemoteSocketAddress): Check if connected. (shutdownInput): Set new variable. (shutdownOutput): Set new variable. (isConnected): New method. (isClosed): New method. (isInputShutdown): New method. (isOutputShutdown): New method. * java/net/URLStreamHandler.java (URLStreamHandler): New method. (openConnection): Added documentation. (parseURL): Added documentation. (getHostAddress): New method. (getDefaultPort): New method. From-SVN: r57772
2002-10-03 11:23:33 +00:00
/**
* Creates a URLStreamHander
*/
public URLStreamHandler ()
{
}
/**
* Opens a connection to the object referenced by the URL argument.
* This method should be overridden by a subclass.
*
* @exception IOException If an error occurs
*/
1999-04-07 14:42:40 +00:00
protected abstract URLConnection openConnection(URL u)
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 09:05:53 +00:00
throws IOException;
/**
* Pasrses the given URL
*
* @param u The URL to parse
* @param spec The specification to use
2002-09-30 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (receive): Check with SecurityManager AFTER the packet is received, check if connected to multicast address, documentation added. (send): Only check SecurityManager if connected, check address of packet to send. (connect): Implemented, documentation added. * java/net/Inet6Address.java: New file (not added yet to Makefile.am). * java/net/InetSocketAddress.java (whole file): Reindented. (hostname): New attribute. (InetSocketAddress): Initialize new attribute. (getAddress): Documentation added. (getHostName): Documentation added. (getPort): Documentation added. (hashCode): Documentation added. (isUnresolved): Documentation added. (toString): Conform to output of JDK 1.4.1, documentation added. * java/net/MulticastSocket.java (joinGroup): Removed FIXME, documentation added. (leaveGroup): Removed FIXME, documentation added. (send): Documentation added. * java/net/Socket.java (inputShutdown): New variable. (outputShutdown): New variable. (Socket): Initialize new variables. (getRemoteSocketAddress): Check if connected. (shutdownInput): Set new variable. (shutdownOutput): Set new variable. (isConnected): New method. (isClosed): New method. (isInputShutdown): New method. (isOutputShutdown): New method. * java/net/URLStreamHandler.java (URLStreamHandler): New method. (openConnection): Added documentation. (parseURL): Added documentation. (getHostAddress): New method. (getDefaultPort): New method. From-SVN: r57772
2002-10-03 11:23:33 +00:00
* @param start The character index at which to begin parsing. This is just
* past the ':' (if there is one) that specifies the determination of the
* protocol name
* @param limit The character position to stop parsing at. This is the end
* of the string or the position of the "#" character, if present. All
* information after the sharp sign indicates an anchor
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 09:05:53 +00:00
*/
protected void parseURL(URL u, String spec, int start, int limit)
1999-04-07 14:42:40 +00:00
{
String host = u.getHost();
int port = u.getPort();
String file = u.getFile();
1999-04-07 14:42:40 +00:00
/* TBD: The JDK 1.2 doc specifically says that limit is the position
* to stop parsing at and that it will be either the end of the string
* or the position of '#'; thus the doc infers that this method does
* not set the ref.
*/
if (spec.regionMatches (start, "//", 0, 2))
1999-04-07 14:42:40 +00:00
{
int hostEnd;
int colon;
1999-04-07 14:42:40 +00:00
start += 2;
int slash = spec.indexOf('/', start);
if (slash >= 0)
hostEnd = slash;
else
hostEnd = limit;
host = spec.substring (start, hostEnd);
// Look for optional port number. It is valid for the non-port
// part of the host name to be null (e.g. a URL "http://:80").
// TBD: JDK 1.2 in this case sets host to null rather than "";
// 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.
1999-04-07 14:42:40 +00:00
if ((colon = host.indexOf(':')) >= 0)
{
try
{
port = Integer.parseInt(host.substring(colon + 1));
}
catch (NumberFormatException e)
{
; // Ignore invalid port values; port is already set to u's
// port.
1999-04-07 14:42:40 +00:00
}
host = host.substring(0, colon);
}
file = null;
start = hostEnd;
}
else if (host == null)
host = "";
if (start < limit && spec.charAt(start) == '/')
{
// This is an absolute path name; ignore any file context.
file = spec.substring(start, limit);
}
else if (file == null || file.length() <= 0)
{
// No file context available; just spec for file.
file = spec.substring(start, limit);
}
else if (start < limit)
{
// Context is available, but only override it if there is a new file.
file = file.substring(0, file.lastIndexOf('/'))
+ '/' + spec.substring(start, limit);
1999-04-07 14:42:40 +00:00
}
u.set(u.getProtocol(), host, port, file, u.getRef());
}
private static String canonicalizeFilename(String file)
{
int index;
1999-04-07 14:42:40 +00:00
// Replace "/./" with "/". This probably isn't very efficient in
// the general case, but it's probably not bad most of the time.
while ((index = file.indexOf("/./")) >= 0)
file = file.substring(0, index) + file.substring(index + 2);
// Process "/../" correctly. This probably isn't very efficient in
// the general case, but it's probably not bad most of the time.
while ((index = file.indexOf("/../")) >= 0)
{
// Strip of the previous directory - if it exists.
int previous = file.lastIndexOf('/', index - 1);
if (previous >= 0)
file = file.substring(0, previous) + file.substring(index + 3);
else
break;
}
return file;
1999-04-07 14:42:40 +00:00
}
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 09:05:53 +00:00
/**
* Compares two URLs, excluding the fragment component
*
* @param url1 The first url
* @param url2 The second url to compare with the first
*
* @specnote Now protected
*/
protected boolean sameFile(URL url1, URL url2)
{
if (url1 == url2)
return true;
// This comparison is very conservative. It assumes that any
// field can be null.
if (url1 == null || url2 == null || url1.getPort() != url2.getPort())
return false;
String s1, s2;
s1 = url1.getProtocol();
s2 = url2.getProtocol();
if (s1 != s2 && (s1 == null || ! s1.equals(s2)))
return false;
s1 = url1.getHost();
s2 = url2.getHost();
if (s1 != s2 && (s1 == null || ! s1.equals(s2)))
return false;
s1 = canonicalizeFilename(url1.getFile());
s2 = canonicalizeFilename(url2.getFile());
if (s1 != s2 && (s1 == null || ! s1.equals(s2)))
return false;
return true;
}
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 09:05:53 +00:00
/**
* Sets the fields of the URL argument to the indicated values
*
* @param u The URL to modify
* @param protocol The protocol to set
* @param host The host name to et
* @param port The port number to set
* @param file The filename to set
* @param ref The reference
*
* @exception SecurityException If the protocol handler of the URL is
* different from this one
*
* @deprecated 1.2 Please use
* #setURL(URL,String,String,int,String,String,String,String);
*/
1999-04-07 14:42:40 +00:00
protected void setURL(URL u, String protocol, String host, int port,
String file, String ref)
{
u.set(protocol, host, port, file, ref);
}
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Initialize new instance variables. (close): Reset new instance variables. (getLocalAddress): Remove unneeded SecurityManager usage. (getLocalPort): Check if socket is already bound. (isConnected): New method. (getInetAddress): Implemented. (getPort): Better Implementation, documentation fixed. (getRemoteSocketAddress): New method. * java/net/JarURLConnection.java (element): Typo fixed. (getMainAttributes): New method. (getAttributes): New method (stub only). (getManifest): New method (stub only). * java/net/NetPermission.java: Added serialVersionsUID. * java/net/Socket.java (connect): Check blocking mode of associated channel, documentation added. (getLocalSocketAddress): Better implementation. (getRemoteSocketAddress): Implemented. (isBound): New method. (setSendBufferSize): Documentation added. * java/net/SocketAddress.java: Added serialVersionsUID. * java/net/SocketPermission.java: Added serialVersionsUID. * java/net/URL.java (URL): Wrap for shorter lines, initialize new instance variables, documentation added. (equals): Check new instance variables too. (getContent): Documentation added. (getPath): Documentation added. (getAuthority): New method. (getHost): Documentation added. (getPort): Documentation added. (getDefaultPort): New method. (getProtocol): Documentation added. (getUserInfo): Documentation added. (set): Initialize new instance variables, documentation added. * java/net/URLStreamHandler.java (setURL): New method. * java/net/natPlainDatagramSocketImpl.cc (connect): Fix exception name. (disconnect): Fix exception name. From-SVN: r57501
2002-09-25 17:14:09 +00:00
/**
* Sets the fields of the URL argument to the indicated values
*
* @param u The URL to modify
* @param protocol The protocol to set
* @param host The host name to set
* @param port The port number to set
* @param authority The authority to set
* @param userInfo The user information to set
* @param path The path/filename to set
* @param query The query part to set
* @param ref The reference
*
* @exception SecurityException If the protocol handler of the URL is
* 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)
{
u.set(protocol, host, port, authority, userInfo, path, query, ref);
}
2002-09-30 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (receive): Check with SecurityManager AFTER the packet is received, check if connected to multicast address, documentation added. (send): Only check SecurityManager if connected, check address of packet to send. (connect): Implemented, documentation added. * java/net/Inet6Address.java: New file (not added yet to Makefile.am). * java/net/InetSocketAddress.java (whole file): Reindented. (hostname): New attribute. (InetSocketAddress): Initialize new attribute. (getAddress): Documentation added. (getHostName): Documentation added. (getPort): Documentation added. (hashCode): Documentation added. (isUnresolved): Documentation added. (toString): Conform to output of JDK 1.4.1, documentation added. * java/net/MulticastSocket.java (joinGroup): Removed FIXME, documentation added. (leaveGroup): Removed FIXME, documentation added. (send): Documentation added. * java/net/Socket.java (inputShutdown): New variable. (outputShutdown): New variable. (Socket): Initialize new variables. (getRemoteSocketAddress): Check if connected. (shutdownInput): Set new variable. (shutdownOutput): Set new variable. (isConnected): New method. (isClosed): New method. (isInputShutdown): New method. (isOutputShutdown): New method. * java/net/URLStreamHandler.java (URLStreamHandler): New method. (openConnection): Added documentation. (parseURL): Added documentation. (getHostAddress): New method. (getDefaultPort): New method. From-SVN: r57772
2002-10-03 11:23:33 +00:00
/**
* Get the IP address of our host. An empty host field or a DNS failure will
* result in a null return.
*/
protected InetAddress getHostAddress (URL url)
{
String hostname = url.getHost ();
if (hostname == "")
return null;
try
{
return InetAddress.getByName (hostname);
}
catch (UnknownHostException e)
{
return null;
}
}
/**
* Returns the default port for a URL parsed by this handler. This method is
* meant to be overidden by handlers with default port numbers.
*/
protected int getDefaultPort ()
{
return -1;
}
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 09:05:53 +00:00
/**
* Converts an URL of a specific protocol to a string
*
* @param u The URL to convert
*/
1999-04-07 14:42:40 +00:00
protected String toExternalForm(URL u)
{
String resStr, host, file, ref;
int port;
resStr = u.getProtocol() + ":";
host = u.getHost();
port = u.getPort();
file = u.getFile();
ref = u.getRef();
// 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.
//
// Note that this produces different results from JDK 1.2 as JDK 1.2
// ignores a non-default port if host is null or "". That is inconsistent
// with the spec since the result of this method is spec'ed so it can be
// used to construct a new URL that is equivalent to the original.
if (host == null)
host = "";
if (port >= 0 || ! (host.length() == 0))
resStr = resStr + "//" + host + (port < 0 ? "" : ":" + port);
1999-04-07 14:42:40 +00:00
resStr = resStr + file;
if (ref != null)
resStr = resStr + "#" + ref;
return resStr;
}
}