Comparable<Uri>, Sequenceablepublic abstract class Uri extends Object implements Sequenceable, Comparable<Uri>
For details, see RFC 2396.
The standard URI format is as follows:
[scheme:]scheme-specific-part[#fragment]
As described in RFC 2396, URIs are classified into four types: hierarchical,
opaque, relative, and absolute URIs.
| 限定符和类型 | 类 | 说明 |
|---|---|---|
static class |
Uri.Builder |
Quickly constructs a Uniform Resource Identifier (URI) object.
|
Sequenceable.Producer<T>| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static Uri |
EMPTY_URI |
Indicates an empty
Uri object. |
static Sequenceable.Producer<Uri> |
PRODUCER |
Indicates that a
Uri instance is created after unmarshalling of
a Parcel object. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static Uri |
appendEncodedPathToUri(Uri orgUri,
String path) |
Appends a path to a specified
Uri object. |
int |
compareTo(Uri other) |
Compares this object with the specified object for order.
|
static String |
decode(String str) |
Decodes the specified string using UTF-8 encoding.
|
static String |
encode(String str) |
Encodes the specified string using UTF-8 encoding.
|
static String |
encode(String str,
String allow) |
Encodes the characters other than those specified by the
allow parameter using UTF-8 encoding. |
boolean |
equals(Object obj) |
Indicates whether some other object is "equal to" this one.
|
boolean |
getBooleanQueryParam(String key,
boolean defaultValue) |
Obtains the first result that matches the
query field in the current URI based on a specified
key and checks whether the result is not false or 0. |
abstract String |
getDecodedAuthority() |
Obtains the decoded
authority field of the current URI. |
abstract String |
getDecodedFragment() |
Obtains the decoded
fragment field of the current URI. |
abstract String |
getDecodedHost() |
Obtains the decoded
host field of the current URI. |
abstract String |
getDecodedPath() |
Obtains the decoded
path field in the current URI. |
abstract List<String> |
getDecodedPathList() |
Obtains a list of decoded paths in the current URI.
|
abstract String |
getDecodedQuery() |
Obtains the decoded
query field in the current URI. |
abstract Map<String,List<String>> |
getDecodedQueryParams() |
Obtains all search criteria and values in the
query field of the current URI. |
abstract String |
getDecodedSchemeSpecificPart() |
Obtains the decoded
scheme-specific-part field in the current URI. |
abstract String |
getDecodedUserInfo() |
Obtains the decoded
user-info field of the current URI. |
abstract String |
getEncodedAuthority() |
Obtains the encoded
authority field of the current URI. |
abstract String |
getEncodedFragment() |
Obtains the encoded
fragment field of the current URI. |
abstract String |
getEncodedHost() |
Obtains the encoded
host field of the current URI. |
abstract String |
getEncodedPath() |
Obtains the encoded
path field of the current URI. |
abstract String |
getEncodedQuery() |
Obtains the encoded
query field of the current URI. |
abstract String |
getEncodedSchemeSpecificPart() |
Obtains the encoded
scheme-specific-part field in the current URI. |
abstract String |
getEncodedUserInfo() |
Obtains the encoded
user-info field of the current URI. |
String |
getFirstQueryParamByKey(String key) |
Obtains the first result that matches the
query field in the current URI based on a specified key. |
String |
getLastPath() |
Obtains the last path of the current URI.
|
Uri |
getLowerCaseScheme() |
Sets the
scheme field in the current Uri object to lowercase. |
abstract int |
getPort() |
Obtains the
port field of the current URI. |
Set<String> |
getQueryParamNames() |
Obtains all names in the
query field of the current URI. |
List<String> |
getQueryParamsByKey(String key) |
Obtains all results that match the
query field in the current URI based on a specified key. |
String |
getScheme() |
Obtains the
scheme field of the current URI. |
static Uri |
getUriFromFile(File file) |
Creates a
hierarchical Uri object based on the given file. |
static Uri |
getUriFromFileCanonicalPath(File file) |
Creates a
hierarchical Uri object based on the canonical path of the given file. |
static Uri |
getUriFromParts(String scheme,
String ssp,
String fragment) |
Creates an
opaque Uri object based on the given strings. |
boolean |
hasFileDescriptor() |
Checks whether the implementation class of this
Sequenceable contains FileDescriptor object data. |
int |
hashCode() |
Returns a hash code value for the object.
|
boolean |
isAbsolute() |
Checks whether the current URI is an
absolute one. |
abstract boolean |
isHierarchical() |
Checks whether the current URI is a
hierarchical one. |
boolean |
isOpaque() |
Checks whether the current URI is an
opaque one. |
boolean |
isRelative() |
Checks whether the current URI is a
relative one. |
abstract Uri.Builder |
makeBuilder() |
Obtains the
Builder object of the current URI so that you can use the object to
add or modify the URI components. |
static Uri |
parse(String uriStr) |
Creates a
Uri object based on the given RFC 2396-compliant string. |
static Uri |
readFromParcel(Parcel in) |
Reads a
Uri object from a Parcel. |
abstract String |
toString() |
Obtains the complete character string of the encoded URI object.
|
boolean |
unmarshalling(Parcel in) |
Unmarshals the URI object from the
Parcel object. |
marshallingpublic static final Uri EMPTY_URI
Uri object. The value is an empty string.public static final Sequenceable.Producer<Uri> PRODUCER
Uri instance is created after unmarshalling of
a Parcel object.public abstract boolean isHierarchical()
hierarchical one.
For example, http://www.mycompany.com.
A hierarchical URI can be an absolute one, but its scheme-specific-part field must
start with a slash (/). It can also be a relative one.
true if it is a hierarchical URI; returns false otherwise.public boolean isOpaque()
opaque one.
For example, news:www.mycompany.com.
An opaque URI must be an absolute URI and its scheme-specific-part field cannot
start with a slash (/).
true if it is an opaque URI; returns false otherwise.public boolean isRelative()
relative one.
For example, www.mycompany.com.
A relative URI does not contain the scheme field.
true if it is a relative URI; returns false otherwise.public boolean isAbsolute()
absolute one.
For example, http://www.mycompany.com.
An absolute URI must contain the scheme field.
true if it is an absolute URI; returns false otherwise.public String getScheme()
scheme field of the current URI.
For example, http is the scheme field of URI http://www.mycompany.com.
scheme field; returns null if the current URI does not contain
the scheme field.public abstract String getDecodedSchemeSpecificPart()
scheme-specific-part field in the current URI.
It is everything between the scheme separator (:) and the fragment separator (#).
For example, in URI https://www.mycompany.com/cn/?ic_medium=direct,
//www.mycompany.com/cn/?ic_medium=direct is the scheme-specific-part field.
scheme-specific-part field;
returns null if the current URI does not contain the scheme-specific-part field.public abstract String getEncodedSchemeSpecificPart()
scheme-specific-part field in the current URI.scheme-specific-part field;
returns null if the current URI does not contain the scheme-specific-part field.getDecodedSchemeSpecificPart()public abstract String getDecodedAuthority()
authority field of the current URI.
A hierarchical URI is in the format of [scheme:][//authority][path][?query][#fragment].
For example, www.mycompany.com is the authority field of URI
https://www.mycompany.com/cn/?ic_medium=direct.
authority field;
returns null if the current URI does not contain the authority field.public abstract String getEncodedAuthority()
authority field of the current URI.authority field;
returns null if the current URI does not contain the authority field.getDecodedAuthority()public abstract String getDecodedUserInfo()
user-info field of the current URI.
The authority structure of the server type is in the format of [user-info@]host[:port].
For example, test is the user-info field of the authority
structure test@mycompany.com.
user-info field;
returns null if the current URI does not contain the user-info field.public abstract String getEncodedUserInfo()
user-info field of the current URI.user-info field;
returns null if the current URI does not contain the user-info field.getDecodedUserInfo()public abstract String getDecodedHost()
host field of the current URI.
The authority structure of the server type is in the format of [user-info@]host[:port].
For example, mycompany.com is the host field of the authority
structure test@mycompany.com.
host field;
returns null if the current URI does not contain the host field.public abstract String getEncodedHost()
host field of the current URI.host field;
returns null if the current URI does not contain the host field.getDecodedHost()public abstract int getPort()
port field of the current URI.
The authority structure of the server type is in the format of [user-info@]host[:port].
For example, 443 is the port field of the authority
structure test@mycompany.com:443.
port field of the current URI;
returns -1 if the current URI does not contain the port field.public abstract String getDecodedPath()
path field in the current URI.path field;
returns null if the current URI does not contain the path field.public abstract String getEncodedPath()
path field of the current URI.path field;
returns null if the current URI does not contain the path field.public abstract List<String> getDecodedPathList()
There may be multiple path fields in a URI, for example,
scheme://authority/path1/path2/path3?query#fragment.
public abstract String getDecodedQuery()
query field in the current URI.
It is everything between the query separator (?) and the fragment separator (#).
For example, ic_medium=direct is the query field of URI
https://www.mycompany.com/cn/?ic_medium=direct.
query field;
returns null if the current URI does not contain the query field.public abstract String getEncodedQuery()
query field of the current URI.query field;
returns null if the current URI does not contain the query field.getDecodedQuery()public abstract Map<String,List<String>> getDecodedQueryParams()
query field of the current URI.key) and search criterion values (referred to as value).
The values in the map are in the same sequence as the query statements of the URI.
Returns a map containing "" if the specified key has no value associated.public abstract String getDecodedFragment()
fragment field of the current URI.
For example, 28 is the fragment field of URI
https://www.mycompany.com/cn/?ic_medium=direct#28.
fragment field;
returns null if the current URI does not contain the fragment field.public abstract String getEncodedFragment()
fragment field of the current URI.fragment field;
returns null if the current URI does not contain the fragment field.getDecodedFragment()public abstract Uri.Builder makeBuilder()
Builder object of the current URI so that you can use the object to
add or modify the URI components.Builder object.public abstract String toString()
For example, https://www.mycompany.com/cn/?ic_medium=direct#28.
public boolean unmarshalling(Parcel in)
Parcel object.
This method is not supported currently. Use Uri#PRODUCER for alternation.
unmarshalling 在接口中 Sequenceablein - Indicates the Parcel object.true if unmarshalling is successful; returns false otherwise.UnsupportedOperationException - Throws this exception if this method is called because it
is not supported currently.public static String encode(String str)
All characters, except letters (A-Z and a-z), digits 0-9, and non-reserved characters ("_-!.~'()*") can be encoded.
str - Indicates the string to encode.null if null is passed in the input parameter.public static String encode(String str, String allow)
allow parameter using UTF-8 encoding.
Letters (A-Z and a-z), digits 0-9, and non-reserved characters ("_-!.~'()*") will not be encoded.
str - Indicates the string to encode.allow - Indicates the additional character set that will not be encoded. You can set it to null.null if null is passed in the input parameter.public static String decode(String str)
str - Indicates the string to decode.null if null is passed in the input parameter.public static Uri getUriFromParts(String scheme, String ssp, String fragment)
opaque Uri object based on the given strings.scheme - Indicates the scheme field in the opaque URI.ssp - Indicates the scheme-specific-part field in the opaque URI.fragment - Indicates the fragment field in the opaque URI.opaque Uri object.NullPointerException - Throws this exception if scheme or scheme-specific-part
is null.public static Uri getUriFromFile(File file)
hierarchical Uri object based on the given file.
The URI is in the format of file://<absolute path>.
file - Indicates the file used for creating the URI.hierarchical Uri object.NullPointerException - Throws this exception if the file parameter is null.public static Uri getUriFromFileCanonicalPath(File file) throws IOException
hierarchical Uri object based on the canonical path of the given file.
The URI is in the format of file://<canonical path>.
file - Indicates the file used for creating the URI.hierarchical Uri object.IOException - Throws this exception if an I/O error occurs.NullPointerException - Throws this exception if the file parameter is null.public static Uri appendEncodedPathToUri(Uri orgUri, String path)
Uri object.orgUri - Indicates the Uri object to append the path to.path - Indicates the encoded path string to append.Uri object that has the encoded path appended.UnsupportedOperationException - Throws this exception if the specified Uri object is
an opaque URI.public static Uri parse(String uriStr)
Uri object based on the given RFC 2396-compliant string.uriStr - Indicates the encoded URI string, which must comply with the RFC 2396.Uri object.NullPointerException - Throws this exception if the uriStr is null or empty.IllegalArgumentException - Throws this exception if the uriStr is invalid.public static Uri readFromParcel(Parcel in)
Uri object from a Parcel.in - Indicates the Parcel object.Uri object.IllegalArgumentException - Throws this exception if the input parameter is null or the unmarshalling fails.public String getLastPath()
null if the last path does not exist.public List<String> getQueryParamsByKey(String key)
query field in the current URI based on a specified key.
Keys can be duplicate and may have no values associated. Therefore, a list of matched results is
returned in the sequence of statements in the query field.
If the specified key exists but has no value associated, a list containing "" will be returned.
key - Indicates the decoded key.query
field of the URI;
returns an empty list if no result is found.public String getFirstQueryParamByKey(String key)
query field in the current URI based on a specified key.
Keys can be duplicate and may have no values associated. Therefore, the first matched result is returned
in the sequence of statements in the query field. If the specified key has no value, "" will be returned.
key - Indicates the decoded key."" if no result is found.public Set<String> getQueryParamNames()
query field of the current URI.query field of the current URI;
returns an empty list if there is no query field.public boolean getBooleanQueryParam(String key, boolean defaultValue)
query field in the current URI based on a specified
key and checks whether the result is not false or 0.key - Indicates the decoded key.defaultValue - Indicates the default value to return if no result is found.defaultValue if no match is found;
returns false if the matched value is false or 0; returns true for other cases.public Uri getLowerCaseScheme()
scheme field in the current Uri object to lowercase.Uri object with the scheme field in lowercase.public boolean equals(Object obj)
Object
The equals method implements an equivalence relation
on non-null object references:
x, x.equals(x) should return
true.
x and y, x.equals(y)
should return true if and only if
y.equals(x) returns true.
x, y, and z, if
x.equals(y) returns true and
y.equals(z) returns true, then
x.equals(z) should return true.
x and y, multiple invocations of
x.equals(y) consistently return true
or consistently return false, provided no
information used in equals comparisons on the
objects is modified.
x,
x.equals(null) should return false.
The equals method for class Object implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x and
y, this method returns true if and only
if x and y refer to the same object
(x == y has the value true).
Note that it is generally necessary to override the hashCode
method whenever this method is overridden, so as to maintain the
general contract for the hashCode method, which states
that equal objects must have equal hash codes.
equals 在类中 Objectobj - the reference object with which to compare.true if this object is the same as the obj
argument; false otherwise.Object.hashCode(),
HashMappublic int hashCode()
ObjectHashMap.
The general contract of hashCode is:
hashCode method
must consistently return the same integer, provided no information
used in equals comparisons on the object is modified.
This integer need not remain consistent from one execution of an
application to another execution of the same application.
equals(Object)
method, then calling the hashCode method on each of
the two objects must produce the same integer result.
Object.equals(java.lang.Object)
method, then calling the hashCode method on each of the
two objects must produce distinct integer results. However, the
programmer should be aware that producing distinct integer results
for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by
class Object does return distinct integers for distinct
objects. (This is typically implemented by converting the internal
address of the object into an integer, but this implementation
technique is not required by the
Java™ programming language.)
hashCode 在类中 ObjectObject.equals(java.lang.Object),
System.identityHashCode(java.lang.Object)public int compareTo(Uri other)
ComparableThe implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception iff y.compareTo(x) throws an exception.)
The implementor must also ensure that the relation is transitive: (x.compareTo(y)>0 && y.compareTo(z)>0) implies x.compareTo(z)>0.
Finally, the implementor must ensure that x.compareTo(y)==0 implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all z.
It is strongly recommended, but not strictly required that (x.compareTo(y)==0) == (x.equals(y)). Generally speaking, any class that implements the Comparable interface and violates this condition should clearly indicate this fact. The recommended language is "Note: this class has a natural ordering that is inconsistent with equals."
In the foregoing description, the notation sgn(expression) designates the mathematical signum function, which is defined to return one of -1, 0, or 1 according to whether the value of expression is negative, zero or positive.
compareTo 在接口中 Comparable<Uri>other - the object to be compared.public boolean hasFileDescriptor()
SequenceableSequenceable contains FileDescriptor object data.
If the custom Sequenceable class contains any FileDescriptor data, you should override this
method.
This method return false by default.
hasFileDescriptor 在接口中 Sequenceabletrue if it contains FileDescriptor data; returns false otherwise.