public final class Uri extends Object implements Comparable<Uri>
Modifier and Type | Field and Description |
---|---|
private static char |
a |
private static char |
A |
private boolean |
absolute |
(package private) static String |
allLegal |
(package private) static String |
allLegalUnescaped |
private String |
authority |
(package private) static String |
authorityLegal |
private static char |
escape |
private boolean |
fileSchemeCaseInsensitiveOS |
private String |
fragment |
private int |
hash |
private String |
hashString |
private String |
host |
(package private) static String |
hostRegNameLegal |
(package private) static String |
iPvFuture |
private static char |
lowerCaseBitwiseMask |
private boolean |
opaque |
private String |
path |
(package private) static String |
pathLegal |
(package private) static String |
pcharLegal |
private int |
port |
(package private) static String |
punct |
private String |
query |
(package private) static String |
queryFragLegal |
(package private) static String |
queryLegal |
(package private) static String |
reserved |
private String |
scheme |
(package private) static String |
schemeLegal |
private String |
schemespecificpart |
(package private) static String |
segmentLegal |
(package private) static String |
segmentNzNcLegal |
private boolean |
serverAuthority |
(package private) static String |
someLegal |
private String |
string |
(package private) static String |
unreserved |
private static char |
upperCaseBitwiseMask |
private String |
userinfo |
(package private) static String |
userinfoLegal |
private static char |
z |
private static char |
Z |
Modifier | 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.
|
private |
Uri(String string,
String scheme,
String schemespecificpart,
String authority,
String userinfo,
String host,
int port,
String path,
String query,
String fragment,
boolean opaque,
boolean absolute,
boolean serverAuthority,
int hash,
boolean fileSchemeCaseInsensitiveOS) |
private |
Uri(UriParser p)
Private constructor that doesn't throw URISyntaxException, all public
constructors are designed to avoid finalizer attacks by calling static
methods that throw URISyntaxException, just in case we
decide to make this class non final at some point in future.
|
Modifier and Type | Method and Description |
---|---|
(package private) static boolean |
asciiStringsLowerCaseEqual(String a,
String b) |
(package private) static boolean |
asciiStringsUpperCaseEqual(String a,
String b) |
(package private) static boolean |
charArraysEqual(char[] a,
char[] b) |
int |
compareTo(Uri uri)
Compares this URI with the given argument
uri . |
private static UriParser |
constructor1(String uri) |
private static UriParser |
constructor2(String scheme,
String ssp,
String frag) |
private static UriParser |
constructor3(String scheme,
String userinfo,
String host,
int port,
String path,
String query,
String fragment) |
private static UriParser |
constructor4(String scheme,
String authority,
String path,
String query,
String fragment) |
private String |
convertHexToUpperCase(String s) |
static Uri |
create(String rfc3986compliantURI)
Parses the given argument
rfc3986compliantURI and creates an appropriate URI
instance. |
private String |
decode(String s) |
private String |
encodeOthers(String s) |
boolean |
equals(Object o)
Compares this URI instance with the given argument
o and
determines if both are equal. |
private boolean |
equalsHexCaseInsensitive(String first,
String second) |
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.
|
private String |
getHashString() |
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.
|
private String |
normalize(String path) |
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.
|
private static String |
quoteComponent(String component,
String legalset) |
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. |
private String |
setSchemeSpecificPart(String authority,
String path,
String query)
UriParser method used to re-calculate the scheme specific part of the
resolved or normalized URIs
|
(package private) static char |
toAsciiLowerCase(char c) |
(package private) static char[] |
toAsciiLowerCase(char[] array) |
(package private) static String |
toAsciiLowerCase(String s) |
String |
toASCIIString()
Returns the textual string representation of this URI instance using the
US-ASCII encoding.
|
(package private) static char |
toAsciiUpperCase(char c) |
(package private) static char[] |
toAsciiUpperCase(char[] array) |
(package private) static String |
toAsciiUpperCase(String s) |
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) |
static final String unreserved
static final String punct
static final String reserved
static final String someLegal
static final String queryLegal
private static final char escape
static final String allLegalUnescaped
static final String allLegal
static final String schemeLegal
static final String userinfoLegal
static final String authorityLegal
static final String iPvFuture
static final String hostRegNameLegal
static final String pcharLegal
static final String segmentNzNcLegal
static final String segmentLegal
static final String pathLegal
static final String queryFragLegal
private static final char a
private static final char z
private static final char A
private static final char Z
private static final char upperCaseBitwiseMask
private static final char lowerCaseBitwiseMask
private final String string
private final String scheme
private final String schemespecificpart
private final String authority
private final String userinfo
private final String host
private final int port
private final String path
private final String query
private final String fragment
private final boolean opaque
private final boolean absolute
private final boolean serverAuthority
private final String hashString
private final int hash
private final boolean fileSchemeCaseInsensitiveOS
private Uri(String string, String scheme, String schemespecificpart, String authority, String userinfo, String host, int port, String path, String query, String fragment, boolean opaque, boolean absolute, boolean serverAuthority, int hash, boolean fileSchemeCaseInsensitiveOS)
string
- scheme
- schemespecificpart
- authority
- userinfo
- host
- port
- path
- query
- fragment
- opaque
- absolute
- serverAuthority
- hash
- private Uri(UriParser p)
p
- 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.static char[] toAsciiUpperCase(char[] array)
static char toAsciiUpperCase(char c)
static char[] toAsciiLowerCase(char[] array)
static char toAsciiLowerCase(char c)
static boolean charArraysEqual(char[] a, char[] b)
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
private static UriParser constructor1(String uri) throws URISyntaxException
URISyntaxException
private static UriParser constructor2(String scheme, String ssp, String frag) throws URISyntaxException
URISyntaxException
private static UriParser constructor3(String scheme, String userinfo, String host, int port, String path, String query, String fragment) throws URISyntaxException
URISyntaxException
private static UriParser constructor4(String scheme, String authority, String path, String query, String fragment) 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
- URISyntaxException
public static Uri parseAndCreate(String nonCompliantEscapedString) throws URISyntaxException
nonCompliantEscapedString
- URISyntaxException
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)
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.private String setSchemeSpecificPart(String authority, String path, String query)
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()
private String getHashString()
public URL toURL() throws MalformedURLException
MalformedURLException
- if an error occurs while creating the URL or no protocol
handler could be found.Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.