Class URIBuilder
- java.lang.Object
-
- org.apache.http.client.utils.URIBuilder
-
public class URIBuilder extends java.lang.Object
Builder forURI
instances.- Since:
- 4.2
-
-
Constructor Summary
Constructors Constructor Description URIBuilder()
Constructs an empty instance.URIBuilder(java.lang.String string)
Construct an instance from the string which must be a valid URI.URIBuilder(java.lang.String string, java.nio.charset.Charset charset)
Construct an instance from the string which must be a valid URI.URIBuilder(java.net.URI uri)
Construct an instance from the provided URI.URIBuilder(java.net.URI uri, java.nio.charset.Charset charset)
Construct an instance from the provided URI.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description URIBuilder
addParameter(java.lang.String param, java.lang.String value)
Adds parameter to URI query.URIBuilder
addParameters(java.util.List<NameValuePair> nvps)
Adds URI query parameters.java.net.URI
build()
Builds aURI
instance.URIBuilder
clearParameters()
Clears URI query parameters.java.nio.charset.Charset
getCharset()
java.lang.String
getFragment()
java.lang.String
getHost()
java.lang.String
getPath()
java.util.List<java.lang.String>
getPathSegments()
int
getPort()
java.util.List<NameValuePair>
getQueryParams()
java.lang.String
getScheme()
java.lang.String
getUserInfo()
boolean
isAbsolute()
boolean
isOpaque()
boolean
isPathEmpty()
boolean
isQueryEmpty()
URIBuilder
removeQuery()
Removes URI query.URIBuilder
setCharset(java.nio.charset.Charset charset)
URIBuilder
setCustomQuery(java.lang.String query)
Sets custom URI query.URIBuilder
setFragment(java.lang.String fragment)
Sets URI fragment.URIBuilder
setHost(java.lang.String host)
Sets URI host.URIBuilder
setParameter(java.lang.String param, java.lang.String value)
Sets parameter of URI query overriding existing value if set.URIBuilder
setParameters(java.util.List<NameValuePair> nvps)
Sets URI query parameters.URIBuilder
setParameters(NameValuePair... nvps)
Sets URI query parameters.URIBuilder
setPath(java.lang.String path)
Sets URI path.URIBuilder
setPathSegments(java.lang.String... pathSegments)
Sets URI path.URIBuilder
setPathSegments(java.util.List<java.lang.String> pathSegments)
Sets URI path.URIBuilder
setPort(int port)
Sets URI port.URIBuilder
setQuery(java.lang.String query)
Deprecated.(4.3) usesetParameters(List)
orsetParameters(NameValuePair...)
URIBuilder
setScheme(java.lang.String scheme)
Sets URI scheme.URIBuilder
setUserInfo(java.lang.String userInfo)
Sets URI user info.URIBuilder
setUserInfo(java.lang.String username, java.lang.String password)
Sets URI user info as a combination of username and password.java.lang.String
toString()
-
-
-
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 aURI
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.
-
setQuery
@Deprecated public URIBuilder setQuery(java.lang.String query)
Deprecated.(4.3) usesetParameters(List)
orsetParameters(NameValuePair...)
Sets URI query.The value is expected to be encoded form data.
-
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 classjava.lang.Object
-
-