Top Description Constructors Methods
org.apache.hc.client5.http.utils

public Class URIUtils

extends Object
Class Inheritance
Imports
java.net.URI, .URISyntaxException, java.util.ArrayList, .Iterator, .List, .Locale, org.apache.hc.core5.http.HttpHost, .URIScheme, org.apache.hc.core5.net.URIAuthority, .URIBuilder, org.apache.hc.core5.util.Args, .TextUtils

A collection of utilities for URIs, to workaround bugs within the class or for ease-of-use features.
Since
4.0

Constructor Summary

AccessConstructor and Description
private
URIUtils()

This class should not be instantiated.

Method Summary

Modifier and TypeMethod and Description
public static URI
create(final HttpHost host, final String path)

Deprecated Use URIBuilder.
Convenience factory method for URI instances.
public static URI
create(final String scheme, final URIAuthority host, final String path)

Deprecated Use URIBuilder.
Convenience factory method for URI instances.
public static HttpHost

Returns:

the target host if the URI is absolute or null if the URI is relative or does not contain a valid host name.
extractHost
(final URI uri)

Extracts target host from the given URI.

pack-priv static URI

Returns:

the URI without dot segments
normalizeSyntax
(final URI
the original URI
uri
)

Removes dot segments and performs Syntax-Based Normalization.

public static URI

Returns:

the resulting URI
resolve
(final URI
the base URI
baseURI
,
final String
the URI reference
reference
)

Resolves a URI reference against a base URI.

public static URI

Returns:

the resulting URI
resolve
(final URI
the base URI
baseURI
,
final URI
the URI reference
reference
)

Resolves a URI reference against a base URI.

public static URI

Returns:

interpreted (absolute) URI
resolve
(final URI
original request before any redirects
originalURI
,
final HttpHost
if the last URI is relative, it is resolved against this target, or null if not available.
target
,
final List<URI>
collection of redirect locations since the original request or null if not available.
redirects
)

Derives the interpreted (absolute) URI that was used to generate the last request.

public static URI
rewriteURI(final URI
Contains the path, query and fragment to use.
uri
,
final HttpHost
Contains the scheme, host and port to use.
target
,
final boolean
True if the fragment should not be copied.
dropFragment
)

Deprecated Use URIBuilder.
A convenience method for creating a new URI whose scheme, host and port are taken from the target host, but whose path, query and fragment are taken from the existing URI.
public static URI
rewriteURI(final URI uri, final HttpHost target)

Deprecated Use URIBuilder.
A convenience method for URIUtils#rewriteURI(URI, HttpHost, boolean) that always keeps the fragment.
public static URI
rewriteURI(final URI
original URI.
uri
)

Deprecated Use URIBuilder.
A convenience method that creates a new URI whose scheme, host, port, path, query are taken from the existing URI, dropping any fragment or user-information.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

URIUtilsback to summary
private URIUtils()

This class should not be instantiated.

Method Detail

createback to summary
public static URI create(final HttpHost host, final String path) throws URISyntaxException

Deprecated

Use URIBuilder.

Convenience factory method for URI instances.

Annotations
@Deprecated
Since
5.0
createback to summary
public static URI create(final String scheme, final URIAuthority host, final String path) throws URISyntaxException

Deprecated

Use URIBuilder.

Convenience factory method for URI instances.

Annotations
@Deprecated
Since
5.0
extractHostback to summary
public static HttpHost extractHost(final URI uri)

Extracts target host from the given URI.

Returns:HttpHost

the target host if the URI is absolute or null if the URI is relative or does not contain a valid host name.

Since
4.1
normalizeSyntaxback to summary
pack-priv static URI normalizeSyntax(final URI uri) throws URISyntaxException

Removes dot segments and performs Syntax-Based Normalization.

Parameters
uri:URI

the original URI

Returns:URI

the URI without dot segments

resolveback to summary
public static URI resolve(final URI baseURI, final String reference)

Resolves a URI reference against a base URI. Work-around for bug in java.net.URI (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535)

Parameters
baseURI:URI

the base URI

reference:String

the URI reference

Returns:URI

the resulting URI

resolveback to summary
public static URI resolve(final URI baseURI, final URI reference)

Resolves a URI reference against a base URI. Work-around for bugs in java.net.URI (e.g. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535)

Parameters
baseURI:URI

the base URI

reference:URI

the URI reference

Returns:URI

the resulting URI

resolveback to summary
public static URI resolve(final URI originalURI, final HttpHost target, final List<URI> redirects) throws URISyntaxException

Derives the interpreted (absolute) URI that was used to generate the last request. This is done by extracting the request-uri and target origin for the last request and scanning all the redirect locations for the last fragment identifier, then combining the result into a URI.

Parameters
originalURI:URI

original request before any redirects

target:HttpHost

if the last URI is relative, it is resolved against this target, or null if not available.

redirects:List<URI>

collection of redirect locations since the original request or null if not available.

Returns:URI

interpreted (absolute) URI

rewriteURIback to summary
public static URI rewriteURI(final URI uri, final HttpHost target, final boolean dropFragment) throws URISyntaxException

Deprecated

Use URIBuilder.

A convenience method for creating a new URI whose scheme, host and port are taken from the target host, but whose path, query and fragment are taken from the existing URI. The fragment is only used if dropFragment is false. The path is set to "/" if not explicitly specified.

Parameters
uri:URI

Contains the path, query and fragment to use.

target:HttpHost

Contains the scheme, host and port to use.

dropFragment:boolean

True if the fragment should not be copied.

Annotations
@Deprecated
Exceptions
URISyntaxException:
If the resulting URI is invalid.
rewriteURIback to summary
public static URI rewriteURI(final URI uri, final HttpHost target) throws URISyntaxException

Deprecated

Use URIBuilder.

A convenience method for URIUtils#rewriteURI(URI, HttpHost, boolean) that always keeps the fragment.

Annotations
@Deprecated
rewriteURIback to summary
public static URI rewriteURI(final URI uri) throws URISyntaxException

Deprecated

Use URIBuilder.

A convenience method that creates a new URI whose scheme, host, port, path, query are taken from the existing URI, dropping any fragment or user-information. The path is set to "/" if not explicitly specified. The existing URI is returned unmodified if it has no fragment or user-information and has a path.

Parameters
uri:URI

original URI.

Annotations
@Deprecated
Exceptions
URISyntaxException:
If the resulting URI is invalid.