org.apache.http.client.utils

## Class URIBuilder

- java.lang.Object
- - org.apache.http.client.utils.URIBuilder

    public class URIBuilder
    extends Object

Builder for `URI` instances.

Since:
  4.2

### Constructor Summary

Constructors
Constructor and Description
`URIBuilder()` Constructs an empty instance.
`URIBuilder(String string)` Construct an instance from the string which must be a valid URI.
`URIBuilder(String string, Charset charset)` Construct an instance from the string which must be a valid URI.
`URIBuilder(URI uri)` Construct an instance from the provided URI.
`URIBuilder(URI uri, Charset charset)` Construct an instance from the provided URI.

### Method Summary

Methods
`URIBuilder` `addParameter(String param, String value)` Adds parameter to URI query.
`URIBuilder` `addParameters(List<org.apache.http.NameValuePair> nvps)` Adds URI query parameters.
`URI` `build()` Builds a `URI` instance.
`URIBuilder` `clearParameters()` Clears URI query parameters.
`Charset` `getCharset()`
`String` `getFragment()`
`String` `getHost()`
`String` `getPath()`
`List<String>` `getPathSegments()`
`int` `getPort()`
`List<org.apache.http.NameValuePair>` `getQueryParams()`
`String` `getScheme()`
`String` `getUserInfo()`
`boolean` `isAbsolute()`
`boolean` `isOpaque()`
`boolean` `isPathEmpty()`
`boolean` `isQueryEmpty()`
`URIBuilder` `removeQuery()` Removes URI query.
`URIBuilder` `setCharset(Charset charset)`
`URIBuilder` `setCustomQuery(String query)` Sets custom URI query.
`URIBuilder` `setFragment(String fragment)` Sets URI fragment.
`URIBuilder` `setHost(String host)` Sets URI host.
`URIBuilder` `setParameter(String param, String value)` Sets parameter of URI query overriding existing value if set.
`URIBuilder` `setParameters(List<org.apache.http.NameValuePair> nvps)` Sets URI query parameters.
`URIBuilder` `setParameters(org.apache.http.NameValuePair... nvps)` 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` `setPort(int port)` Sets URI port.
`URIBuilder` `setQuery(String query)` Deprecated. (4.3) use `setParameters(List)` or `setParameters(NameValuePair...)`
`URIBuilder` `setScheme(String scheme)` Sets URI scheme.
`URIBuilder` `setUserInfo(String userInfo)` Sets URI user info.
`URIBuilder` `setUserInfo(String username, String password)` Sets URI user info as a combination of username and password.
`String` `toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### URIBuilder

    public URIBuilder()

Constructs an empty instance.

#### URIBuilder

    public URIBuilder(String string)
               throws URISyntaxException

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

Parameters:
  `string` - a valid URI in string form
Throws:
  `URISyntaxException` - if the input is not a valid URI

#### URIBuilder

    public URIBuilder(URI uri)

Construct an instance from the provided URI.

Parameters:
  `uri` -

#### URIBuilder

    public URIBuilder(String string,
              Charset charset)
               throws URISyntaxException

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

Parameters:
  `string` - a valid URI in string form
Throws:
  `URISyntaxException` - if the input is not a valid URI

#### URIBuilder

    public URIBuilder(URI uri,
              Charset charset)

Construct an instance from the provided URI.

Parameters:
  `uri` -

### Method Detail

#### setCharset

    public URIBuilder setCharset(Charset charset)

Since:
  4.4

#### getCharset

    public Charset getCharset()

Since:
  4.4

#### build

    public URI build()
              throws URISyntaxException

Builds a `URI` instance.

Throws:
  `URISyntaxException`

#### setScheme

    public URIBuilder setScheme(String scheme)

Sets URI scheme.

#### setUserInfo

    public URIBuilder setUserInfo(String userInfo)

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

#### setUserInfo

    public URIBuilder setUserInfo(String username,
                         String password)

Sets URI user info as a combination of username and password. These values are expected to be unescaped and may contain non ASCII characters.

#### setHost

    public URIBuilder setHost(String host)

Sets URI host.

#### setPort

    public URIBuilder setPort(int port)

Sets URI port.

#### setPath

    public URIBuilder setPath(String path)

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

Returns:
  this.

#### setPathSegments

    public URIBuilder setPathSegments(String... pathSegments)

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

Returns:
  this.
Since:
  4.5.8

#### setPathSegments

    public URIBuilder setPathSegments(List<String> pathSegments)

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

Returns:
  this.
Since:
  4.5.8

#### removeQuery

    public URIBuilder removeQuery()

Removes URI query.

#### setQuery

    @Deprecated
    public URIBuilder setQuery(String query)

Deprecated. (4.3) use `setParameters(List)` or `setParameters(NameValuePair...)`
Sets URI query.

The value is expected to be encoded form data.

See Also:
  `URLEncodedUtils.parse(java.net.URI, java.lang.String)`

#### setParameters

    public URIBuilder setParameters(List<org.apache.http.NameValuePair> nvps)

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.

Since:
  4.3

#### addParameters

    public URIBuilder addParameters(List<org.apache.http.NameValuePair> nvps)

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.

Since:
  4.3

#### setParameters

    public URIBuilder setParameters(org.apache.http.NameValuePair... nvps)

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.

Since:
  4.3

#### addParameter

    public URIBuilder addParameter(String param,
                          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.

#### setParameter

    public URIBuilder setParameter(String param,
                          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.

#### clearParameters

    public URIBuilder clearParameters()

Clears URI query parameters.

Since:
  4.3

#### setCustomQuery

    public URIBuilder setCustomQuery(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.

Since:
  4.3

#### setFragment

    public URIBuilder setFragment(String fragment)

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

#### isAbsolute

    public boolean isAbsolute()

Since:
  4.3

#### isOpaque

    public boolean isOpaque()

Since:
  4.3

#### getScheme

    public String getScheme()

#### getUserInfo

    public String getUserInfo()

#### getHost

    public String getHost()

#### getPort

    public int getPort()

#### isPathEmpty

    public boolean isPathEmpty()

Since:
  4.5.8

#### getPathSegments

    public List<String> getPathSegments()

Since:
  4.5.8

#### getPath

    public String getPath()

#### isQueryEmpty

    public boolean isQueryEmpty()

Since:
  4.5.8

#### getQueryParams

    public List<org.apache.http.NameValuePair> getQueryParams()

#### getFragment

    public String getFragment()

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`