类 UriUtils
- java.lang.Object
- org.springframework.web.util.UriUtils
public abstract class UriUtils extends Object
Utility class for URI encoding and decoding based on RFC 3986. Offers encoding methods for the various URI components.All
encode*(String, String)
methods in this class operate in a similar way:- Valid characters for the specific URI component as defined in RFC 3986 stay the same.
- All other characters are converted into one or more bytes in the given encoding scheme. Each of the resulting bytes is written as a hexadecimal string in the "
%xy
" format.
- 从以下版本开始:
- 3.0
- 作者:
- Arjen Poutsma, Juergen Hoeller
- 另请参阅:
- RFC 3986
构造器概要
构造器 构造器 说明 UriUtils()
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static String
decode(String source, String encoding)
Decode the given encoded URI component.static String
encode(String source, String encoding)
Encode characters outside the unreserved character set as defined in RFC 3986 Section 2.static String
encodeAuthority(String authority, String encoding)
Encode the given URI authority with the given encoding.static String
encodeFragment(String fragment, String encoding)
Encode the given URI fragment with the given encoding.static String
encodeHost(String host, String encoding)
Encode the given URI host with the given encoding.static String
encodePath(String path, String encoding)
Encode the given URI path with the given encoding.static String
encodePathSegment(String segment, String encoding)
Encode the given URI path segment with the given encoding.static String
encodePort(String port, String encoding)
Encode the given URI port with the given encoding.static String
encodeQuery(String query, String encoding)
Encode the given URI query with the given encoding.static String
encodeQueryParam(String queryParam, String encoding)
Encode the given URI query parameter with the given encoding.static String
encodeScheme(String scheme, String encoding)
Encode the given URI scheme with the given encoding.static String
encodeUserInfo(String userInfo, String encoding)
Encode the given URI user info with the given encoding.static String
extractFileExtension(String path)
Extract the file extension from the given URI path.
构造器详细资料
UriUtils
public UriUtils()
方法详细资料
encodeScheme
public static String encodeScheme(String scheme, String encoding) throws UnsupportedEncodingException
Encode the given URI scheme with the given encoding.- 参数:
scheme
- the scheme to be encodedencoding
- the character encoding to encode to- 返回:
- the encoded scheme
- 抛出:
UnsupportedEncodingException
- when the given encoding parameter is not supported
encodeAuthority
public static String encodeAuthority(String authority, String encoding) throws UnsupportedEncodingException
Encode the given URI authority with the given encoding.- 参数:
authority
- the authority to be encodedencoding
- the character encoding to encode to- 返回:
- the encoded authority
- 抛出:
UnsupportedEncodingException
- when the given encoding parameter is not supported
encodeUserInfo
public static String encodeUserInfo(String userInfo, String encoding) throws UnsupportedEncodingException
Encode the given URI user info with the given encoding.- 参数:
userInfo
- the user info to be encodedencoding
- the character encoding to encode to- 返回:
- the encoded user info
- 抛出:
UnsupportedEncodingException
- when the given encoding parameter is not supported
encodeHost
public static String encodeHost(String host, String encoding) throws UnsupportedEncodingException
Encode the given URI host with the given encoding.- 参数:
host
- the host to be encodedencoding
- the character encoding to encode to- 返回:
- the encoded host
- 抛出:
UnsupportedEncodingException
- when the given encoding parameter is not supported
encodePort
public static String encodePort(String port, String encoding) throws UnsupportedEncodingException
Encode the given URI port with the given encoding.- 参数:
port
- the port to be encodedencoding
- the character encoding to encode to- 返回:
- the encoded port
- 抛出:
UnsupportedEncodingException
- when the given encoding parameter is not supported
encodePath
public static String encodePath(String path, String encoding) throws UnsupportedEncodingException
Encode the given URI path with the given encoding.- 参数:
path
- the path to be encodedencoding
- the character encoding to encode to- 返回:
- the encoded path
- 抛出:
UnsupportedEncodingException
- when the given encoding parameter is not supported
encodePathSegment
public static String encodePathSegment(String segment, String encoding) throws UnsupportedEncodingException
Encode the given URI path segment with the given encoding.- 参数:
segment
- the segment to be encodedencoding
- the character encoding to encode to- 返回:
- the encoded segment
- 抛出:
UnsupportedEncodingException
- when the given encoding parameter is not supported
encodeQuery
public static String encodeQuery(String query, String encoding) throws UnsupportedEncodingException
Encode the given URI query with the given encoding.- 参数:
query
- the query to be encodedencoding
- the character encoding to encode to- 返回:
- the encoded query
- 抛出:
UnsupportedEncodingException
- when the given encoding parameter is not supported
encodeQueryParam
public static String encodeQueryParam(String queryParam, String encoding) throws UnsupportedEncodingException
Encode the given URI query parameter with the given encoding.- 参数:
queryParam
- the query parameter to be encodedencoding
- the character encoding to encode to- 返回:
- the encoded query parameter
- 抛出:
UnsupportedEncodingException
- when the given encoding parameter is not supported
encodeFragment
public static String encodeFragment(String fragment, String encoding) throws UnsupportedEncodingException
Encode the given URI fragment with the given encoding.- 参数:
fragment
- the fragment to be encodedencoding
- the character encoding to encode to- 返回:
- the encoded fragment
- 抛出:
UnsupportedEncodingException
- when the given encoding parameter is not supported
encode
public static String encode(String source, String encoding) throws UnsupportedEncodingException
Encode characters outside the unreserved character set as defined in RFC 3986 Section 2.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 to- 返回:
- the encoded String
- 抛出:
UnsupportedEncodingException
- when the given encoding parameter is not supported
decode
public static String decode(String source, String encoding) throws UnsupportedEncodingException
Decode the given encoded URI component.- Alphanumeric characters
"a"
through"z"
,"A"
through"Z"
, and"0"
through"9"
stay the same. - Special characters
"-"
,"_"
,"."
, and"*"
stay the same. - A sequence "
%<i>xy</i>
" is interpreted as a hexadecimal representation of the character.
- 参数:
source
- the encoded Stringencoding
- the encoding- 返回:
- the decoded value
- 抛出:
IllegalArgumentException
- when the given source contains invalid encoded sequencesUnsupportedEncodingException
- when the given encoding parameter is not supported- 另请参阅:
URLDecoder.decode(String, String)
- Alphanumeric characters
extractFileExtension
public static String extractFileExtension(String path)
Extract the file extension from the given URI path.- 参数:
path
- the URI path (e.g. "/products/index.html")- 返回:
- the extracted file extension (e.g. "html")
- 从以下版本开始:
- 4.3.2