Class URIBuilder


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

      • scheme

        private java.lang.String scheme
      • encodedSchemeSpecificPart

        private java.lang.String encodedSchemeSpecificPart
      • encodedAuthority

        private java.lang.String encodedAuthority
      • userInfo

        private java.lang.String userInfo
      • encodedUserInfo

        private java.lang.String encodedUserInfo
      • host

        private java.lang.String host
      • port

        private int port
      • encodedPath

        private java.lang.String encodedPath
      • pathSegments

        private java.util.List<java.lang.String> pathSegments
      • encodedQuery

        private java.lang.String encodedQuery
      • queryParams

        private java.util.List<org.apache.http.NameValuePair> queryParams
      • query

        private java.lang.String query
      • charset

        private java.nio.charset.Charset charset
      • fragment

        private java.lang.String fragment
      • encodedFragment

        private java.lang.String encodedFragment
    • 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 -
    • Method Detail

      • setCharset

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

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

        private java.util.List<org.apache.http.NameValuePair> parseQuery​(java.lang.String query,
                                                                         java.nio.charset.Charset charset)
      • parsePath

        private java.util.List<java.lang.String> parsePath​(java.lang.String path,
                                                           java.nio.charset.Charset charset)
      • build

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

        private java.lang.String buildString()
      • normalizePath

        private static java.lang.String normalizePath​(java.lang.String path,
                                                      boolean relative)
      • digestURI

        private void digestURI​(java.net.URI uri)
      • encodeUserInfo

        private java.lang.String encodeUserInfo​(java.lang.String userInfo)
      • encodePath

        private java.lang.String encodePath​(java.util.List<java.lang.String> pathSegments)
      • encodeUrlForm

        private java.lang.String encodeUrlForm​(java.util.List<org.apache.http.NameValuePair> params)
      • encodeUric

        private java.lang.String encodeUric​(java.lang.String fragment)
      • 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<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​(java.util.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​(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<org.apache.http.NameValuePair> getQueryParams()
      • getFragment

        public java.lang.String getFragment()
      • toString

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