URI class in Java

java.net.URI

Represents a Uniform Resource Identifier (URI) reference.

The Literal IPv6 address format also supports scope_ids. The syntax and usage of scope_ids are described here. This class provides constructors for creating URI instances from their components or by parsing their string forms, methods for accessing the various components of an instance, and methods for normalizing, resolving, and relativizing URI instances. Instances of this class are immutable.

URI syntax and components At the highest level a URI reference in string form has the syntax

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

where square brackets [...] delineate optional components and the characters: and # stand for themselves. An absolute URI specifies a scheme; a URI that is not absolute is said to be relative. URIs are also classified according to whether they are opaque or hierarchical.

An opaque URI is an absolute URI whose scheme-specific part does not begin with a slash character ('/'). Opaque URIs are not subject to further parsing.

A hierarchical URI is either an absolute URI whose scheme-specific part begins with a slash character, or a relative URI, that is, a URI that does not specify a scheme.

A hierarchical URI is subject to further parsing according to the syntax

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

where the characters:, /, ? and # stand for themselves.

The scheme-specific part of a hierarchical URI consists of the characters between the scheme and fragment components.

The authority component of a hierarchical URI is if specified, either server-based or registry-based.

A server-based authority parses according to the familiar syntax

[user-info@]host[: port]

where the characters @ and: stand for themselves.

Nearly all URI schemes currently in use are server-based. An authority component that does not parse in this way is considered to be registry-based. The path component of a hierarchical URI is itself said to be absolute if it begins with a slash character ('/'); otherwise it is relative. The path of a hierarchical URI that is either absolute or specifies an authority is always absolute.

Some methods of URI class

URI(String)This method constructs a URI by parsing the given string.

URI(String, String, String)This method constructs a URI from the given components. A component may be left undefined by passing null.

URI(String, String, String, String)This method constructs a hierarchical URI from the given components.

URI(String, String, String, String, String)This method constructs a hierarchical URI from the given components. If a scheme is given then the path, if also given, must either be empty or begin with a slash character ('/'). Otherwise, a component of the new URI may be left undefined by passing null for the corresponding parameter.

URI(String, String, String, int, String, String, String)This method constructs a hierarchical URI from the given components. If a scheme is given then the path, if also given, must either be empty or begin with a slash character ('/'). Otherwise, a component of the new URI may be left undefined by passing null for the corresponding parameter or, in the case of the port parameter, bypassing -1.

compareTo(URI)This method compares this URI to another object, which must be a URI.

URI.create(String)This method creates a URI by parsing the given string.

equals(Object)This method tests this URI for equality with another object.

getAuthority()This method returns the decoded authority component of this URI.

getFragment()This method returns the decoded fragment component of this URI.

getHost()This method returns the host component of this URI.

getPath()This method returns the decoded path component of this URI.

getPort()This method returns the port number of this URI.

getQuery()This method returns the decoded query component of this URI.

getRawAuthority()This method returns the raw authority component of this URI.

getRawFragment()This method returns the raw fragment component of this URI.

getRawPath()This method returns the raw path component of this URI.

getRawQuery()This method returns the raw query component of this URI.

getRawSchemeSpecificPart()This method returns the raw scheme-specific part of this URI. The scheme-specific part is never undefined, though it may be empty.

getRawUserInfo()This method returns the raw user-information component of this URI.

getScheme()This method returns the scheme component of this URI.

hashCode()This method returns a hash code value for this URI.

isAbsolute()This method tells whether or not this URI is absolute.

isOpaque()This method tells whether or not this URI is opaque.

normalize()This method normalizes this URI's path.

parseServerAuthority()This method attempts to parse this URI's authority component if defined, into user information, host, and port components.

relativize(URI) This method relativizes the given URI against this URI.

resolve(String)This method constructs a new URI by parsing the given string and then resolving it against this URI.

resolve(URI)This method resolves the given URI against this URI

toASCIIString()This method returns the content of this URI as a US-ASCII string.

toString()This method returns the content of this URI as a string.

toURL()This method constructs a URL from this URI.

No comments:

Post a Comment