spring-framework / org.springframework.web.util / UriUtils

UriUtils

abstract class UriUtils

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:

Author
Arjen Poutsma

Author
Juergen Hoeller

Since
3.0

See Also
<a href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>

Constructors

<init>

UriUtils()

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.

Functions

decode

open static fun decode(source: String, encoding: String): String
open static fun decode(source: String, charset: Charset): String

Decode the given encoded URI component.

See StringUtils#uriDecode(String, Charset) for the decoding rules.

encode

open static fun encode(source: String, encoding: String): String
open static fun encode(source: String, charset: Charset): String

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.

encodeAuthority

open static fun encodeAuthority(authority: String, encoding: String): String
open static fun encodeAuthority(authority: String, charset: Charset): String

Encode the given URI authority with the given encoding.

encodeFragment

open static fun encodeFragment(fragment: String, encoding: String): String
open static fun encodeFragment(fragment: String, charset: Charset): String

Encode the given URI fragment with the given encoding.

encodeHost

open static fun encodeHost(host: String, encoding: String): String
open static fun encodeHost(host: String, charset: Charset): String

Encode the given URI host with the given encoding.

encodePath

open static fun encodePath(path: String, encoding: String): String
open static fun encodePath(path: String, charset: Charset): String

Encode the given URI path with the given encoding.

encodePathSegment

open static fun encodePathSegment(segment: String, encoding: String): String
open static fun encodePathSegment(segment: String, charset: Charset): String

Encode the given URI path segment with the given encoding.

encodePort

open static fun encodePort(port: String, encoding: String): String
open static fun encodePort(port: String, charset: Charset): String

Encode the given URI port with the given encoding.

encodeQuery

open static fun encodeQuery(query: String, encoding: String): String
open static fun encodeQuery(query: String, charset: Charset): String

Encode the given URI query with the given encoding.

encodeQueryParam

open static fun encodeQueryParam(queryParam: String, encoding: String): String
open static fun encodeQueryParam(queryParam: String, charset: Charset): String

Encode the given URI query parameter with the given encoding.

encodeScheme

open static fun encodeScheme(scheme: String, encoding: String): String
open static fun encodeScheme(scheme: String, charset: Charset): String

Encode the given URI scheme with the given encoding.

encodeUriVariables

open static fun encodeUriVariables(uriVariables: MutableMap<String, *>): MutableMap<String, String>

Apply #encode(String, String) to the values in the given URI variables and return a new Map containing the encoded values.

open static fun encodeUriVariables(vararg uriVariables: Any): Array<Any>

Apply #encode(String, String) to the values in the given URI variables and return a new array containing the encoded values.

encodeUserInfo

open static fun encodeUserInfo(userInfo: String, encoding: String): String
open static fun encodeUserInfo(userInfo: String, charset: Charset): String

Encode the given URI user info with the given encoding.

extractFileExtension

open static fun extractFileExtension(path: String): String

Extract the file extension from the given URI path.