GeezerVison is showing docs.oracle.com — URI (Java SE 11 & JDK 11 )
-
-
Constructor Summary
Constructors
| Constructor |
Description |
URI(String str) |
Constructs a URI by parsing the given string.
|
URI(String scheme,
String ssp,
String fragment) |
Constructs a URI from the given components.
|
URI(String scheme,
String userInfo,
String host,
int port,
String path,
String query,
String fragment) |
Constructs a hierarchical URI from the given components.
|
URI(String scheme,
String host,
String path,
String fragment) |
Constructs a hierarchical URI from the given components.
|
URI(String scheme,
String authority,
String path,
String query,
String fragment) |
Constructs a hierarchical URI from the given components.
|
-
-
Constructor Detail
-
URI
public URI(String scheme,
String userInfo,
String host,
int port,
String path,
String query,
String fragment)
throws URISyntaxException
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, by passing -1.
This constructor first builds a URI string from the given components
according to the rules specified in RFC 2396,
section 5.2, step 7:
Initially, the result string is empty.
If a scheme is given then it is appended to the result,
followed by a colon character (':').
If user information, a host, or a port are given then the
string "//" is appended.
If user information is given then it is appended, followed by
a commercial-at character ('@'). Any character not in the
unreserved, punct, escaped, or other
categories is quoted.
If a host is given then it is appended. If the host is a
literal IPv6 address but is not enclosed in square brackets
('[' and ']') then the square brackets are added.
If a port number is given then a colon character
(':') is appended, followed by the port number in decimal.
If a path is given then it is appended. Any character not in
the unreserved, punct, escaped, or other
categories, and not equal to the slash character ('/') or the
commercial-at character ('@'), is quoted.
If a query is given then a question-mark character
('?') is appended, followed by the query. Any character that
is not a legal URI character is quoted.
Finally, if a fragment is given then a hash character
('#') is appended, followed by the fragment. Any character
that is not a legal URI character is quoted.
The resulting URI string is then parsed as if by invoking the URI(String) constructor and then invoking the parseServerAuthority() method upon the result; this may cause a URISyntaxException to be thrown.
- Parameters:
scheme - Scheme name
userInfo - User name and authorization information
host - Host name
port - Port number
path - Path
query - Query
fragment - Fragment
- Throws:
URISyntaxException - If both a scheme and a path are given but the path is relative,
if the URI string constructed from the given components violates
RFC 2396, or if the authority component of the string is
present but cannot be parsed as a server-based authority
-
URI
public URI(String scheme,
String authority,
String path,
String query,
String fragment)
throws URISyntaxException
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.
This constructor first builds a URI string from the given components
according to the rules specified in RFC 2396,
section 5.2, step 7:
Initially, the result string is empty.
If a scheme is given then it is appended to the result,
followed by a colon character (':').
If an authority is given then the string "//" is
appended, followed by the authority. If the authority contains a
literal IPv6 address then the address must be enclosed in square
brackets ('[' and ']'). Any character not in the
unreserved, punct, escaped, or other
categories, and not equal to the commercial-at character
('@'), is quoted.
If a path is given then it is appended. Any character not in
the unreserved, punct, escaped, or other
categories, and not equal to the slash character ('/') or the
commercial-at character ('@'), is quoted.
If a query is given then a question-mark character
('?') is appended, followed by the query. Any character that
is not a legal URI character is quoted.
Finally, if a fragment is given then a hash character
('#') is appended, followed by the fragment. Any character
that is not a legal URI character is quoted.
The resulting URI string is then parsed as if by invoking the URI(String) constructor and then invoking the parseServerAuthority() method upon the result; this may cause a URISyntaxException to be thrown.
- Parameters:
scheme - Scheme name
authority - Authority
path - Path
query - Query
fragment - Fragment
- Throws:
URISyntaxException - If both a scheme and a path are given but the path is relative,
if the URI string constructed from the given components violates
RFC 2396, or if the authority component of the string is
present but cannot be parsed as a server-based authority
-
Method Detail
-
normalize
public URI normalize()
Normalizes this URI's path.
If this URI is opaque, or if its path is already in normal form,
then this URI is returned. Otherwise a new URI is constructed that is
identical to this URI except that its path is computed by normalizing
this URI's path in a manner consistent with RFC 2396,
section 5.2, step 6, sub-steps c through f; that is:
All "." segments are removed.
If a ".." segment is preceded by a non-".."
segment then both of these segments are removed. This step is
repeated until it is no longer applicable.
If the path is relative, and if its first segment contains a
colon character (':'), then a "." segment is
prepended. This prevents a relative URI with a path such as
"a:b/c/d" from later being re-parsed as an opaque URI with a
scheme of "a" and a scheme-specific part of "b/c/d".
(Deviation from RFC 2396)
A normalized path will begin with one or more ".." segments
if there were insufficient non-".." segments preceding them to
allow their removal. A normalized path will begin with a "."
segment if one was inserted by step 3 above. Otherwise, a normalized
path will not contain any "." or ".." segments.
- Returns:
- A URI equivalent to this URI,
but whose path is in normal form
-
getHost
public String getHost()
Returns the host component of this URI.
The host component of a URI, if defined, will have one of the
following forms:
A domain name consisting of one or more labels
separated by period characters ('.'), optionally followed by
a period character. Each label consists of alphanum characters
as well as hyphen characters ('-'), though hyphens never
occur as the first or last characters in a label. The rightmost
label of a domain name consisting of two or more labels, begins
with an alpha character.
A dotted-quad IPv4 address of the form
digit+.digit+.digit+.digit+,
where no digit sequence is longer than three characters and no
sequence has a value larger than 255.
An IPv6 address enclosed in square brackets ('[' and
']') and consisting of hexadecimal digits, colon characters
(':'), and possibly an embedded IPv4 address. The full
syntax of IPv6 addresses is specified in RFC 2373: IPv6
Addressing Architecture.
The host component of a URI cannot contain escaped octets, hence this
method does not perform any decoding.
- Returns:
- The host component of this URI,
or
null if the host is undefined
-
getPort
public int getPort()
Returns the port number of this URI.
The port component of a URI, if defined, is a non-negative
integer.
- Returns:
- The port component of this URI,
or
-1 if the port is undefined
-
getPath
public String getPath()
Returns the decoded path component of this URI.
The string returned by this method is equal to that returned by the
getRawPath method except that all sequences of
escaped octets are decoded.
- Returns:
- The decoded path component of this URI,
or
null if the path is undefined
-
getQuery
public String getQuery()
Returns the decoded query component of this URI.
The string returned by this method is equal to that returned by the
getRawQuery method except that all sequences of
escaped octets are decoded.
- Returns:
- The decoded query component of this URI,
or
null if the query is undefined
-
toString
public String toString()
Returns the content of this URI as a string.
If this URI was created by invoking one of the constructors in this
class then a string equivalent to the original input string, or to the
string computed from the originally-given components, as appropriate, is
returned. Otherwise this URI was created by normalization, resolution,
or relativization, and so a string is constructed from this URI's
components according to the rules specified in RFC 2396,
section 5.2, step 7.
- Overrides:
toString in class Object
- Returns:
- The string form of this URI
|