java.net
Class URLStreamHandler
java.lang.Object
|
+--java.net.URLStreamHandler
public abstract class
URLStreamHandlerextends
Object This class is the superclass of all URL protocol handlers. The URL
class loads the appropriate protocol handler to establish a connection
to a (possibly) remote service (eg, "http", "ftp") and to do protocol
specific parsing of URL's. Refer to the URL class documentation for
details on how that class locates and loads protocol handlers.
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
of URLConnection will most likely need to be created as well.
Note that the instance methods in this class are called as if they
were static methods. That is, a URL object to act on is passed with
every call rather than the caller assuming the URL is stored in an
instance variable of the "this" object.
The methods in this class are protected and accessible only to subclasses.
URLStreamConnection objects are intended for use by the URL class only,
not by other classes (unless those classes are implementing protocols).
Authors:- Aaron M. Renn (arenn@urbanophile.com)
- Warren Levy (warrenl@cygnus.com)
See Also:
boolean | equals(java.net.URL url1, java.net.URL url2)
|
int | getDefaultPort()
|
java.net.InetAddress | getHostAddress(java.net.URL url)
|
int | hashCode(java.net.URL url)
|
boolean | hostsEqual(java.net.URL url1, java.net.URL url2)
|
java.net.URLConnection | openConnection(java.net.URL u)
|
void | parseURL(java.net.URL url, java.lang.String spec, int start, int end)
|
boolean | sameFile(java.net.URL url1, java.net.URL url2)
|
void | setURL(java.net.URL u, java.lang.String protocol, java.lang.String host, int port, java.lang.String file, java.lang.String ref)
|
void | setURL(java.net.URL u, java.lang.String protocol, java.lang.String host, int port, java.lang.String authority, java.lang.String userInfo, java.lang.String path, java.lang.String query, java.lang.String ref)
|
java.lang.String | toExternalForm(java.net.URL u)
|
URLStreamHandler
public URLStreamHandler()
Creates a URLStreamHander
equals
protected boolean equals(java.net.URL url1, java.net.URL url2)
Provides the default equals calculation. May be overidden by handlers for
other protocols that have different requirements for equals(). This method
requires that none of its arguments is null. This is guaranteed by the
fact that it is only called by java.net.URL class.
Parameters:
getDefaultPort
protected int getDefaultPort()
Returns the default port for a URL parsed by this handler. This method is
meant to be overidden by handlers with default port numbers.
getHostAddress
protected InetAddress getHostAddress(java.net.URL url)
Get the IP address of our host. An empty host field or a DNS failure will
result in a null return.
Parameters:
hashCode
protected int hashCode(java.net.URL url)
Provides the default hash calculation. May be overidden by handlers for
other protocols that have different requirements for hashCode calculation.
Parameters:
hostsEqual
protected boolean hostsEqual(java.net.URL url1, java.net.URL url2)
Compares the host components of two URLs.
Parameters:
Throws:
openConnection
protected URLConnection openConnection(java.net.URL u)
Returns a URLConnection for the passed in URL. Note that this should
not actually create the connection to the (possibly) remote host, but
rather simply return a URLConnection object. The connect() method of
URL connection is used to establish the actual connection, possibly
after the caller sets up various connection options.
Parameters:
Returns:
- A URLConnection object for the given URL
Throws:
parseURL
protected void parseURL(java.net.URL url, java.lang.String spec, int start, int end)
This method parses the string passed in as a URL and set's the
instance data fields in the URL object passed in to the various values
parsed out of the string. The start parameter is the position to start
scanning the string. This is usually the position after the ":" which
terminates the protocol name. The end parameter is the position to
stop scanning. This will be either the end of the String, or the
position of the "#" character, which separates the "file" portion of
the URL from the "anchor" portion.
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
a an empty hostname (i.e., "file:///"), which is legal for that protocol
Parameters:
sameFile
protected boolean sameFile(java.net.URL url1, java.net.URL url2)
Compares two URLs, excluding the fragment component
Parameters:
setURL
protected void setURL(java.net.URL u, java.lang.String protocol, java.lang.String host, int port, java.lang.String file, java.lang.String ref)
This methods sets the instance variables representing the various fields
of the URL to the values passed in.
Parameters:
Throws:
setURL
protected void setURL(java.net.URL u, java.lang.String protocol, java.lang.String host, int port, java.lang.String authority, java.lang.String userInfo, java.lang.String path, java.lang.String query, java.lang.String ref)
Sets the fields of the URL argument to the indicated values
Parameters:
Throws:
toExternalForm
protected String toExternalForm(java.net.URL u)
This method converts a URL object into a String. This method creates
Strings in the mold of http URL's, so protocol handlers which use URL's
that have a different syntax should override this method
Parameters:
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 of URLConnection will most likely need to be created as well.
Note that the instance methods in this class are called as if they were static methods. That is, a URL object to act on is passed with every call rather than the caller assuming the URL is stored in an instance variable of the "this" object.
The methods in this class are protected and accessible only to subclasses. URLStreamConnection objects are intended for use by the URL class only, not by other classes (unless those classes are implementing protocols).