Class URIBuilder


  • public class URIBuilder
    extends java.lang.Object
    Builder for URI instances.
    Since:
    4.2
    • Constructor Detail

      • URIBuilder

        public URIBuilder()
        Constructs an empty instance.
      • URIBuilder

        public URIBuilder​(java.lang.String string)
                   throws java.net.URISyntaxException
        Construct an instance from the string which must be a valid URI.
        Parameters:
        string - a valid URI in string form
        Throws:
        java.net.URISyntaxException - if the input is not a valid URI
      • URIBuilder

        public URIBuilder​(java.net.URI uri)
        Construct an instance from the provided URI.
        Parameters:
        uri -
      • URIBuilder

        public URIBuilder​(java.lang.String string,
                          java.nio.charset.Charset charset)
                   throws java.net.URISyntaxException
        Construct an instance from the string which must be a valid URI.
        Parameters:
        string - a valid URI in string form
        Throws:
        java.net.URISyntaxException - if the input is not a valid URI
      • URIBuilder

        public URIBuilder​(java.net.URI uri,
                          java.nio.charset.Charset charset)
        Construct an instance from the provided URI.
        Parameters:
        uri -
    • Method Detail

      • setCharset

        public URIBuilder setCharset​(java.nio.charset.Charset charset)
        Since:
        4.4
      • getCharset

        public java.nio.charset.Charset getCharset()
        Since:
        4.4
      • build

        public java.net.URI build()
                           throws java.net.URISyntaxException
        Builds a URI instance.
        Throws:
        java.net.URISyntaxException
      • setScheme

        public URIBuilder setScheme​(java.lang.String scheme)
        Sets URI scheme.
      • setUserInfo

        public URIBuilder setUserInfo​(java.lang.String userInfo)
        Sets URI user info. The value is expected to be unescaped and may contain non ASCII characters.
      • setUserInfo

        public URIBuilder setUserInfo​(java.lang.String username,
                                      java.lang.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​(java.lang.String host)
        Sets URI host.
      • setPort

        public URIBuilder setPort​(int port)
        Sets URI port.
      • setPath

        public URIBuilder setPath​(java.lang.String path)
        Sets URI path. The value is expected to be unescaped and may contain non ASCII characters.
        Returns:
        this.
      • setPathSegments

        public URIBuilder setPathSegments​(java.lang.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​(java.util.List<java.lang.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.
      • setParameters

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

        Since:
        4.3
      • addParameters

        public URIBuilder addParameters​(java.util.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.

        Since:
        4.3
      • 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.

        Since:
        4.3
      • addParameter

        public URIBuilder addParameter​(java.lang.String param,
                                       java.lang.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​(java.lang.String param,
                                       java.lang.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​(java.lang.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​(java.lang.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 java.lang.String getScheme()
      • getUserInfo

        public java.lang.String getUserInfo()
      • getHost

        public java.lang.String getHost()
      • getPort

        public int getPort()
      • isPathEmpty

        public boolean isPathEmpty()
        Since:
        4.5.8
      • getPathSegments

        public java.util.List<java.lang.String> getPathSegments()
        Since:
        4.5.8
      • getPath

        public java.lang.String getPath()
      • isQueryEmpty

        public boolean isQueryEmpty()
        Since:
        4.5.8
      • getQueryParams

        public java.util.List<NameValuePair> getQueryParams()
      • getFragment

        public java.lang.String getFragment()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object