Top Description Fields Constructors Methods
org.apache.hc.core5.net

public Class URIBuilder

extends Object
Class Inheritance
Imports
java.net.InetAddress, .URI, .URISyntaxException, .UnknownHostException, java.nio.charset.Charset, .StandardCharsets, java.util.ArrayList, .Arrays, .BitSet, .Collections, .LinkedList, .List, org.apache.hc.core5.http.HttpHost, .NameValuePair, org.apache.hc.core5.http.message.BasicNameValuePair, .ParserCursor, org.apache.hc.core5.util.Args, .TextUtils, .Tokenizer

Builder for URI instances.
Since
5.0

Field Summary

Modifier and TypeField and Description
private 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 List<String>
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

AccessConstructor and Description
public
URIBuilder()

Constructs an empty instance.

public
URIBuilder(final String
a valid URI in string form.
uriString
)

Constructs an instance from the string which must be a valid URI.

public
URIBuilder(final URI
a URI.
uri
)

Constructs an instance from the provided URI.

public
URIBuilder(final String
a valid URI in string form.
uriString
,
final Charset charset)

Constructs an instance from the string which must be a valid URI.

public
URIBuilder(final URI
a URI.
uri
,
final Charset charset)

Constructs an instance from the provided URI.

Method Summary

Modifier and TypeMethod and Description
public URIBuilder

Returns:

this.
addParameter
(final String param, final String value)

Adds parameter to URI query.

public URIBuilder

Returns:

this.
addParameter
(final NameValuePair nameValuePair)

Adds parameter to URI query.

public URIBuilder

Returns:

this.
addParameters
(final List<NameValuePair> nameValuePairs)

Adds URI query parameters.

public URIBuilder

Returns:

this.
appendPath
(final String path)

Appends path to URI.

public URIBuilder

Returns:

this.
appendPathSegments
(final String... pathSegments)

Appends segments URI path.

public URIBuilder

Returns:

this.
appendPathSegments
(final List<String> pathSegments)

Appends segments to URI path.

public URI
build()

Builds a URI instance.

private String
public URIBuilder

Returns:

this.
clearParameters
()

Clears URI query parameters.

private void
digestURI(final URI uri, final Charset charset)

pack-priv static void
formatPath(final StringBuilder buf, final Iterable<String> segments, final boolean rootless, final Charset charset)

pack-priv static void
formatQuery(final StringBuilder buf, final Iterable<? extends NameValuePair> params, final Charset charset, final boolean blankAsPlus)

public URIAuthority

Returns:

the authority.
getAuthority
()

Gets the authority.

public Charset

Returns:

the Charset.
getCharset
()

Gets the Charset.

public NameValuePair

Returns:

the first named NameValuePair or null if not found.
getFirstQueryParam
(final String
the name
name
)

Gets the first NameValuePair for a given name.

public String

Returns:

the fragments.
getFragment
()

Gets the fragments.

public String

Returns:

The host portion of the URI.
getHost
()

Gets the host portion of the URI.

public String

Returns:

the path.
getPath
()

Gets the path.

public List<String>

Returns:

the path segments.
getPathSegments
()

Gets the path segments.

public int

Returns:

the port.
getPort
()

Gets the port.

public List<NameValuePair>

Returns:

the query parameters as a List.
getQueryParams
()

Gets the query parameters as a List.

public String

Returns:

the scheme.
getScheme
()

Gets the scheme.

public String

Returns:

String
getSchemeSpecificPart
()

Gets the scheme specific part.

public String

Returns:

the user info.
getUserInfo
()

Gets the user info.

public boolean

Returns:

whether the URI is absolute.
isAbsolute
()

Tests whether the URI is absolute.

public boolean

Returns:

whether the URI is opaque.
isOpaque
()

Tests whether the URI is opaque.

public boolean

Returns:

whether the path is empty.
isPathEmpty
()

Tests whether the path is empty.

public boolean

Returns:

whether the query is empty.
isQueryEmpty
()

