DthingApi
Public Member Functions | Protected Member Functions | List of all members
java.net.http.URL Class Reference
Inheritance diagram for java.net.http.URL:
java.io.Serializable

Public Member Functions

 URL (String protocol, String host, String file) throws MalformedURLException
 
 URL (String protocol, String host, int port, String file) throws MalformedURLException
 
 URL (String spec) throws MalformedURLException
 
 URL (URL context, String spec) throws MalformedURLException
 
 URL (URL context, String spec, URLStreamHandler handler) throws MalformedURLException
 
String getQuery ()
 
String getPath ()
 
String getUserInfo ()
 
String getAuthority ()
 
int getPort ()
 
int getDefaultPort ()
 
String getProtocol ()
 
String getHost ()
 
String getFile ()
 
String getRef ()
 
boolean equals (Object obj)
 
synchronized int hashCode ()
 
boolean sameFile (URL other)
 
String toString ()
 
String toExternalForm ()
 
URLConnection openConnection () throws java.io.IOException
 
final InputStream openStream () throws java.io.IOException
 
final Object getContent () throws java.io.IOException
 
final Object getContent (Class[] classes) throws java.io.IOException
 

Protected Member Functions

void set (String protocol, String host, int port, String file, String ref)
 
void set (String protocol, String host, int port, String authority, String userInfo, String path, String query, String ref)
 

Constructor & Destructor Documentation

◆ URL() [1/5]

java.net.http.URL.URL ( String  protocol,
String  host,
String  file 
) throws MalformedURLException
inline

Creates a URL from the specified protocol name, host name, and file name. The default port for the specified protocol is used.

This method is equivalent to calling the four-argument constructor with the arguments being protocol, host, -1, and file.

No validation of the inputs is performed by this constructor.

Parameters
protocolthe name of the protocol to use.
hostthe name of the host.
filethe file on the host.
Exceptions
MalformedURLExceptionif an unknown protocol is specified.
See also
java.net.URL::URL(java.lang.String, java.lang.String, int, java.lang.String)

◆ URL() [2/5]

java.net.http.URL.URL ( String  protocol,
String  host,
int  port,
String  file 
) throws MalformedURLException
inline

Creates a URL object from the specified protocol, host, port number, file, and handler. Specifying a port number of -1 indicates that the URL should use the default port for the protocol. Specifying a handler of null indicates that the URL should use a default stream handler for the protocol, as outlined for: java.net.URL::URL(java.lang.String, java.lang.String, int, java.lang.String)

If the handler is not null and there is a security manager, the security manager's checkPermission method is called with a NetPermission("specifyStreamHandler") permission. This may result in a SecurityException.

No validation of the inputs is performed by this constructor.

Parameters
protocolthe name of the protocol to use.
hostthe name of the host.
portthe port number on the host.
filethe file on the host
handlerthe stream handler for the URL.
Exceptions
MalformedURLException
MalformedURLExceptionif an unknown protocol is specified.
SecurityExceptionif a security manager exists and its checkPermission method doesn't allow specifying a stream handler explicitly.
See also
java.lang.System::getProperty(java.lang.String)
java.net.URL::setURLStreamHandlerFactory( java.net.URLStreamHandlerFactory)
java.net.URLStreamHandler
java.net.URLStreamHandlerFactory::createURLStreamHandler( java.lang.String)
SecurityManager::checkPermission
java.net.NetPermission

if host is a literal IPv6 address, we will make it conform to RFC 2732

◆ URL() [3/5]

java.net.http.URL.URL ( String  spec) throws MalformedURLException
inline

Creates a URL object from the String representation.

This constructor is equivalent to a call to the two-argument constructor with a null first argument.

Parameters
specthe String to parse as a URL.
Exceptions
MalformedURLExceptionIf the string specifies an unknown protocol.
See also
java.net.URL::URL(java.net.URL, java.lang.String)

◆ URL() [4/5]

java.net.http.URL.URL ( URL  context,
String  spec 
) throws MalformedURLException
inline

Creates a URL by parsing the given spec within a specified context.

The new URL is created from the given context URL and the spec argument as described in RFC2396 "Uniform Resource Identifiers : Generic * Syntax" :

         <scheme>://<authority><path>?<query>#<fragment>

The reference is parsed into the scheme, authority, path, query and fragment parts. If the path component is empty and the scheme, authority, and query components are undefined, then the new URL is a reference to the current document. Otherwise, the fragment and query parts present in the spec are used in the new URL.

