public abstract class UriUtils
extends java.lang.Object
All encode*(String, String)
methods in this class operate in a similar way:
%xy
"
format.Constructor and Description |
---|
UriUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
decode(java.lang.String source,
java.nio.charset.Charset charset)
Decode the given encoded URI component.
|
static java.lang.String |
decode(java.lang.String source,
java.lang.String encoding)
Decode the given encoded URI component.
|
static java.lang.String |
encode(java.lang.String source,
java.nio.charset.Charset charset)
Encode characters outside the unreserved character set as defined in
RFC 3986 Section 2.
|
static java.lang.String |
encode(java.lang.String source,
java.lang.String encoding)
Encode characters outside the unreserved character set as defined in
RFC 3986 Section 2.
|
static java.lang.String |
encodeAuthority(java.lang.String authority,
java.nio.charset.Charset charset)
Encode the given URI authority with the given encoding.
|
static java.lang.String |
encodeAuthority(java.lang.String authority,
java.lang.String encoding)
Encode the given URI authority with the given encoding.
|
static java.lang.String |
encodeFragment(java.lang.String fragment,
java.nio.charset.Charset charset)
Encode the given URI fragment with the given encoding.
|
static java.lang.String |
encodeFragment(java.lang.String fragment,
java.lang.String encoding)
Encode the given URI fragment with the given encoding.
|
static java.lang.String |
encodeHost(java.lang.String host,
java.nio.charset.Charset charset)
Encode the given URI host with the given encoding.
|
static java.lang.String |
encodeHost(java.lang.String host,
java.lang.String encoding)
Encode the given URI host with the given encoding.
|
static java.lang.String |
encodePath(java.lang.String path,
java.nio.charset.Charset charset)
Encode the given URI path with the given encoding.
|
static java.lang.String |
encodePath(java.lang.String path,
java.lang.String encoding)
Encode the given URI path with the given encoding.
|
static java.lang.String |
encodePathSegment(java.lang.String segment,
java.nio.charset.Charset charset)
Encode the given URI path segment with the given encoding.
|
static java.lang.String |
encodePathSegment(java.lang.String segment,
java.lang.String encoding)
Encode the given URI path segment with the given encoding.
|
static java.lang.String |
encodePort(java.lang.String port,
java.nio.charset.Charset charset)
Encode the given URI port with the given encoding.
|
static java.lang.String |
encodePort(java.lang.String port,
java.lang.String encoding)
Encode the given URI port with the given encoding.
|
static java.lang.String |
encodeQuery(java.lang.String query,
java.nio.charset.Charset charset)
Encode the given URI query with the given encoding.
|
static java.lang.String |
encodeQuery(java.lang.String query,
java.lang.String encoding)
Encode the given URI query with the given encoding.
|
static java.lang.String |
encodeQueryParam(java.lang.String queryParam,
java.nio.charset.Charset charset)
Encode the given URI query parameter with the given encoding.
|
static java.lang.String |
encodeQueryParam(java.lang.String queryParam,
java.lang.String encoding)
Encode the given URI query parameter with the given encoding.
|
static java.lang.String |
encodeScheme(java.lang.String scheme,
java.nio.charset.Charset charset)
Encode the given URI scheme with the given encoding.
|
static java.lang.String |
encodeScheme(java.lang.String scheme,
java.lang.String encoding)
Encode the given URI scheme with the given encoding.
|
static java.util.Map<java.lang.String,java.lang.String> |
encodeUriVariables(java.util.Map<java.lang.String,?> uriVariables)
Apply
encode(String, String) to the values in the given URI
variables and return a new Map containing the encoded values. |
static java.lang.Object[] |
encodeUriVariables(java.lang.Object... uriVariables)
Apply
encode(String, String) to the values in the given URI
variables and return a new array containing the encoded values. |
static java.lang.String |
encodeUserInfo(java.lang.String userInfo,
java.nio.charset.Charset charset)
Encode the given URI user info with the given encoding.
|
static java.lang.String |
encodeUserInfo(java.lang.String userInfo,
java.lang.String encoding)
Encode the given URI user info with the given encoding.
|
static java.lang.String |
extractFileExtension(java.lang.String path)
Extract the file extension from the given URI path.
|
public static java.lang.String encodeScheme(java.lang.String scheme, java.lang.String encoding) throws java.io.UnsupportedEncodingException
scheme
- the scheme to be encodedencoding
- the character encoding to encode tojava.io.UnsupportedEncodingException
- when the given encoding parameter is not supportedpublic static java.lang.String encodeScheme(java.lang.String scheme, java.nio.charset.Charset charset)
scheme
- the scheme to be encodedcharset
- the character encoding to encode topublic static java.lang.String encodeAuthority(java.lang.String authority, java.lang.String encoding) throws java.io.UnsupportedEncodingException
authority
- the authority to be encodedencoding
- the character encoding to encode tojava.io.UnsupportedEncodingException
- when the given encoding parameter is not supportedpublic static java.lang.String encodeAuthority(java.lang.String authority, java.nio.charset.Charset charset)
authority
- the authority to be encodedcharset
- the character encoding to encode topublic static java.lang.String encodeUserInfo(java.lang.String userInfo, java.lang.String encoding) throws java.io.UnsupportedEncodingException
userInfo
- the user info to be encodedencoding
- the character encoding to encode tojava.io.UnsupportedEncodingException
- when the given encoding parameter is not supportedpublic static java.lang.String encodeUserInfo(java.lang.String userInfo, java.nio.charset.Charset charset)
userInfo
- the user info to be encodedcharset
- the character encoding to encode topublic static java.lang.String encodeHost(java.lang.String host, java.lang.String encoding) throws java.io.UnsupportedEncodingException
host
- the host to be encodedencoding
- the character encoding to encode tojava.io.UnsupportedEncodingException
- when the given encoding parameter is not supportedpublic static java.lang.String encodeHost(java.lang.String host, java.nio.charset.Charset charset)
host
- the host to be encodedcharset
- the character encoding to encode topublic static java.lang.String encodePort(java.lang.String port, java.lang.String encoding) throws java.io.UnsupportedEncodingException
port
- the port to be encodedencoding
- the character encoding to encode tojava.io.UnsupportedEncodingException
- when the given encoding parameter is not supportedpublic static java.lang.String encodePort(java.lang.String port, java.nio.charset.Charset charset)
port
- the port to be encodedcharset
- the character encoding to encode topublic static java.lang.String encodePath(java.lang.String path, java.lang.String encoding) throws java.io.UnsupportedEncodingException
path
- the path to be encodedencoding
- the character encoding to encode tojava.io.UnsupportedEncodingException
- when the given encoding parameter is not supportedpublic static java.lang.String encodePath(java.lang.String path, java.nio.charset.Charset charset)
path
- the path to be encodedcharset
- the character encoding to encode topublic static java.lang.String encodePathSegment(java.lang.String segment, java.lang.String encoding) throws java.io.UnsupportedEncodingException
segment
- the segment to be encodedencoding
- the character encoding to encode tojava.io.UnsupportedEncodingException
- when the given encoding parameter is not supportedpublic static java.lang.String encodePathSegment(java.lang.String segment, java.nio.charset.Charset charset)
segment
- the segment to be encodedcharset
- the character encoding to encode topublic static java.lang.String encodeQuery(java.lang.String query, java.lang.String encoding) throws java.io.UnsupportedEncodingException
query
- the query to be encodedencoding
- the character encoding to encode tojava.io.UnsupportedEncodingException
- when the given encoding parameter is not supportedpublic static java.lang.String encodeQuery(java.lang.String query, java.nio.charset.Charset charset)
query
- the query to be encodedcharset
- the character encoding to encode topublic static java.lang.String encodeQueryParam(java.lang.String queryParam, java.lang.String encoding) throws java.io.UnsupportedEncodingException
queryParam
- the query parameter to be encodedencoding
- the character encoding to encode tojava.io.UnsupportedEncodingException
- when the given encoding parameter is not supportedpublic static java.lang.String encodeQueryParam(java.lang.String queryParam, java.nio.charset.Charset charset)
queryParam
- the query parameter to be encodedcharset
- the character encoding to encode topublic static java.lang.String encodeFragment(java.lang.String fragment, java.lang.String encoding) throws java.io.UnsupportedEncodingException
fragment
- the fragment to be encodedencoding
- the character encoding to encode tojava.io.UnsupportedEncodingException
- when the given encoding parameter is not supportedpublic static java.lang.String encodeFragment(java.lang.String fragment, java.nio.charset.Charset charset)
fragment
- the fragment to be encodedcharset
- the character encoding to encode topublic static java.lang.String encode(java.lang.String source, java.lang.String encoding) throws java.io.UnsupportedEncodingException
This can be used to ensure the given String will not contain any characters with reserved URI meaning regardless of URI component.
source
- the String to be encodedencoding
- the character encoding to encode tojava.io.UnsupportedEncodingException
- when the given encoding parameter is not supportedpublic static java.lang.String encode(java.lang.String source, java.nio.charset.Charset charset)
This can be used to ensure the given String will not contain any characters with reserved URI meaning regardless of URI component.
source
- the String to be encodedcharset
- the character encoding to encode topublic static java.lang.String decode(java.lang.String source, java.lang.String encoding) throws java.io.UnsupportedEncodingException
See StringUtils.uriDecode(String, Charset)
for the decoding rules.
source
- the encoded Stringencoding
- the character encoding to usejava.lang.IllegalArgumentException
- when the given source contains invalid encoded sequencesjava.io.UnsupportedEncodingException
- when the given encoding parameter is not supportedStringUtils.uriDecode(String, Charset)
,
URLDecoder.decode(String, String)
public static java.lang.String decode(java.lang.String source, java.nio.charset.Charset charset)
See StringUtils.uriDecode(String, Charset)
for the decoding rules.
source
- the encoded Stringcharset
- the character encoding to usejava.lang.IllegalArgumentException
- when the given source contains invalid encoded sequencesStringUtils.uriDecode(String, Charset)
,
URLDecoder.decode(String, String)
@Nullable public static java.lang.String extractFileExtension(java.lang.String path)
path
- the URI path (e.g. "/products/index.html")public static java.util.Map<java.lang.String,java.lang.String> encodeUriVariables(java.util.Map<java.lang.String,?> uriVariables)
encode(String, String)
to the values in the given URI
variables and return a new Map containing the encoded values.uriVariables
- the URI variable values to be encodedpublic static java.lang.Object[] encodeUriVariables(java.lang.Object... uriVariables)
encode(String, String)
to the values in the given URI
variables and return a new array containing the encoded values.uriVariables
- the URI variable values to be encoded