Tests whether the query is empty.

public static URIBuilder

Returns:

a new builder.
localhost
()

Creates a new builder for the host InetAddress#getLocalHost().

public static URIBuilder
loopbackAddress()

Creates a new builder for the host InetAddress#getLoopbackAddress().

public URIBuilder
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
pack-priv static List<String>
parsePath(final CharSequence s, final Charset charset)

pack-priv static List<NameValuePair>
parseQuery(final CharSequence s, final Charset charset, final boolean plusAsBlank)

public URIBuilder

Returns:

this.
removeParameter
(final String param)

Removes parameter of URI query if set.

public URIBuilder

Returns:

this.
removeQuery
()

Removes URI query.

public URIBuilder

Returns:

this.
setAuthority
(final NamedEndpoint
the authority.
authority
)

Sets the authority.

public URIBuilder

Returns:

this.
setAuthority
(final URIAuthority
the authority.
authority
)

Sets the authority.

public URIBuilder

Returns:

this.
setCharset
(final Charset
the Charset.
charset
)

Sets the Charset.

public URIBuilder

Returns:

this.
setCustomQuery
(final String query)

Sets custom URI query.

public URIBuilder

Returns:

this.
setFragment
(final String fragment)

Sets URI fragment.

public URIBuilder

Returns:

this.
setHost
(final InetAddress host)

Sets URI host.

public URIBuilder

Returns:

this.
setHost
(final String host)

Sets URI host.

public URIBuilder

Returns:

this.
setHttpHost
(final HttpHost
the scheme, host name, and port.
httpHost
)

Sets the scheme, host name, and port.

public URIBuilder

Returns:

this.
setParameter
(final String param, final String value)

Sets parameter of URI query overriding existing value if set.

public URIBuilder

Returns:

this.
setParameters
(final List<NameValuePair> nameValuePairs)

Sets URI query parameters.

public URIBuilder

Returns:

this.
setParameters
(final NameValuePair... nameValuePairs)

Sets URI query parameters.

public URIBuilder

Returns:

this.
setPath
(final String path)

Sets URI path.

public URIBuilder

Returns:

this.
setPathSegments
(final String... pathSegments)

Sets URI path.

public URIBuilder

Returns:

this.
setPathSegments
(final List<String> pathSegments)

Sets URI path.

public URIBuilder

Returns:

this.
setPathSegmentsRootless
(final String... pathSegments)

Sets rootless URI path (the first segment does not start with a /).

public URIBuilder

Returns:

this.
setPathSegmentsRootless
(final List<String> pathSegments)

Sets rootless URI path (the first segment does not start with a /).

public URIBuilder

Returns:

this.
setPort
(final int port)

Sets URI port.

public URIBuilder

Returns:

this.
setScheme
(final String scheme)

Sets URI scheme.

public URIBuilder

Returns:

this.
setSchemeSpecificPart
(final String schemeSpecificPart)

Sets the URI scheme specific part.

public URIBuilder

Returns:

this.
setSchemeSpecificPart
(final String schemeSpecificPart, final NameValuePair...
Optional, can be null. Variable arguments list of NameValuePair query parameters to be reused by the specific scheme part
nvps
)

Sets the URI scheme specific part and append a variable arguments list of NameValuePair instance(s) to this part.

public URIBuilder

Returns:

this.
setSchemeSpecificPart
(final String schemeSpecificPart, final List<NameValuePair>
Optional, can be null. List of query parameters to be reused by the specific scheme part
nvps
)

Sets the URI scheme specific part and append a list of NameValuePair to this part.

public URIBuilder

Returns:

this.
setUserInfo
(final String userInfo)

Sets URI user info.

public URIBuilder

Returns:

this.
setUserInfo
(final String username, final String password)

Deprecated The use of clear-text passwords in URIs has been deprecated and is strongly discouraged.
Sets URI user info as a combination of username and password.
pack-priv static List<String>
public String

Returns:

