Class URIBuilder
URI
instances.- Since:
- 5.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Charset
private String
private String
private String
private String
private String
private String
private String
private String
private static final char
private static final char
private static final BitSet
private boolean
private int
private String
private static final char
private static final BitSet
private static final BitSet
private List
<NameValuePair> private String
private String
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs 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. -
Method Summary
Modifier and TypeMethodDescriptionaddParameter
(String param, String value) Adds parameter to URI query.addParameter
(NameValuePair nameValuePair) Adds parameter to URI query.addParameters
(List<NameValuePair> nameValuePairs) Adds URI query parameters.appendPath
(String path) Appends path to URI.appendPathSegments
(String... pathSegments) Appends segments URI path.appendPathSegments
(List<String> pathSegments) Appends segments to URI path.build()
Builds aURI
instance.private String
Clears URI query parameters.private void
(package private) static void
formatPath
(StringBuilder buf, Iterable<String> segments, boolean rootless, Charset charset) (package private) static void
formatQuery
(StringBuilder buf, Iterable<? extends NameValuePair> params, Charset charset, boolean blankAsPlus) Gets the authority.Gets the Charset.getFirstQueryParam
(String name) Gets the firstNameValuePair
for a given name.Gets the fragments.getHost()
Gets the host portion of theURI
.getPath()
Gets the path.Gets the path segments.int
getPort()
Gets the port.Gets the query parameters as a List.Gets the scheme.Gets the scheme specific part.Gets the user info.boolean
Tests whether the URI is absolute.boolean
isOpaque()
Tests whether the URI is opaque.boolean
Tests whether the path is empty.boolean
Tests whether the query is empty.static URIBuilder
Creates a new builder for the hostInetAddress.getLocalHost()
.static URIBuilder
Creates a new builder for the hostInetAddress.getLoopbackAddress()
.Normalizes syntax of 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 normalizedparsePath
(CharSequence s, Charset charset) (package private) static List
<NameValuePair> parseQuery
(CharSequence s, Charset charset, boolean plusAsBlank) removeParameter
(String param) Removes parameter of URI query if set.Removes URI query.setAuthority
(NamedEndpoint authority) Sets the authority.setAuthority
(URIAuthority authority) Sets the authority.setCharset
(Charset charset) Sets the Charset.setCustomQuery
(String query) Sets custom URI query.setFragment
(String fragment) Sets URI fragment.Sets URI host.setHost
(InetAddress host) Sets URI host.setHttpHost
(HttpHost httpHost) Sets the scheme, host name, and port.setParameter
(String param, String value) Sets parameter of URI query overriding existing value if set.setParameters
(List<NameValuePair> nameValuePairs) Sets URI query parameters.setParameters
(NameValuePair... nameValuePairs) Sets URI query parameters.Sets URI path.setPathSegments
(String... pathSegments) Sets URI path.setPathSegments
(List<String> pathSegments) Sets URI path.setPathSegmentsRootless
(String... pathSegments) Sets rootless URI path (the first segment does not start with a /).setPathSegmentsRootless
(List<String> pathSegments) Sets rootless URI path (the first segment does not start with a /).setPort
(int port) Sets URI port.Sets URI scheme.setSchemeSpecificPart
(String schemeSpecificPart) Sets the URI scheme specific part.setSchemeSpecificPart
(String schemeSpecificPart, List<NameValuePair> nvps) Sets the URI scheme specific part and append a list of NameValuePair to this part.setSchemeSpecificPart
(String schemeSpecificPart, NameValuePair... nvps) Sets the URI scheme specific part and append a variable arguments list of NameValuePair instance(s) to this part.setUserInfo
(String userInfo) Sets URI user info.setUserInfo
(String username, String password) Deprecated.toString()
Converts this instance to a URI string.
-
Field Details
-
scheme
-
encodedSchemeSpecificPart
-
encodedAuthority
-
userInfo
-
encodedUserInfo
-
host
-
port
private int port -
encodedPath
-
pathRootless
private boolean pathRootless -
pathSegments
-
encodedQuery
-
queryParams
-
query
-
charset
-
fragment
-
encodedFragment
-
QUERY_PARAM_SEPARATOR
private static final char QUERY_PARAM_SEPARATOR- See Also:
-
PARAM_VALUE_SEPARATOR
private static final char PARAM_VALUE_SEPARATOR- See Also:
-
PATH_SEPARATOR
private static final char PATH_SEPARATOR- See Also:
-
QUERY_PARAM_SEPARATORS
-
QUERY_VALUE_SEPARATORS
-
PATH_SEPARATORS
-
-
Constructor Details
-
URIBuilder
public URIBuilder()Constructs an empty instance. -
URIBuilder
Constructs an instance from the string which must be a valid URI.- Parameters:
uriString
- a valid URI in string form.- Throws:
URISyntaxException
- if the input is not a valid URI.
-
URIBuilder
Constructs an instance from the provided URI.- Parameters:
uri
- a URI.
-
URIBuilder
Constructs an instance from the string which must be a valid URI.- Parameters:
uriString
- a valid URI in string form.- Throws:
URISyntaxException
- if the input is not a valid URI
-
URIBuilder
Constructs an instance from the provided URI.- Parameters:
uri
- a URI.
-
-
Method Details
-
localhost
Creates a new builder for the hostInetAddress.getLocalHost()
.- Returns:
- a new builder.
- Throws:
UnknownHostException
- if the local host name could not be resolved into an address.
-
loopbackAddress
Creates a new builder for the hostInetAddress.getLoopbackAddress()
. -
setAuthority
Sets the authority.- Parameters:
authority
- the authority.- Returns:
- this.
- Since:
- 5.2
-
setAuthority
Sets the authority.- Parameters:
authority
- the authority.- Returns:
- this.
- Since:
- 5.2
-
setCharset
Sets the Charset.- Parameters:
charset
- the Charset.- Returns:
- this.
-
getAuthority
Gets the authority.- Returns:
- the authority.
- Since:
- 5.2
-
getCharset
Gets the Charset.- Returns:
- the Charset.
-
parseQuery
-
splitPath
-
parsePath
-
formatPath
static void formatPath(StringBuilder buf, Iterable<String> segments, boolean rootless, Charset charset) -
formatQuery
static void formatQuery(StringBuilder buf, Iterable<? extends NameValuePair> params, Charset charset, boolean blankAsPlus) -
build
Builds aURI
instance.- Throws:
URISyntaxException
-
buildString
-
digestURI
-
setScheme
Sets URI scheme.- Returns:
- this.
-
setSchemeSpecificPart
Sets the URI scheme specific part.- Parameters:
schemeSpecificPart
-- Returns:
- this.
- Since:
- 5.1
-
setSchemeSpecificPart
Sets the URI scheme specific part and append a variable arguments list of NameValuePair instance(s) to this part.- Parameters:
schemeSpecificPart
-nvps
- Optional, can be null. Variable arguments list of NameValuePair query parameters to be reused by the specific scheme part- Returns:
- this.
- Since:
- 5.1
-
setSchemeSpecificPart
Sets the URI scheme specific part and append a list of NameValuePair to this part.- Parameters:
schemeSpecificPart
-nvps
- Optional, can be null. List of query parameters to be reused by the specific scheme part- Returns:
- this.
- Since:
- 5.1
-
setUserInfo
Sets URI user info. The value is expected to be unescaped and may contain non ASCII characters.- Returns:
- this.
-
setUserInfo
Deprecated.The use of clear-text passwords inURI
s has been deprecated and is strongly discouraged.Sets URI user info as a combination of username and password. These values are expected to be unescaped and may contain non ASCII characters.- Returns:
- this.
-
setHost
Sets URI host.- Returns:
- this.
-
setHost
Sets URI host. The input value must not already be URI encoded, for example::1
is valid however[::1]
is not. It is dangerous to calluriBuilder.setHost(uri.getHost())
due toURI.getHost()
returning URI encoded values.- Returns:
- this.
-
setHttpHost
Sets the scheme, host name, and port.- Parameters:
httpHost
- the scheme, host name, and port.- Returns:
- this.
-
setPort
Sets URI port.- Returns:
- this.
-
setPath
Sets URI path. The value is expected to be unescaped and may contain non ASCII characters.- Returns:
- this.
-
appendPath
Appends path to URI. The value is expected to be unescaped and may contain non ASCII characters.- Returns:
- this.
-
setPathSegments
Sets URI path. The value is expected to be unescaped and may contain non ASCII characters.- Returns:
- this.
-
appendPathSegments
Appends segments URI path. The value is expected to be unescaped and may contain non ASCII characters.- Returns:
- this.
-
setPathSegmentsRootless
Sets rootless URI path (the first segment does not start with a /). The value is expected to be unescaped and may contain non ASCII characters.- Returns:
- this.
- Since:
- 5.1
-
setPathSegments
Sets URI path. The value is expected to be unescaped and may contain non ASCII characters.- Returns:
- this.
-
appendPathSegments
Appends segments to URI path. The value is expected to be unescaped and may contain non ASCII characters.- Returns:
- this.
-
setPathSegmentsRootless
Sets rootless URI path (the first segment does not start with a /). The value is expected to be unescaped and may contain non ASCII characters.- Returns:
- this.
- Since:
- 5.1
-
removeQuery
Removes URI query.- Returns:
- this.
-
setParameters
Sets URI query parameters. The parameter name / values are expected to be unescaped and may contain non ASCII characters.Please note query parameters and custom query component are mutually exclusive. This method will remove custom query if present.
- Returns:
- this.
-
addParameters
Adds URI query parameters. The parameter name / values are expected to be unescaped and may contain non ASCII characters.Please note query parameters and custom query component are mutually exclusive. This method will remove custom query if present.
- Returns:
- this.
-
setParameters
Sets URI query parameters. The parameter name / values are expected to be unescaped and may contain non ASCII characters.Please note query parameters and custom query component are mutually exclusive. This method will remove custom query if present.
- Returns:
- this.
-
addParameter
Adds parameter to URI query. The parameter name and value are expected to be unescaped and may contain non ASCII characters.Please note query parameters and custom query component are mutually exclusive. This method will remove custom query if present.
- Returns:
- this.
-
addParameter
Adds parameter to URI query. The parameter name and value are expected to be unescaped and may contain non ASCII characters.Please note query parameters and custom query component are mutually exclusive. This method will remove custom query if present.
- Returns:
- this.
- Since:
- 5.2
-
removeParameter
Removes parameter of URI query if set. The parameter name is expected to be unescaped and may contain non ASCII characters.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.
- Returns:
- this.
- Since:
- 5.2
-
setParameter
Sets parameter of URI query overriding existing value if set. The parameter name and value are expected to be unescaped and may contain non ASCII characters.Please note query parameters and custom query component are mutually exclusive. This method will remove custom query if present.
- Returns:
- this.
-
clearParameters
Clears URI query parameters.- Returns:
- this.
-
setCustomQuery
Sets custom URI query. The value is expected to be unescaped and may contain non ASCII characters.Please note query parameters and custom query component are mutually exclusive. This method will remove query parameters if present.
- Returns:
- this.
-
setFragment
Sets URI fragment. The value is expected to be unescaped and may contain non ASCII characters.- Returns:
- this.
-
isAbsolute
public boolean isAbsolute()Tests whether the URI is absolute.- Returns:
- whether the URI is absolute.
-
isOpaque
public boolean isOpaque()Tests whether the URI is opaque.- Returns:
- whether the URI is opaque.
-
getScheme
Gets the scheme.- Returns:
- the scheme.
-
getSchemeSpecificPart
Gets the scheme specific part.- Returns:
- String
- Since:
- 5.1
-
getUserInfo
Gets the user info.- Returns:
- the user info.
-
getHost
Gets the host portion of theURI
. This method returns unencoded IPv6 addresses (without brackets). This behavior differs from values returned byURI.getHost()
.- Returns:
- The host portion of the URI.
-
getPort
public int getPort()Gets the port.- Returns:
- the port.
-
isPathEmpty
public boolean isPathEmpty()Tests whether the path is empty.- Returns:
- whether the path is empty.
-
getPathSegments
Gets the path segments.- Returns:
- the path segments.
-
getPath
Gets the path.- Returns:
- the path.
-
isQueryEmpty
public boolean isQueryEmpty()Tests whether the query is empty.- Returns:
- whether the query is empty.
-
getQueryParams
Gets the query parameters as a List.- Returns:
- the query parameters as a List.
-
getFirstQueryParam
Gets the firstNameValuePair
for a given name.- Parameters:
name
- the name- Returns:
- the first named
NameValuePair
or null if not found. - Since:
- 5.2
-
getFragment
Gets the fragments.- Returns:
- the fragments.
-
normalizeSyntax
Normalizes syntax of 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 normalized
- Since:
- 5.1
-
toString
Converts this instance to a URI string.
-
URI
s has been deprecated and is strongly discouraged.