org.apache.hc.core5.net

## Class URIBuilder

- java.lang.Object
- - org.apache.hc.core5.net.URIBuilder

-     public class URIBuilder
      extends Object

  Builder for `URI` instances.
  Since:
    5.0

- - ### 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
    Modifier and Type | Method and Description
    --- | ---
    `URIBuilder` | `addParameter(String param, String value)` Adds parameter to URI query.
    `URIBuilder` | `addParameters(List<NameValuePair> nvps)` 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.
    `Charset` | `getCharset()`
    `String` | `getFragment()`
    `String` | `getHost()` Gets the host portion of the `URI`.
    `String` | `getPath()`
    `List<String>` | `getPathSegments()`
    `int` | `getPort()`
    `List<NameValuePair>` | `getQueryParams()`
    `String` | `getScheme()`
    `String` | `getSchemeSpecificPart()` Gets the scheme specific part
    `String` | `getUserInfo()`
    `boolean` | `isAbsolute()`
    `boolean` | `isOpaque()`
    `boolean` | `isPathEmpty()`
    `boolean` | `isQueryEmpty()`
    `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()` 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
    `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(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> nvps)` Sets URI query parameters.
    `URIBuilder` | `setParameters(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` | `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()`

    - ### 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

    - #### localhost

          public static URIBuilder localhost()
                                      throws UnknownHostException

      Creates a new builder for the host `InetAddress.getLocalHost()`.
      Returns:
        a new builder.
      Throws:
        `UnknownHostException` - if the local host name could not be resolved into an address.

    - #### loopbackAddress

          public static URIBuilder loopbackAddress()

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

    - #### setCharset

          public URIBuilder setCharset(Charset charset)

    - #### getCharset

          public Charset getCharset()

    - #### build

          public URI build()
                    throws URISyntaxException

      Builds a `URI` instance.
      Throws:
        `URISyntaxException`

    - #### setScheme

          public URIBuilder setScheme(String scheme)

      Sets URI scheme.
      Returns:
        this.

    - #### setSchemeSpecificPart

          public URIBuilder setSchemeSpecificPart(String schemeSpecificPart)

      Sets the URI scheme specific part.
      Parameters:
        `schemeSpecificPart` -
      Returns:
        this.
      Since:
        5.1

    - #### setSchemeSpecificPart

          public 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.
      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

          public URIBuilder setSchemeSpecificPart(String schemeSpecificPart,
                                         List<NameValuePair> nvps)

      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

          public URIBuilder setUserInfo(String userInfo)

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

    - #### setUserInfo

          @Deprecated
          public URIBuilder setUserInfo(String username,
                                          String password)

      Deprecated. The use of clear-text passwords in `URI`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

          public URIBuilder setHost(InetAddress host)

      Sets URI host.
      Returns:
        this.

    - #### setHost

          public URIBuilder setHost(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:
        this.

    - #### setHttpHost

          public URIBuilder setHttpHost(HttpHost httpHost)

      Sets the scheme, host name, and port.
      Parameters:
        `httpHost` - the scheme, host name, and port.
      Returns:
        this.

    - #### setPort

          public URIBuilder setPort(int port)

      Sets URI port.
      Returns:
        this.

    - #### setPath

          public URIBuilder setPath(String path)

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

    - #### appendPath

          public URIBuilder appendPath(String path)

      Appends path to URI. 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.

    - #### appendPathSegments

          public URIBuilder appendPathSegments(String... pathSegments)

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

    - #### setPathSegmentsRootless

          public URIBuilder setPathSegmentsRootless(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:
        this.
      Since:
        5.1

    - #### 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.

    - #### appendPathSegments

          public URIBuilder appendPathSegments(List<String> pathSegments)

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

    - #### setPathSegmentsRootless

          public URIBuilder setPathSegmentsRootless(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:
        this.
      Since:
        5.1

    - #### removeQuery

          public URIBuilder removeQuery()

      Removes URI query.
      Returns:
        this.

    - #### setParameters

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

      Returns:
        this.

    - #### addParameters

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

      Returns:
        this.

    - #### setParameters

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

      Returns:
        this.

    - #### 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.

      Returns:
        this.

    - #### 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.

      Returns:
        this.

    - #### clearParameters

          public URIBuilder clearParameters()

      Clears URI query parameters.
      Returns:
        this.

    - #### 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.

      Returns:
        this.

    - #### setFragment

          public URIBuilder setFragment(String fragment)

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

    - #### isAbsolute

          public boolean isAbsolute()

    - #### isOpaque

          public boolean isOpaque()

    - #### getScheme

          public String getScheme()

    - #### getSchemeSpecificPart

          public String getSchemeSpecificPart()

      Gets the scheme specific part
      Returns:
        String
      Since:
        5.1

    - #### getUserInfo

          public String getUserInfo()

    - #### getHost

          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:
        The host portion of the URI.

    - #### getPort

          public int getPort()

    - #### isPathEmpty

          public boolean isPathEmpty()

    - #### getPathSegments

          public List<String> getPathSegments()

    - #### getPath

          public String getPath()

    - #### isQueryEmpty

          public boolean isQueryEmpty()

    - #### getQueryParams

          public List<NameValuePair> getQueryParams()

    - #### getFragment

          public String getFragment()

    - #### normalizeSyntax

          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

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2005–2022 The Apache Software Foundation. All rights reserved.