this instance to a URI string.
toString
()

Overrides java.lang.Object.toString.

Converts this instance to a URI string.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

charsetback to summary
private Charset charset
encodedAuthorityback to summary
private String encodedAuthority
encodedFragmentback to summary
private String encodedFragment
encodedPathback to summary
private String encodedPath
encodedQueryback to summary
private String encodedQuery
encodedSchemeSpecificPartback to summary
private String encodedSchemeSpecificPart
encodedUserInfoback to summary
private String encodedUserInfo
fragmentback to summary
private String fragment
hostback to summary
private String host
PARAM_VALUE_SEPARATORback to summary
private static final char PARAM_VALUE_SEPARATOR
PATH_SEPARATORback to summary
private static final char PATH_SEPARATOR
PATH_SEPARATORSback to summary
private static final BitSet PATH_SEPARATORS
pathRootlessback to summary
private boolean pathRootless
pathSegmentsback to summary
private List<String> pathSegments
portback to summary
private int port
queryback to summary
private String query
QUERY_PARAM_SEPARATORback to summary
private static final char QUERY_PARAM_SEPARATOR
QUERY_PARAM_SEPARATORSback to summary
private static final BitSet QUERY_PARAM_SEPARATORS
QUERY_VALUE_SEPARATORSback to summary
private static final BitSet QUERY_VALUE_SEPARATORS
queryParamsback to summary
private List<NameValuePair> queryParams
schemeback to summary
private String scheme
userInfoback to summary
private String userInfo

Constructor Detail

URIBuilderback to summary
public URIBuilder()

Constructs an empty instance.

URIBuilderback to summary
public URIBuilder(final String uriString) throws URISyntaxException

Constructs an instance from the string which must be a valid URI.

Parameters
uriString:String

a valid URI in string form.

Exceptions
URISyntaxException:
if the input is not a valid URI.
URIBuilderback to summary
public URIBuilder(final URI uri)

Constructs an instance from the provided URI.

Parameters
uri:URI

a URI.

URIBuilderback to summary
public URIBuilder(final String uriString, final Charset charset) throws URISyntaxException

Constructs an instance from the string which must be a valid URI.

Parameters
uriString:String

a valid URI in string form.

Exceptions
URISyntaxException:
if the input is not a valid URI
URIBuilderback to summary
public URIBuilder(final URI uri, final Charset charset)

Constructs an instance from the provided URI.

Parameters
uri:URI

a URI.

Method Detail

addParameterback to summary
public URIBuilder addParameter(final String param, final String value)

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:URIBuilder

this.

addParameterback to summary
public URIBuilder addParameter(final NameValuePair nameValuePair)

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:URIBuilder

this.

Since
5.2
addParametersback to summary
public URIBuilder addParameters(final List<NameValuePair> nameValuePairs)

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:URIBuilder

this.

appendPathback to summary
public URIBuilder appendPath(final String path)

Appends path to URI. The value is expected to be unescaped and may contain non ASCII characters.

Returns:URIBuilder

this.

appendPathSegmentsback to summary
public URIBuilder appendPathSegments(final String... pathSegments)

Appends segments URI path. The value is expected to be unescaped and may contain non ASCII characters.

Returns:URIBuilder

this.

appendPathSegmentsback to summary
public URIBuilder appendPathSegments(final List<String> pathSegments)

Appends segments to URI path. The value is expected to be unescaped and may contain non ASCII characters.

Returns:URIBuilder

this.

buildback to summary
public URI build() throws URISyntaxException

Builds a URI instance.

buildStringback to summary
private String buildString()
clearParametersback to summary
public URIBuilder clearParameters()

Clears URI query parameters.

Returns:URIBuilder

this.

digestURIback to summary
private void digestURI(final URI uri, final Charset charset)
formatPathback to summary
pack-priv static void formatPath(final StringBuilder buf, final Iterable<String> segments, final boolean rootless, final Charset charset)
formatQueryback to summary
pack-priv static void formatQuery(final StringBuilder buf, final Iterable<? extends NameValuePair> params, final Charset charset, final boolean blankAsPlus)
getAuthorityback to summary
public URIAuthority getAuthority()

