public static final class Uri.Builder extends Object
An absolute hierarchical URI reference follows the pattern:
<scheme>://<authority><absolute path>?<query>#<fragment>
Relative URI references (which are always hierarchical) follow one
of two patterns: <relative or absolute path>?<query>#<fragment>
or //<authority><absolute path>?<query>#<fragment>
An opaque URI follows this pattern:
<scheme>:<opaque part>#<fragment>
Use Uri.buildUpon()
to obtain a builder representing an existing URI.
Constructor and Description |
---|
Builder()
Constructs a new Builder.
|
Modifier and Type | Method and Description |
---|---|
Uri.Builder |
appendEncodedPath(String newSegment)
Appends the given segment to the path.
|
Uri.Builder |
appendPath(String newSegment)
Encodes the given segment and appends it to the path.
|
Uri.Builder |
appendQueryParameter(String key,
String value)
Encodes the key and value and then appends the parameter to the
query string.
|
Uri.Builder |
authority(String authority)
Encodes and sets the authority.
|
Uri |
build()
Constructs a Uri with the current attributes.
|
Uri.Builder |
clearQuery()
Clears the the previously set query.
|
Uri.Builder |
encodedAuthority(String authority)
Sets the previously encoded authority.
|
Uri.Builder |
encodedFragment(String fragment)
Sets the previously encoded fragment.
|
Uri.Builder |
encodedOpaquePart(String opaquePart)
Sets the previously encoded opaque scheme-specific-part.
|
Uri.Builder |
encodedPath(String path)
Sets the previously encoded path.
|
Uri.Builder |
encodedQuery(String query)
Sets the previously encoded query.
|
Uri.Builder |
fragment(String fragment)
Encodes and sets the fragment.
|
Uri.Builder |
opaquePart(String opaquePart)
Encodes and sets the given opaque scheme-specific-part.
|
Uri.Builder |
path(String path)
Sets the path.
|
Uri.Builder |
query(String query)
Encodes and sets the query.
|
Uri.Builder |
scheme(String scheme)
Sets the scheme.
|
String |
toString()
Returns a string representation of the object.
|
public Uri.Builder scheme(String scheme)
scheme
- name or null
if this is a relative Uripublic Uri.Builder opaquePart(String opaquePart)
opaquePart
- decoded opaque partpublic Uri.Builder encodedOpaquePart(String opaquePart)
opaquePart
- encoded opaque partpublic Uri.Builder authority(String authority)
public Uri.Builder encodedAuthority(String authority)
public Uri.Builder path(String path)
If the path is not null and doesn't start with a '/', and if you specify a scheme and/or authority, the builder will prepend the given path with a '/'.
public Uri.Builder encodedPath(String path)
If the path is not null and doesn't start with a '/', and if you specify a scheme and/or authority, the builder will prepend the given path with a '/'.
public Uri.Builder appendPath(String newSegment)
public Uri.Builder appendEncodedPath(String newSegment)
public Uri.Builder query(String query)
public Uri.Builder encodedQuery(String query)
public Uri.Builder fragment(String fragment)
public Uri.Builder encodedFragment(String fragment)
public Uri.Builder appendQueryParameter(String key, String value)
key
- which will be encodedvalue
- which will be encodedpublic Uri.Builder clearQuery()
public Uri build()
UnsupportedOperationException
- if the URI is opaque and the
scheme is nullpublic String toString()
Object
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())