public final class Uri extends Object implements Comparable<Uri>
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Uri uri)
Compares this URI with the given argument
uri . |
static Uri |
create(String rfc3986compliantURI)
Parses the given argument
rfc3986compliantURI 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. |
static Uri |
escapeAndCreate(String unescapedString)
The parameter string doesn't contain any existing escape sequences, any
escape character % found is encoded as %25.
|
static Uri |
filePathToUri(String path) |
static Uri |
fileToUri(File file) |
static String |
fixWindowsURI(String uri)
Fixes windows file URI string by converting back slashes to forward
slashes and inserting a forward slash before the drive letter if it is
missing.
|
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 |
implies(Uri implied)
Indicates whether the specified Uri is implied by this
Uri . |
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.
|
static Uri |
parseAndCreate(String nonCompliantEscapedString)
The parameter string may already contain escaped sequences, any illegal
characters are escaped and any that shouldn't be escaped are un-escaped.
|
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(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. |
Uri |
resolve(Uri relative)
Resolves the given URI
relative 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.
|
static File |
uriToFile(Uri uri) |
static URI |
uriToURI(Uri uri) |
static Uri |
urlToUri(URL url) |
public Uri(String uri) throws URISyntaxException
uri
.
The URI must strictly conform to RFC3986, it doesn't support extended
characters sets like java.net.URI, instead all non ASCII characters
must be escaped.
Any encoded unreserved characters are decoded.uri
- the textual URI representation to be parsed into a URI object.URISyntaxException
- if the given string uri
doesn't fit to the
specification RF3986 or could not be parsed correctly.public Uri(String scheme, String ssp, String frag) throws URISyntaxException
[scheme:]scheme-specific-part[#fragment]
scheme
- the scheme part of the URI.ssp
- the scheme-specific-part of the URI.frag
- the fragment part of the URI.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) throws URISyntaxException
[scheme:][user-info@]host[:port][path][?query][#fragment]
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.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) throws URISyntaxException
[scheme:]host[path][#fragment]
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.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) throws URISyntaxException
[scheme:][//authority][path][?query][#fragment]
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.URISyntaxException
- if the temporary created string doesn't fit to the
specification RFC2396 or could not be parsed correctly.public static String fixWindowsURI(String uri)
uri
- String representation of URIpublic static Uri urlToUri(URL url) throws URISyntaxException
URISyntaxException
public static Uri fileToUri(File file) throws URISyntaxException
URISyntaxException
public static Uri filePathToUri(String path) throws URISyntaxException
URISyntaxException
public int compareTo(Uri uri)
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.compareTo
in interface Comparable<Uri>
uri
- the URI this instance has to compare with.public static Uri create(String rfc3986compliantURI)
rfc3986compliantURI
and creates an appropriate URI
instance.
The parameter string is checked for compliance, an IllegalArgumentException
is thrown if the string is non compliant.rfc3986compliantURI
- the string which has to be parsed to create the URI instance.public static Uri escapeAndCreate(String unescapedString) throws URISyntaxException
unescapedString
- URI in un-escaped string formURISyntaxException
- if string cannot be escaped.public static Uri parseAndCreate(String nonCompliantEscapedString) throws URISyntaxException
nonCompliantEscapedString
- URI in string from.URISyntaxException
- if string cannot be escaped.public boolean equals(Object o)
o
and
determines if both are equal. Two URI instances are equal if all single
parts are identical in their meaning.public boolean implies(Uri implied)
Indicates whether the specified Uri is implied by this Uri
. Returns true
if all of the following conditions are
true
, otherwise false
:
null
implied
's scheme.
null
, the
following conditions are checked
cs
's host is not null
Uri
's
host matches implied
's host.
Uri
's port != -1 the port of implied
's location is equal to this Uri
's port
Uri
's path matches implied
's path
whereas special wildcard matching applies as described below.
Uri
's path ends with "/-"
,
then implied
's path must start with Uri
's path
(exclusive the trailing '-')
Uri
's path ends with "/*"
,
then implied
's path must start with Uri
's path
(exclusive the trailing '*') and must not have any further '/'
Uri
's path ends with "/"
,
then implied
's path must start with Uri
's path
Uri
's path does not end with "/"
, then implied
's path must start with Uri
's
path with the '/' appended to it.
http: http://*/milestones/M9/* http://*.apache.org/milestones/M9/* http://harmony.apache.org/milestones/- http://harmony.apache.org/milestones/M9/apache-harmony.jar
implied
- the Uri to check.true
if the argument is implied by this
Uri
, otherwise false
.public String getAuthority()
null
if undefined.public String getFragment()
null
if undefined.public String getHost()
null
if undefined.public String getPath()
null
if undefined.public int getPort()
-1
if undefined.public String getQuery()
null
if undefined.public String getRawAuthority()
null
if undefined.public String getRawFragment()
null
if undefined.public String getRawPath()
null
if undefined.public String getRawQuery()
null
if undefined.public String getRawSchemeSpecificPart()
null
if undefined.public String getRawUserInfo()
null
if undefined.public String getScheme()
null
if undefined.public String getSchemeSpecificPart()
null
if undefined.public String getUserInfo()
null
if undefined.public int hashCode()
public boolean isAbsolute()
true
if this URI is absolute, false
otherwise.public boolean isOpaque()
true
if the URI is opaque, false
otherwise.public Uri normalize()
public Uri parseServerAuthority() throws URISyntaxException
URISyntaxException
- if the authority part could not be parsed as a server-based
authority.public Uri relativize(Uri relative)
relative
to a relative URI against the URI
represented by this instance.relative
- the URI which has to be relativized against this URI.public Uri resolve(Uri relative)
relative
against the URI represented by
this instance.relative
- the URI which has to be resolved against this URI.public Uri resolve(String relative)
relative
and resolves the created URI against the URI represented by this
instance.relative
- the given string to create the new URI instance which has to
be resolved later on.public String toASCIIString()
public String toString()
public URL toURL() throws MalformedURLException
MalformedURLException
- if an error occurs while creating the URL or no protocol
handler could be found.Copyright © 2016–2018 The Apache Software Foundation. All rights reserved.