Gets the authority.

Returns:URIAuthority

the authority.

Since
5.2
getCharsetback to summary
public Charset getCharset()

Gets the Charset.

Returns:Charset

the Charset.

getFirstQueryParamback to summary
public NameValuePair getFirstQueryParam(final String name)

Gets the first NameValuePair for a given name.

Parameters
name:String

the name

Returns:NameValuePair

the first named NameValuePair or null if not found.

Since
5.2
getFragmentback to summary
public String getFragment()

Gets the fragments.

Returns:String

the fragments.

getHostback to summary
public String getHost()

Gets the host portion of the URI. This method returns unencoded IPv6 addresses (without brackets). This behavior differs from values returned by URI#getHost().

Returns:String

The host portion of the URI.

getPathback to summary
public String getPath()

Gets the path.

Returns:String

the path.

getPathSegmentsback to summary
public List<String> getPathSegments()

Gets the path segments.

Returns:List<String>

the path segments.

getPortback to summary
public int getPort()

Gets the port.

Returns:int

the port.

getQueryParamsback to summary
public List<NameValuePair> getQueryParams()

Gets the query parameters as a List.

Returns:List<NameValuePair>

the query parameters as a List.

getSchemeback to summary
public String getScheme()

Gets the scheme.

Returns:String

the scheme.

getSchemeSpecificPartback to summary
public String getSchemeSpecificPart()

Gets the scheme specific part.

Returns:String

String

Since
5.1
getUserInfoback to summary
public String getUserInfo()

Gets the user info.

Returns:String

the user info.

isAbsoluteback to summary
public boolean isAbsolute()

Tests whether the URI is absolute.

Returns:boolean

whether the URI is absolute.

isOpaqueback to summary
public boolean isOpaque()

Tests whether the URI is opaque.

Returns:boolean

whether the URI is opaque.

isPathEmptyback to summary
public boolean isPathEmpty()

Tests whether the path is empty.

Returns:boolean

whether the path is empty.

isQueryEmptyback to summary
public boolean isQueryEmpty()

Tests whether the query is empty.

Returns:boolean

whether the query is empty.

localhostback to summary
public static URIBuilder localhost() throws UnknownHostException

Creates a new builder for the host InetAddress#getLocalHost().

Returns:URIBuilder

a new builder.

Exceptions
UnknownHostException:
if the local host name could not be resolved into an address.
loopbackAddressback to summary
public static URIBuilder loopbackAddress()

Creates a new builder for the host InetAddress#getLoopbackAddress().

normalizeSyntaxback to summary
public URIBuilder 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
parsePathback to summary
pack-priv static List<String> parsePath(final CharSequence s, final Charset charset)
parseQueryback to summary
pack-priv static List<NameValuePair> parseQuery(final CharSequence s, final Charset charset, final boolean plusAsBlank)
removeParameterback to summary
public URIBuilder removeParameter(final String param)

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:URIBuilder

this.

Since
5.2
removeQueryback to summary
public URIBuilder removeQuery()

Removes URI query.

Returns:URIBuilder

this.

setAuthorityback to summary
public URIBuilder setAuthority(final NamedEndpoint authority)

Sets the authority.

Parameters
authority:NamedEndpoint

the authority.

Returns:URIBuilder

this.

Since
5.2
setAuthorityback to summary
public URIBuilder setAuthority(final URIAuthority authority)

Sets the authority.

Parameters
authority:URIAuthority

the authority.

Returns:URIBuilder

this.

Since
5.2
setCharsetback to summary
public URIBuilder setCharset(final Charset charset)

Sets the Charset.

Parameters
charset:Charset

the Charset.

Returns:URIBuilder

this.

setCustomQueryback to summary
public URIBuilder setCustomQuery(final String query)

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:URIBuilder

