java.lang.Object | |
↳ | java.net.URL |
A URL instance specifies the location of a resource on the internet as specified by RFC 1738. Such a resource can be a simple file or a service which generates the output dynamically. A URL is divided in its parts protocol, host name, port, path, file, user-info, query, reference and authority. However, not each of this parts has to be defined.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a new URL instance by parsing the string
spec . | |||||||||||
Creates a new URL to the specified resource
spec . | |||||||||||
Creates a new URL to the specified resource
spec . | |||||||||||
Creates a new URL instance using the given arguments.
| |||||||||||
Creates a new URL instance using the given arguments.
| |||||||||||
Creates a new URL instance using the given arguments.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Compares this URL instance with the given argument
o and
determines if both are equal. | |||||||||||
Gets the value of the authority part of this URL.
| |||||||||||
Gets the content of the resource which is referred by this URL.
| |||||||||||
Gets the content of the resource which is referred by this URL.
| |||||||||||
Gets the default port number of the protocol used by this URL.
| |||||||||||
Gets the value of the file part of this URL.
| |||||||||||
Gets the value of the host part of this URL.
| |||||||||||
Gets the value of the path part of this URL.
| |||||||||||
Gets the port number of this URL or
-1 if the port is not set. | |||||||||||
Gets the protocol of this URL.
| |||||||||||
Gets the value of the query part of this URL.
| |||||||||||
Gets the value of the reference part of this URL.
| |||||||||||
Gets the value of the user-info part of this URL.
| |||||||||||
Gets the hashcode value of this URL instance.
| |||||||||||
Opens a connection to the remote resource specified by this URL.
| |||||||||||
Opens a connection to the remote resource specified by this URL.
| |||||||||||
Opens an InputStream to read the resource referred by this URL.
| |||||||||||
Returns whether this URL refers to the same resource as the given
argument
otherURL . | |||||||||||
Sets the
URLStreamHandlerFactory which creates protocol specific
stream handlers. | |||||||||||
Returns a string containing a concise, human-readable representation of
this URL.
| |||||||||||
Returns a string containing a concise, human-readable representation of
this URL.
| |||||||||||
Converts this URL instance into an equivalent URI object.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Sets the properties of this URL using the provided arguments.
| |||||||||||
Sets the properties of this URL using the provided arguments.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
|
Creates a new URL instance by parsing the string spec
.
spec | the URL string representation which has to be parsed. |
---|
MalformedURLException | if the given string spec could not be parsed as a
URL.
|
---|
Creates a new URL to the specified resource spec
. This URL is
relative to the given context
. If the protocol of the parsed URL
does not match with the protocol of the context URL, then the newly
created URL is absolute and bases only on the given URL represented by
spec
. Otherwise the protocol is defined by the context URL.
context | the URL which is used as the context. |
---|---|
spec | the URL string representation which has to be parsed. |
MalformedURLException | if the given string spec could not be parsed as a URL
or an invalid protocol has been found.
|
---|
Creates a new URL to the specified resource spec
. This URL is
relative to the given context
. The handler
will be used
to parse the URL string representation. If this argument is null
the default URLStreamHandler
will be used. If the protocol of the
parsed URL does not match with the protocol of the context URL, then the
newly created URL is absolute and bases only on the given URL represented
by spec
. Otherwise the protocol is defined by the context URL.
context | the URL which is used as the context. |
---|---|
spec | the URL string representation which has to be parsed. |
handler | the specific stream handler to be used by this URL. |
MalformedURLException | if the given string spec could not be parsed as a URL
or an invalid protocol has been found.
|
---|
Creates a new URL instance using the given arguments. The URL uses the default port for the specified protocol.
protocol | the protocol of the new URL. |
---|---|
host | the host name or IP address of the new URL. |
file | the name of the resource. |
MalformedURLException | if the combination of all arguments do not represent a valid URL or the protocol is invalid. |
---|
Creates a new URL instance using the given arguments. The URL uses the specified port instead of the default port for the given protocol.
protocol | the protocol of the new URL. |
---|---|
host | the host name or IP address of the new URL. |
port | the specific port number of the URL. -1 represents the
default port of the protocol. |
file | the name of the resource. |
MalformedURLException | if the combination of all arguments do not represent a valid URL or the protocol is invalid. |
---|
Creates a new URL instance using the given arguments. The URL uses the specified port instead of the default port for the given protocol.
protocol | the protocol of the new URL. |
---|---|
host | the host name or IP address of the new URL. |
port | the specific port number of the URL. -1 represents the
default port of the protocol. |
file | the name of the resource. |
handler | the stream handler to be used by this URL. |
MalformedURLException | if the combination of all arguments do not represent a valid URL or the protocol is invalid. |
---|---|
SecurityException | if handler is non-null , and a security
manager is installed that disallows user-defined protocol
handlers.
|
Compares this URL instance with the given argument o
and
determines if both are equal. Two URL instances are equal if all single
parts are identical in their meaning. Compares the argument to the
receiver, and returns true if they represent the same URL. Two URLs are
equal if they have the same file, host, port, protocol, and reference
components.
o | the URL this instance has to be compared with. |
---|
true
if both instances represents the same URL, false
otherwise.Gets the value of the authority part of this URL.
Gets the content of the resource which is referred by this URL. The
argument types
is an array of allowed or expected object types.
null
will be returned if the obtained object type does not match
with one from this list. Otherwise the first type that matches will be
used.
types | the list of allowed or expected object types. |
---|
null
if the content does not match to a specified content
type.IOException | if an error occurs obtaining the content. |
---|
Gets the content of the resource which is referred by this URL. By default one of the following object types will be returned:
InputStream
for all other dataIOException | if an error occurs obtaining the content. |
---|
Gets the default port number of the protocol used by this URL. If no
default port is defined by the protocol or the URLStreamHandler
,
-1
will be returned.
Gets the value of the file part of this URL.
Gets the value of the host part of this URL.
Gets the value of the path part of this URL.
Gets the port number of this URL or -1
if the port is not set.
Gets the protocol of this URL.
Gets the value of the query part of this URL.
Gets the value of the reference part of this URL.
Gets the value of the user-info part of this URL.
Gets the hashcode value of this URL instance.
Opens a connection to the remote resource specified by this URL. The connection will be established through the given proxy and allows bidirectional data transfer.
proxy | the proxy through which the connection will be established. |
---|
IOException | if an I/O error occurs while opening the connection. |
---|---|
SecurityException | if a security manager is installed and it denies to connect to the proxy. |
IllegalArgumentException | if the argument proxy is null or is an invalid type. |
UnsupportedOperationException | if the protocol handler does not support opening connections through proxies. |
Opens a connection to the remote resource specified by this URL. This connection allows bidirectional data transfer.
IOException | if an error occurs while opening the connection. |
---|
Opens an InputStream to read the resource referred by this URL.
IOException | if an error occurs while opening the InputStream. |
---|
Returns whether this URL refers to the same resource as the given
argument otherURL
. All URL components except the reference field
are compared.
otherURL | the URL to compare against. |
---|
true
if both instances refer to the same resource,
false
otherwise.
Sets the URLStreamHandlerFactory
which creates protocol specific
stream handlers. This method can be invoked only once during an
application's lifetime. If the URLStreamHandlerFactory
is already
set an Error
will be thrown.
A security check is performed to verify whether the current policy allows to set the stream handler factory.
streamFactory | the factory to be used for creating stream protocol handlers. |
---|
Returns a string containing a concise, human-readable representation of this URL.
Returns a string containing a concise, human-readable representation of
this URL. The returned string is the same as the result of the method
toExternalForm()
.
Converts this URL instance into an equivalent URI object.
URISyntaxException | if this URL cannot be converted into a URI. |
---|
Sets the properties of this URL using the provided arguments. Only a
URLStreamHandler
can use this method to set fields of the
existing URL instance. A URL is generally constant.
protocol | the protocol to be set. |
---|---|
host | the host name to be set. |
port | the port number to be set. |
authority | the authority to be set. |
userInfo | the user-info to be set. |
path | the path to be set. |
query | the query to be set. |
ref | the reference to be set. |
Sets the properties of this URL using the provided arguments. Only a
URLStreamHandler
can use this method to set fields of the
existing URL instance. A URL is generally constant.
protocol | the protocol to be set. |
---|---|
host | the host name to be set. |
port | the port number to be set. |
file | the file to be set. |
ref | the reference to be set. |