Package java.net
Class URLStreamHandler
java.lang.Object
java.net.URLStreamHandler
- Direct Known Subclasses:
FileHandler,FtpHandler,HttpHandler,JarHandler
public abstract class URLStreamHandler extends Object
The abstract class
URLStreamHandler is the base for all classes which
can handle the communication with a URL object over a particular protocol
type.-
Constructor Summary
Constructors Constructor Description URLStreamHandler() -
Method Summary
Modifier and Type Method Description protected booleanequals(URL a, URL b)Returns true ifaandbhave the same protocol, host, port, file, and reference.protected intgetDefaultPort()Returns the default port of the protocol used by the handled URL.protected InetAddressgetHostAddress(URL url)Returns the host address ofurl.protected inthashCode(URL url)Returns the hash code ofurl.protected booleanhostsEqual(URL a, URL b)Returns true if the hosts ofaandbare equal.protected abstract URLConnectionopenConnection(URL u)Establishes a new connection to the resource specified by the URLu.protected URLConnectionopenConnection(URL u, Proxy proxy)Establishes a new connection to the resource specified by the URLuusing the givenproxy.protected voidparseURL(URL url, String spec, int start, int end)Parses the clear text URL instrinto a URL object.protected booleansameFile(URL a, URL b)Returns true ifaandbhave the same protocol, host, port and file.protected voidsetURL(URL u, String protocol, String host, int port, String file, String ref)Deprecated.Use setURL(URL, String String, int, String, String, String, String, String) instead.protected voidsetURL(URL u, String protocol, String host, int port, String authority, String userInfo, String path, String query, String ref)Sets the fields of the URLuto the values of the supplied arguments.protected StringtoExternalForm(URL url)Returns the clear text representation of a given URL using HTTP format.
-
Constructor Details
-
URLStreamHandler
public URLStreamHandler()
-
-
Method Details
-
openConnection
Establishes a new connection to the resource specified by the URLu. Since different protocols also have unique ways of connecting, it must be overwritten by the subclass.- Parameters:
u- the URL to the resource where a connection has to be opened.- Returns:
- the opened URLConnection to the specified resource.
- Throws:
IOException- if an I/O error occurs during opening the connection.
-
openConnection
Establishes a new connection to the resource specified by the URLuusing the givenproxy. Since different protocols also have unique ways of connecting, it must be overwritten by the subclass.- Parameters:
u- the URL to the resource where a connection has to be opened.proxy- the proxy that is used to make the connection.- Returns:
- the opened URLConnection to the specified resource.
- Throws:
IOException- if an I/O error occurs during opening the connection.IllegalArgumentException- if any argument isnullor the type of proxy is wrong.UnsupportedOperationException- if the protocol handler doesn't support this method.
-
parseURL
Parses the clear text URL instrinto a URL object. URL strings generally have the following format:http://www.company.com/java/file1.java#reference
The string is parsed in HTTP format. If the protocol has a different URL format this method must be overridden.
- Parameters:
url- the URL to fill in the parsed clear text URL parts.spec- the URL string that is to be parsed.start- the string position from where to begin parsing.end- the string position to stop parsing.- See Also:
toExternalForm(java.net.URL),URL
-
setURL
@Deprecated protected void setURL(URL u, String protocol, String host, int port, String file, String ref)Deprecated.Use setURL(URL, String String, int, String, String, String, String, String) instead.Sets the fields of the URLuto the values of the supplied arguments.- Parameters:
u- the non-null URL object to be set.protocol- the protocol.host- the host name.port- the port number.file- the file component.ref- 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 URLuto the values of the supplied arguments. -
toExternalForm
Returns the clear text representation of a given URL using HTTP format.- Parameters:
url- the URL object to be converted.- Returns:
- the clear text representation of the specified URL.
- See Also:
parseURL(java.net.URL, java.lang.String, int, int),URL.toExternalForm()
-
equals
Returns true ifaandbhave the same protocol, host, port, file, and reference. -
getDefaultPort
protected int getDefaultPort()Returns the default port of the protocol used by the handled URL. The default implementation always returns-1. -
getHostAddress
Returns the host address ofurl. -
hashCode
Returns the hash code ofurl. -
hostsEqual
Returns true if the hosts ofaandbare equal. -
sameFile
Returns true ifaandbhave the same protocol, host, port and file.
-