this.

setFragmentback to summary
public URIBuilder setFragment(final String fragment)

Sets URI fragment. The value is expected to be unescaped and may contain non ASCII characters.

Returns:URIBuilder

this.

setHostback to summary
public URIBuilder setHost(final InetAddress host)

Sets URI host.

Returns:URIBuilder

this.

setHostback to summary
public URIBuilder setHost(final String host)

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 call uriBuilder.setHost(uri.getHost()) due to URI#getHost() returning URI encoded values.

Returns:URIBuilder

this.

setHttpHostback to summary
public URIBuilder setHttpHost(final HttpHost httpHost)

Sets the scheme, host name, and port.

Parameters
httpHost:HttpHost

the scheme, host name, and port.

Returns:URIBuilder

this.

setParameterback to summary
public URIBuilder setParameter(final String param, final String value)

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:URIBuilder

this.

setParametersback to summary
public URIBuilder setParameters(final List<NameValuePair> nameValuePairs)

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:URIBuilder

this.

setParametersback to summary
public URIBuilder setParameters(final NameValuePair... nameValuePairs)

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:URIBuilder

this.

setPathback to summary
public URIBuilder setPath(final String path)

Sets URI path. The value is expected to be unescaped and may contain non ASCII characters.

Returns:URIBuilder

this.

setPathSegmentsback to summary
public URIBuilder setPathSegments(final String... pathSegments)

Sets URI path. The value is expected to be unescaped and may contain non ASCII characters.

Returns:URIBuilder

this.

setPathSegmentsback to summary
public URIBuilder setPathSegments(final List<String> pathSegments)

Sets URI path. The value is expected to be unescaped and may contain non ASCII characters.

Returns:URIBuilder

this.

setPathSegmentsRootlessback to summary
public URIBuilder setPathSegmentsRootless(final String... pathSegments)

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:URIBuilder

this.

Since
5.1
setPathSegmentsRootlessback to summary
public URIBuilder setPathSegmentsRootless(final List<String> pathSegments)

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:URIBuilder

this.

Since
5.1
setPortback to summary
public URIBuilder setPort(final int port)

Sets URI port.

Returns:URIBuilder

this.

setSchemeback to summary
public URIBuilder setScheme(final String scheme)

Sets URI scheme.

Returns:URIBuilder

this.

setSchemeSpecificPartback to summary
public URIBuilder setSchemeSpecificPart(final String schemeSpecificPart)

Sets the URI scheme specific part.

Returns:URIBuilder

this.

Since
5.1
setSchemeSpecificPartback to summary
public URIBuilder setSchemeSpecificPart(final String schemeSpecificPart, final NameValuePair... nvps)

Sets the URI scheme specific part and append a variable arguments list of NameValuePair instance(s) to this part.

Parameters
nvps:NameValuePair[]

Optional, can be null. Variable arguments list of NameValuePair query parameters to be reused by the specific scheme part

Returns:URIBuilder

this.

Since
5.1
setSchemeSpecificPartback to summary
public URIBuilder setSchemeSpecificPart(final String schemeSpecificPart, final List<NameValuePair> nvps)

Sets the URI scheme specific part and append a list of NameValuePair to this part.

Parameters
nvps:List<NameValuePair>

Optional, can be null. List of query parameters to be reused by the specific scheme part

Returns:URIBuilder

this.

Since
5.1
setUserInfoback to summary
public URIBuilder setUserInfo(final String userInfo)

Sets URI user info. The value is expected to be unescaped and may contain non ASCII characters.

Returns:URIBuilder

this.

setUserInfoback to summary
public URIBuilder setUserInfo(final String username, final String password)

Deprecated

The use of clear-text passwords in URIs 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:URIBuilder

this.

Annotations
@Deprecated
splitPathback to summary
pack-priv static List<String> splitPath(final CharSequence s)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Converts this instance to a URI string.

Returns:String

this instance to a URI string.

Annotations
@Override