If the scheme component is defined in the given spec and does not match the scheme of the context, then the new URL is created as an absolute URL based on the spec alone. Otherwise the scheme component is inherited from the context URL.

If the authority component is present in the spec then the spec is treated as absolute and the spec authority and path will replace the context authority and path. If the authority component is absent in the spec then the authority of the new URL will be inherited from the context.

If the spec's path component begins with a slash character "/" then the path is treated as absolute and the spec path replaces the context path.

Otherwise, the path is treated as a relative path and is appended to the context path, as described in RFC2396. Also, in this case, the path is canonicalized through the removal of directory changes made by occurences of ".." and ".".

For a more detailed description of URL parsing, refer to RFC2396.

Parameters
contextthe context in which to parse the specification.
specthe String to parse as a URL.
Exceptions
MalformedURLExceptionif no protocol is specified, or an unknown protocol is found.
See also
java.net.URL::URL(java.lang.String, java.lang.String, int, java.lang.String)
java.net.URLStreamHandler
java.net.URLStreamHandler::parseURL(java.net.URL, java.lang.String, int, int)

◆ URL() [5/5]

java.net.http.URL.URL ( URL  context,
String  spec,
URLStreamHandler  handler 
) throws MalformedURLException
inline

Creates a URL by parsing the given spec with the specified handler within a specified context. If the handler is null, the parsing occurs as with the two argument constructor.

Parameters
contextthe context in which to parse the specification.
specthe String to parse as a URL.
handlerthe stream handler for the URL.
Exceptions
MalformedURLExceptionif no protocol is specified, or an unknown protocol is found.
SecurityExceptionif a security manager exists and its checkPermission method doesn't allow specifying a stream handler.
See also
java.net.URL::URL(java.lang.String, java.lang.String, int, java.lang.String)
java.net.URLStreamHandler
java.net.URLStreamHandler::parseURL(java.net.URL, java.lang.String, int, int)

Member Function Documentation

◆ equals()

boolean java.net.http.URL.equals ( Object  obj)
inline

Compares this URL for equality with another object.

If the given object is not a URL then this method immediately returns false.

Two URL objects are equal if they have the same protocol, reference equivalent hosts, have the same port number on the host, and the same file and fragment of the file.

Two hosts are considered equivalent if both host names can be resolved into the same IP addresses; else if either host name can't be resolved, the host names must be equal without regard to case; or both host names equal to null.

Since hosts comparison requires name resolution, this operation is a blocking operation.

Note: The defined behavior for equals is known to be inconsistent with virtual hosting in HTTP.

Parameters
objthe URL to compare against.
Returns
true if the objects are the same; false otherwise.

◆ getAuthority()

String java.net.http.URL.getAuthority ( )
inline

Gets the authority part of this URL.

Returns
the authority part of this URL
Since
1.3

◆ getContent() [1/2]

final Object java.net.http.URL.getContent ( ) throws java.io.IOException
inline

Gets the contents of this URL. This method is a shorthand for:

    openConnection().getContent()
Returns
the contents of this URL.
Exceptions
IOExceptionif an I/O exception occurs.
See also
java.net.URLConnection::getContent()

◆ getContent() [2/2]

final Object java.net.http.URL.getContent ( Class []  classes) throws java.io.IOException
inline

Gets the contents of this URL. This method is a shorthand for:

    openConnection().getContent(Class[])
Parameters
classesan array of Java types
Returns
the content object of this URL that is the first match of the types specified in the classes array. null if none of the requested types are supported.
Exceptions
IOExceptionif an I/O exception occurs.
See also
java.net.URLConnection::getContent(Class[])
Since
1.3

◆ getDefaultPort()

int java.net.http.URL.getDefaultPort ( )
inline

Gets the default port number of the protocol associated with this URL. If the URL scheme or the URLStreamHandler for the URL do not define a default port number, then -1 is returned.

Returns
the port number

◆ getFile()

String java.net.http.URL.getFile ( )
inline

Gets the file name of this URL. The returned file portion will be the same as getPath(), plus the concatenation of the value of getQuery(), if any. If there is no query portion, this method and getPath() will return identical results.

Returns
the file name of this URL, or an empty string if one does not exist

◆ getHost()

String java.net.http.URL.getHost ( )
inline

Gets the host name of this URL, if applicable. The format of the host conforms to RFC 2732, i.e. for a literal IPv6 address, this method will return the IPv6 address enclosed in square brackets ('[' and ']').

