java.net
Class URLStreamHandler
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).
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) - 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.
|
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
equals
protected boolean equals(URL url1,
URL url2)
This is the default method for computing whether two URLs are
equivalent. This method assumes that neither URL is null.
url1
- An URL objecturl2
- Another URL object
- True if both given URLs are equal, false otherwise.
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(URL url)
Get the IP address of our host. An empty host field or a DNS failure will
result in a null return.
url
- The URL to return the host address for.
- The address of the hostname in url.
hashCode
protected int hashCode(URL url)
Provides the default hash calculation. May be overidden by handlers for
other protocols that have different requirements for hashCode calculation.
url
- The URL to calc the hashcode for.
- The hashcode for the given URL.
hostsEqual
protected boolean hostsEqual(URL url1,
URL url2)
Compares the host components of two URLs.
url1
- The first URL.url2
- The second URL.
- True if both URLs contain the same host.
openConnection
protected abstract URLConnection openConnection(URL url)
throws IOException
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.
url
- The URL to get a connection object for
- A URLConnection object for the given URL
parseURL
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. 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
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 scanning
sameFile
protected boolean sameFile(URL url1,
URL url2)
Compares two URLs, excluding the fragment component
url1
- The first urlurl2
- The second url to compare with the first
- True if both URLs point to the same file, false otherwise.
setURL
protected void setURL(URL u,
String protocol,
String host,
int port,
String file,
String ref)
1.2 Please use
#setURL(URL,String,String,int,String,String,String,String);
This methods sets the instance variables representing the various fields
of the URL to the values passed in.
u
- The URL to modifyprotocol
- The protocol to sethost
- The host name to etport
- The port number to setfile
- The filename to setref
- The reference
setURL
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
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 reference
toExternalForm
protected String toExternalForm(URL url)
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
url
- The URL object to convert
- A string representation of the url
URLStreamHandler.java -- Abstract superclass for all protocol handlers
Copyright (C) 1998, 1999, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.