public abstract class URLStreamHandler extends Object
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).
URL
Constructor and Description |
---|
URLStreamHandler()
Creates a URLStreamHander
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
equals(URL url1,
URL url2)
This is the default method for computing whether two URLs are
equivalent.
|
protected int |
getDefaultPort()
Returns the default port for a URL parsed by this handler.
|
protected InetAddress |
getHostAddress(URL url)
Get the IP address of our host.
|
protected int |
hashCode(URL url)
Provides the default hash calculation.
|
protected boolean |
hostsEqual(URL url1,
URL url2)
Compares the host components of two URLs.
|
protected abstract URLConnection |
openConnection(URL url)
Returns a URLConnection for the passed in URL.
|
protected void |
parseURL(URL url,
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.
|
protected boolean |
sameFile(URL url1,
URL url2)
Compares two URLs, excluding the fragment component
|
protected void |
setURL(URL u,
String protocol,
String host,
int port,
String file,
String ref)
Deprecated.
1.2 Please use
#setURL(URL,String,String,int,String,String,String,String);
|
protected void |
setURL(URL u,
String protocol,
String host,
int port,
String authority,
String userInfo,
String path,
String query,
String ref)
Sets the fields of the URL argument to the indicated values
|
protected String |
toExternalForm(URL url)
This method converts a URL object into a String.
|
public URLStreamHandler()
protected abstract URLConnection openConnection(URL url) throws IOException
url
- The URL to get a connection object forIOException
- If an error occursprotected void parseURL(URL url, String spec, int start, int end)
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
url
- The URL object in which to store the resultsspec
- The String-ized URL to parsestart
- The position in the string to start scanning fromend
- The position in the string to stop scanningprotected boolean sameFile(URL url1, URL url2)
url1
- The first urlurl2
- The second url to compare with the firstprotected void setURL(URL u, String protocol, String host, int port, String file, String ref)
u
- The URL to modifyprotocol
- The protocol to sethost
- The host name to etport
- The port number to setfile
- The filename to setref
- The referenceSecurityException
- If the protocol handler of the URL is
different from this oneprotected void setURL(URL u, String protocol, String host, int port, String authority, String userInfo, String path, String query, String ref)
u
- The URL to modifyprotocol
- The protocol to sethost
- The host name to setport
- The port number to setauthority
- The authority to setuserInfo
- The user information to setpath
- The path/filename to setquery
- The query part to setref
- The referenceSecurityException
- If the protocol handler of the URL is
different from this oneprotected boolean equals(URL url1, URL url2)
url1
- An URL objecturl2
- Another URL objectprotected boolean hostsEqual(URL url1, URL url2)
url1
- The first URL.url2
- The second URL.protected InetAddress getHostAddress(URL url)
url
- The URL to return the host address for.protected int getDefaultPort()
protected int hashCode(URL url)
url
- The URL to calc the hashcode for.protected String toExternalForm(URL url)
url
- The URL object to convert