Returns
the host name of this URL.

◆ getPath()

String java.net.http.URL.getPath ( )
inline

Gets the path part of this URL.

Returns
the path part of this URL, or an empty string if one does not exist
Since
1.3

◆ getPort()

int java.net.http.URL.getPort ( )
inline

Gets the port number of this URL.

Returns
the port number, or -1 if the port is not set

◆ getProtocol()

String java.net.http.URL.getProtocol ( )
inline

Gets the protocol name of this URL.

Returns
the protocol of this URL.

◆ getQuery()

String java.net.http.URL.getQuery ( )
inline

Gets the query part of this URL.

Returns
the query part of this URL, or null if one does not exist
Since
1.3

◆ getRef()

String java.net.http.URL.getRef ( )
inline

Gets the anchor (also known as the "reference") of this URL.

Returns
the anchor (also known as the "reference") of this URL, or null if one does not exist

◆ getUserInfo()

String java.net.http.URL.getUserInfo ( )
inline

Gets the userInfo part of this URL.

Returns
the userInfo part of this URL, or null if one does not exist

◆ hashCode()

synchronized int java.net.http.URL.hashCode ( )
inline

modify ok

◆ openConnection()

URLConnection java.net.http.URL.openConnection ( ) throws java.io.IOException
inline

Returns a URLConnection object that represents a connection to the remote object referred to by the URL.

A new connection is opened every time by calling the openConnection method of the protocol handler for this URL.

If for the URL's protocol (such as HTTP or JAR), there exists a public, specialized URLConnection subclass belonging to one of the following packages or one of their subpackages: java.lang, java.io, java.util, java.net, the connection returned will be of that subclass. For example, for HTTP an HttpURLConnection will be returned, and for JAR a JarURLConnection will be returned. NOTE: java.net.HttpURLConnection is found in J2ME CDC profiles such as J2ME Foundation Profile. Subclasses of these should

Returns
a URLConnection to the URL.
Exceptions
IOExceptionif an I/O exception occurs.
See also
java.net.URL::URL(java.lang.String, java.lang.String, int, java.lang.String)
java.net.URLConnection
java.net.URLStreamHandler::openConnection(java.net.URL)

◆ openStream()

final InputStream java.net.http.URL.openStream ( ) throws java.io.IOException
inline

Opens a connection to this URL and returns an InputStream for reading from that connection. This method is a shorthand for:

    openConnection().getInputStream()
Returns
an input stream for reading from the URL connection.
Exceptions
IOExceptionif an I/O exception occurs.
See also
java.net.URL::openConnection()
java.net.URLConnection::getInputStream()

◆ sameFile()

boolean java.net.http.URL.sameFile ( URL  other)
inline

Compares two URLs, excluding the fragment component.

Returns true if this URL and the other argument are equal without taking the fragment component into consideration.

Parameters
otherthe URL to compare against.
Returns
true if they reference the same remote object; false otherwise.

◆ set() [1/2]

void java.net.http.URL.set ( String  protocol,
String  host,
int  port,
String  file,
String  ref 
)
inlineprotected

Sets the fields of the URL. This is not a public method so that only URLStreamHandlers can modify URL fields. URLs are otherwise constant.

Parameters
protocolthe name of the protocol to use
hostthe name of the host
portthe port number on the host
filethe file on the host
refthe internal reference in the URL

◆ set() [2/2]

void java.net.http.URL.set ( String  protocol,
String  host,
int  port,
String  authority,
String  userInfo,
String  path,
String  query,
String  ref 
)
inlineprotected

Sets the specified 8 fields of the URL. This is not a public method so that only URLStreamHandlers can modify URL fields. URLs are otherwise constant.

Parameters
protocolthe name of the protocol to use
hostthe name of the host
portthe port number on the host
authoritythe authority part for the url
userInfothe username and password
paththe file on the host
refthe internal reference in the URL
querythe query part of this URL
Since
1.3

◆ toExternalForm()

String java.net.http.URL.toExternalForm ( )
inline

Constructs a string representation of this URL. The string is created by calling the toExternalForm method of the stream protocol handler for this object.

Returns
a string representation of this object.
See also
java.net.URL::URL(java.lang.String, java.lang.String, int, java.lang.String)
java.net.URLStreamHandler::toExternalForm(java.net.URL)

◆ toString()

String java.net.http.URL.toString ( )
inline

modify ok


The documentation for this class was generated from the following file: