public final class

URI

extends Object
implements Serializable Comparable<T>
java.lang.Object
   ↳ java.net.URI

Class Overview

This class represents an instance of a URI as defined by RFC 2396.

Summary

Public Constructors
URI(String uri)
Creates a new URI instance according to the given string uri.
URI(String scheme, String ssp, String frag)
Creates a new URI instance using the given arguments.
URI(String scheme, String userinfo, String host, int port, String path, String query, String fragment)
Creates a new URI instance using the given arguments.
URI(String scheme, String host, String path, String fragment)
Creates a new URI instance using the given arguments.
URI(String scheme, String authority, String path, String query, String fragment)
Creates a new URI instance using the given arguments.
Public Methods
int compareTo(URI uri)
Compares this URI with the given argument uri.
static URI create(String uri)
Parses the given argument uri and creates an appropriate URI instance.
boolean equals(Object o)
Compares this URI instance with the given argument o and determines if both are equal.
String getAuthority()
Gets the decoded authority part of this URI.
String getFragment()
Gets the decoded fragment part of this URI.
String getHost()
Gets the host part of this URI.
String getPath()
Gets the decoded path part of this URI.
int getPort()
Gets the port number of this URI.
String getQuery()
Gets the decoded query part of this URI.
String getRawAuthority()
Gets the authority part of this URI in raw form.
String getRawFragment()
Gets the fragment part of this URI in raw form.
String getRawPath()
Gets the path part of this URI in raw form.
String getRawQuery()
Gets the query part of this URI in raw form.
String getRawSchemeSpecificPart()
Gets the scheme-specific part of this URI in raw form.
String getRawUserInfo()
Gets the user-info part of this URI in raw form.
String getScheme()
Gets the scheme part of this URI.
String getSchemeSpecificPart()
Gets the decoded scheme-specific part of this URI.
String getUserInfo()
Gets the decoded user-info part of this URI.
int hashCode()
Gets the hashcode value of this URI instance.
boolean isAbsolute()
Indicates whether this URI is absolute, which means that a scheme part is defined in this URI.
boolean isOpaque()
Indicates whether this URI is opaque or not.
URI normalize()
Normalizes the path part of this URI.
URI parseServerAuthority()
Tries to parse the authority component of this URI to divide it into the host, port, and user-info.
URI relativize(URI relative)
Makes the given URI relative to a relative URI against the URI represented by this instance.
URI resolve(URI relative)
Resolves the given URI relative against the URI represented by this instance.
URI resolve(String relative)
Creates a new URI instance by parsing the given string relative and resolves the created URI against the URI represented by this instance.
String toASCIIString()
Returns the textual string representation of this URI instance using the US-ASCII encoding.
String toString()
Returns the textual string representation of this URI instance.
URL toURL()
Converts this URI instance to a URL.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.Comparable

Public Constructors

public URI (String uri)

Since: API Level 1

Creates a new URI instance according to the given string uri.

Parameters
uri the textual URI representation to be parsed into a URI object.
Throws
URISyntaxException if the given string uri doesn't fit to the specification RFC2396 or could not be parsed correctly.

public URI (String scheme, String ssp, String frag)

Since: API Level 1

Creates a new URI instance using the given arguments. This constructor first creates a temporary URI string from the given components. This string will be parsed later on to create the URI instance.

[scheme:]scheme-specific-part[#fragment]

Parameters
scheme the scheme part of the URI.
ssp the scheme-specific-part of the URI.
frag the fragment part of the URI.
Throws
URISyntaxException if the temporary created string doesn't fit to the specification RFC2396 or could not be parsed correctly.

public URI (String scheme, String userinfo, String host, int port, String path, String query, String fragment)

Since: API Level 1

Creates a new URI instance using the given arguments. This constructor first creates a temporary URI string from the given components. This string will be parsed later on to create the URI instance.

[scheme:][user-info@]host[:port][path][?query][#fragment]

Parameters
scheme the scheme part of the URI.
userinfo the user information of the URI for authentication and authorization.
host the host name of the URI.
port the port number of the URI.
path the path to the resource on the host.
query the query part of the URI to specify parameters for the resource.
fragment the fragment part of the URI.
Throws
URISyntaxException if the temporary created string doesn't fit to the specification RFC2396 or could not be parsed correctly.

public URI (String scheme, String host, String path, String fragment)

Since: API Level 1

Creates a new URI instance using the given arguments. This constructor first creates a temporary URI string from the given components. This string will be parsed later on to create the URI instance.

[scheme:]host[path][#fragment]

Parameters
scheme the scheme part of the URI.
host the host name of the URI.
path the path to the resource on the host.
fragment the fragment part of the URI.
Throws
URISyntaxException if the temporary created string doesn't fit to the specification RFC2396 or could not be parsed correctly.

public URI (String scheme, String authority, String path, String query, String fragment)

Since: API Level 1

Creates a new URI instance using the given arguments. This constructor first creates a temporary URI string from the given components. This string will be parsed later on to create the URI instance.

[scheme:][//authority][path][?query][#fragment]

Parameters
scheme the scheme part of the URI.
authority the authority part of the URI.
path the path to the resource on the host.
query the query part of the URI to specify parameters for the resource.
fragment the fragment part of the URI.
Throws
URISyntaxException if the temporary created string doesn't fit to the specification RFC2396 or could not be parsed correctly.

Public Methods

public int compareTo (URI uri)

Since: API Level 1

Compares this URI with the given argument uri. This method will return a negative value if this URI instance is less than the given argument and a positive value if this URI instance is greater than the given argument. The return value 0 indicates that the two instances represent the same URI. To define the order the single parts of the URI are compared with each other. String components will be orderer in the natural case-sensitive way. A hierarchical URI is less than an opaque URI and if one part is null the URI with the undefined part is less than the other one.

Parameters
uri the URI this instance has to compare with.
Returns
  • the value representing the order of the two instances.

public static URI create (String uri)

Since: API Level 1

Parses the given argument uri and creates an appropriate URI instance.

Parameters
uri the string which has to be parsed to create the URI instance.
Returns
  • the created instance representing the given URI.

public boolean equals (Object o)

Since: API Level 1

Compares this URI instance with the given argument o and determines if both are equal. Two URI instances are equal if all single parts are identical in their meaning.

Parameters
o the URI this instance has to be compared with.
Returns
  • true if both URI instances point to the same resource, false otherwise.

public String getAuthority ()

Since: API Level 1

Gets the decoded authority part of this URI.

Returns
  • the decoded authority part or null if undefined.

public String getFragment ()

Since: API Level 1

Gets the decoded fragment part of this URI.

Returns
  • the decoded fragment part or null if undefined.

public String getHost ()

Since: API Level 1

Gets the host part of this URI.

Returns
  • the host part or null if undefined.

public String getPath ()

Since: API Level 1

Gets the decoded path part of this URI.

Returns
  • the decoded path part or null if undefined.

public int getPort ()

Since: API Level 1

Gets the port number of this URI.

Returns
  • the port number or -1 if undefined.

public String getQuery ()

Since: API Level 1

Gets the decoded query part of this URI.

Returns
  • the decoded query part or null if undefined.

public String getRawAuthority ()

Since: API Level 1

Gets the authority part of this URI in raw form.

Returns
  • the encoded authority part or null if undefined.

public String getRawFragment ()

Since: API Level 1

Gets the fragment part of this URI in raw form.

Returns
  • the encoded fragment part or null if undefined.

public String getRawPath ()

Since: API Level 1

Gets the path part of this URI in raw form.

Returns
  • the encoded path part or null if undefined.

public String getRawQuery ()

Since: API Level 1

Gets the query part of this URI in raw form.

Returns
  • the encoded query part or null if undefined.

public String getRawSchemeSpecificPart ()

Since: API Level 1

Gets the scheme-specific part of this URI in raw form.

Returns
  • the encoded scheme-specific part or null if undefined.

public String getRawUserInfo ()

Since: API Level 1

Gets the user-info part of this URI in raw form.

Returns
  • the encoded user-info part or null if undefined.

public String getScheme ()

Since: API Level 1

Gets the scheme part of this URI.

Returns
  • the scheme part or null if undefined.

public String getSchemeSpecificPart ()

Since: API Level 1

Gets the decoded scheme-specific part of this URI.

Returns
  • the decoded scheme-specific part or null if undefined.

public String getUserInfo ()

Since: API Level 1

Gets the decoded user-info part of this URI.

Returns
  • the decoded user-info part or null if undefined.

public int hashCode ()

Since: API Level 1

Gets the hashcode value of this URI instance.

Returns
  • the appropriate hashcode value.

public boolean isAbsolute ()

Since: API Level 1

Indicates whether this URI is absolute, which means that a scheme part is defined in this URI.

Returns
  • true if this URI is absolute, false otherwise.

public boolean isOpaque ()

Since: API Level 1

Indicates whether this URI is opaque or not. An opaque URI is absolute and has a scheme-specific part which does not start with a slash character. All parts except scheme, scheme-specific and fragment are undefined.

Returns
  • true if the URI is opaque, false otherwise.

public URI normalize ()

Since: API Level 1

Normalizes the path part of this URI.

Returns
  • an URI object which represents this instance with a normalized path.

public URI parseServerAuthority ()

Since: API Level 1

Tries to parse the authority component of this URI to divide it into the host, port, and user-info. If this URI is already determined as a ServerAuthority this instance will be returned without changes.

Returns
  • this instance with the components of the parsed server authority.
Throws
URISyntaxException if the authority part could not be parsed as a server-based authority.

public URI relativize (URI relative)

Since: API Level 1

Makes the given URI relative to a relative URI against the URI represented by this instance.

Parameters
relative the URI which has to be relativized against this URI.
Returns
  • the relative URI.

public URI resolve (URI relative)

Since: API Level 1

Resolves the given URI relative against the URI represented by this instance.

Parameters
relative the URI which has to be resolved against this URI.
Returns
  • the resolved URI.

public URI resolve (String relative)

Since: API Level 1

Creates a new URI instance by parsing the given string relative and resolves the created URI against the URI represented by this instance.

Parameters
relative the given string to create the new URI instance which has to be resolved later on.
Returns
  • the created and resolved URI.

public String toASCIIString ()

Since: API Level 1

Returns the textual string representation of this URI instance using the US-ASCII encoding.

Returns
  • the US-ASCII string representation of this URI.

public String toString ()

Since: API Level 1

Returns the textual string representation of this URI instance.

Returns
  • the textual string representation of this URI.

public URL toURL ()

Since: API Level 1

Converts this URI instance to a URL.

Returns
  • the created URL representing the same resource as this URI.
Throws
MalformedURLException if an error occurs while creating the URL or no protocol handler could be found.