Constructor and Description |
---|
URIBuilder()
Constructs an empty instance.
|
URIBuilder(String uriString)
Constructs an instance from the string which must be a valid URI.
|
URIBuilder(String uriString,
Charset charset)
Constructs an instance from the string which must be a valid URI.
|
URIBuilder(URI uri)
Constructs an instance from the provided URI.
|
URIBuilder(URI uri,
Charset charset)
Constructs an instance from the provided URI.
|
Modifier and Type | Method and Description |
---|---|
URIBuilder |
addParameter(NameValuePair nameValuePair)
Adds parameter to URI query.
|
URIBuilder |
addParameter(String param,
String value)
Adds parameter to URI query.
|
URIBuilder |
addParameters(List<NameValuePair> nameValuePairs)
Adds URI query parameters.
|
URIBuilder |
appendPath(String path)
Appends path to URI.
|
URIBuilder |
appendPathSegments(List<String> pathSegments)
Appends segments to URI path.
|
URIBuilder |
appendPathSegments(String... pathSegments)
Appends segments URI path.
|
URI |
build()
Builds a
URI instance. |
URIBuilder |
clearParameters()
Clears URI query parameters.
|
URIAuthority |
getAuthority()
Gets the authority.
|
Charset |
getCharset()
Gets the Charset.
|
NameValuePair |
getFirstQueryParam(String name)
Gets the first
NameValuePair for a given name. |
String |
getFragment()
Gets the fragments.
|
String |
getHost()
Gets the host portion of the
URI . |
String |
getPath()
Gets the path.
|
List<String> |
getPathSegments()
Gets the path segments.
|
int |
getPort()
Gets the port.
|
List<NameValuePair> |
getQueryParams()
Gets the query parameters as a List.
|
String |
getScheme()
Gets the scheme.
|
String |
getSchemeSpecificPart()
Gets the scheme specific part.
|
String |
getUserInfo()
Gets the user info.
|
boolean |
isAbsolute()
Tests whether the URI is absolute.
|
boolean |
isOpaque()
Tests whether the URI is opaque.
|
boolean |
isPathEmpty()
Tests whether the path is empty.
|
boolean |
isQueryEmpty()
Tests whether the query is empty.
|
static URIBuilder |
localhost()
Creates a new builder for the host
InetAddress.getLocalHost() . |
static URIBuilder |
loopbackAddress()
Creates a new builder for the host
InetAddress.getLoopbackAddress() . |
URIBuilder |
normalizeSyntax()
Deprecated.
do not use this method.
|
URIBuilder |
optimize()
Optimizes URI components if the URI is considered non-opaque (the path component has a root):
characters of scheme and host components are converted to lower case
dot segments of the path component are removed if the path has a root
percent encoding of all components is re-applied
|
URIBuilder |
removeParameter(String param)
Removes parameter of URI query if set.
|
URIBuilder |
removeQuery()
Removes URI query.
|
URIBuilder |
setAuthority(NamedEndpoint authority)
Sets the authority.
|
URIBuilder |
setAuthority(URIAuthority authority)
Sets the authority.
|
URIBuilder |
setCharset(Charset charset)
Sets the Charset.
|
URIBuilder |
setCustomQuery(String query)
Sets custom URI query.
|
URIBuilder |
setFragment(String fragment)
Sets URI fragment.
|
URIBuilder |
setHost(InetAddress host)
Sets URI host.
|
URIBuilder |
setHost(String host)
Sets URI host.
|
URIBuilder |
setHttpHost(HttpHost httpHost)
Sets the scheme, host name, and port.
|
URIBuilder |
setParameter(String param,
String value)
Sets parameter of URI query overriding existing value if set.
|
URIBuilder |
setParameters(List<NameValuePair> nameValuePairs)
Sets URI query parameters.
|
URIBuilder |
setParameters(NameValuePair... nameValuePairs)
Sets URI query parameters.
|
URIBuilder |
setPath(String path)
Sets URI path.
|
URIBuilder |
setPathSegments(List<String> pathSegments)
Sets URI path.
|
URIBuilder |
setPathSegments(String... pathSegments)
Sets URI path.
|
URIBuilder |
setPathSegmentsRootless(List<String> pathSegments)
Sets rootless URI path (the first segment does not start with a /).
|
URIBuilder |
setPathSegmentsRootless(String... pathSegments)
Sets rootless URI path (the first segment does not start with a /).
|
URIBuilder |
setPort(int port)
Sets URI port.
|
URIBuilder |
setScheme(String scheme)
Sets URI scheme.
|
URIBuilder |
setSchemeSpecificPart(String schemeSpecificPart)
Sets the URI scheme specific part.
|
URIBuilder |
setSchemeSpecificPart(String schemeSpecificPart,
List<NameValuePair> nvps)
Sets the URI scheme specific part and append a list of NameValuePair to this part.
|
URIBuilder |
setSchemeSpecificPart(String schemeSpecificPart,
NameValuePair... nvps)
Sets the URI scheme specific part and append a variable arguments list of NameValuePair instance(s) to this part.
|
URIBuilder |
setUserInfo(String userInfo)
Sets URI user info.
|
URIBuilder |
setUserInfo(String username,
String password)
Deprecated.
The use of clear-text passwords in
URI s has been deprecated and is strongly
discouraged. |
String |
toString()
Converts this instance to a URI string.
|
public URIBuilder()
public URIBuilder(String uriString) throws URISyntaxException
uriString
- a valid URI in string form.URISyntaxException
- if the input is not a valid URI.public URIBuilder(URI uri)
uri
- a URI.public URIBuilder(String uriString, Charset charset) throws URISyntaxException
uriString
- a valid URI in string form.URISyntaxException
- if the input is not a valid URIpublic static URIBuilder localhost() throws UnknownHostException
InetAddress.getLocalHost()
.UnknownHostException
- if the local host name could not be resolved into an address.public static URIBuilder loopbackAddress()
InetAddress.getLoopbackAddress()
.public URIBuilder setAuthority(NamedEndpoint authority)
authority
- the authority.public URIBuilder setAuthority(URIAuthority authority)
authority
- the authority.public URIBuilder setCharset(Charset charset)
charset
- the Charset.public URIAuthority getAuthority()
public Charset getCharset()
public URI build() throws URISyntaxException
URI
instance.URISyntaxException
public URIBuilder setScheme(String scheme)
public URIBuilder setSchemeSpecificPart(String schemeSpecificPart)
schemeSpecificPart
- public URIBuilder setSchemeSpecificPart(String schemeSpecificPart, NameValuePair... nvps)
schemeSpecificPart
- nvps
- Optional, can be null. Variable arguments list of NameValuePair query parameters to be reused by the specific scheme partpublic URIBuilder setSchemeSpecificPart(String schemeSpecificPart, List<NameValuePair> nvps)
schemeSpecificPart
- nvps
- Optional, can be null. List of query parameters to be reused by the specific scheme partpublic URIBuilder setUserInfo(String userInfo)
@Deprecated public URIBuilder setUserInfo(String username, String password)
URI
s has been deprecated and is strongly
discouraged.public URIBuilder setHost(InetAddress host)
public URIBuilder setHost(String host)
::1
is valid however
[::1]
is not. It is dangerous to call uriBuilder.setHost(uri.getHost())
due
to URI.getHost()
returning URI encoded values.public URIBuilder setHttpHost(HttpHost httpHost)
httpHost
- the scheme, host name, and port.public URIBuilder setPort(int port)
public URIBuilder setPath(String path)
public URIBuilder appendPath(String path)
public URIBuilder setPathSegments(String... pathSegments)
public URIBuilder appendPathSegments(String... pathSegments)
public URIBuilder setPathSegmentsRootless(String... pathSegments)
public URIBuilder setPathSegments(List<String> pathSegments)
public URIBuilder appendPathSegments(List<String> pathSegments)
public URIBuilder setPathSegmentsRootless(List<String> pathSegments)
public URIBuilder removeQuery()
public URIBuilder setParameters(List<NameValuePair> nameValuePairs)
Please note query parameters and custom query component are mutually exclusive. This method will remove custom query if present.
public URIBuilder addParameters(List<NameValuePair> nameValuePairs)
Please note query parameters and custom query component are mutually exclusive. This method will remove custom query if present.
public URIBuilder setParameters(NameValuePair... nameValuePairs)
Please note query parameters and custom query component are mutually exclusive. This method will remove custom query if present.
public URIBuilder addParameter(String param, String value)
Please note query parameters and custom query component are mutually exclusive. This method will remove custom query if present.
public URIBuilder addParameter(NameValuePair nameValuePair)
Please note query parameters and custom query component are mutually exclusive. This method will remove custom query if present.
public URIBuilder removeParameter(String param)
Please note query parameters and custom query component are mutually exclusive. This method will remove custom query if present, even when no parameter was actually removed.
public URIBuilder setParameter(String param, String value)
Please note query parameters and custom query component are mutually exclusive. This method will remove custom query if present.
public URIBuilder clearParameters()
public URIBuilder setCustomQuery(String query)
Please note query parameters and custom query component are mutually exclusive. This method will remove query parameters if present.
public URIBuilder setFragment(String fragment)
public boolean isAbsolute()
public boolean isOpaque()
public String getScheme()
public String getSchemeSpecificPart()
public String getUserInfo()
public String getHost()
URI
. This method returns unencoded IPv6 addresses (without brackets).
This behavior differs from values returned by URI.getHost()
.public int getPort()
public boolean isPathEmpty()
public List<String> getPathSegments()
public String getPath()
public boolean isQueryEmpty()
public List<NameValuePair> getQueryParams()
public NameValuePair getFirstQueryParam(String name)
NameValuePair
for a given name.name
- the nameNameValuePair
or null if not found.public String getFragment()
@Deprecated public URIBuilder normalizeSyntax()
optimize()
public URIBuilder optimize()
Please note some URI consumers may consider the optimized URI components produced by this method as semantically different from the original ones.
Copyright © 2005–2021 The Apache Software Foundation. All rights reserved.