Package jodd.net
Class URLCoder
java.lang.Object
jodd.net.URLCoder
Encodes URLs correctly, significantly faster and more convenient.
Here is an example of full URL: https://jodd:ddoj@www.jodd.org:8080/file;p=1?q=2#third. It consist of:
- scheme (https)
- user (jodd)
- password (ddoj)
- host (www.jodd.org)
- port (8080)
- path (file)
- path parameter (p=1)
- query parameter (q=2)
- fragment (third)
builder.
It provides fluent interface for defining query parameters.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class(package private) static enumEnumeration to identify the parts of a URI. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final Stringprivate static final Patternprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Patternprivate static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic URLCoder.BuilderCreates URL builder for user-friendly way of building URLs.static URLCoder.BuilderCreates URL builder with given path that can be optionally encoded.static Stringstatic StringEncodes string using default RFCP rules.private static byte[]encodeBytes(byte[] source, URLCoder.URIPart uriPart) Encodes byte array using allowed characters fromURLCoder.URIPart.static StringencodeFragment(String fragment) static StringencodeFragment(String fragment, Charset encoding) Encodes the given URI fragment with the given encoding.static StringencodeHost(String host) static StringencodeHost(String host, Charset encoding) Encodes the given URI host with the given encoding.static StringencodeHttpUrl(String httpUrl) static StringencodeHttpUrl(String httpUrl, Charset encoding) Encodes the given HTTP URI into an encoded String.static StringencodePath(String path) static StringencodePath(String path, Charset encoding) Encodes the given URI path with the given encoding.static StringencodePathSegment(String segment) static StringencodePathSegment(String segment, Charset encoding) Encodes the given URI path segment with the given encoding.static StringencodePort(String port) static StringencodePort(String port, Charset encoding) Encodes the given URI port with the given encoding.static StringencodeQuery(String query) static StringencodeQuery(String query, Charset encoding) Encodes the given URI query with the given encoding.static StringencodeQueryParam(String queryParam) static StringencodeQueryParam(String queryParam, Charset encoding) Encodes the given URI query parameter with the given encoding.static StringencodeScheme(String scheme) static StringencodeScheme(String scheme, Charset encoding) Encodes the given URI scheme with the given encoding.static Stringstatic StringEncodes the given source URI into an encoded String.private static StringencodeUriComponent(String source, Charset encoding, URLCoder.URIPart uriPart) Encodes single URI component.private static StringencodeUriComponents(String scheme, String authority, String userInfo, String host, String port, String path, String query, String fragment, Charset encoding) static StringencodeUserInfo(String userInfo) static StringencodeUserInfo(String userInfo, Charset encoding) Encodes the given URI user info with the given encoding.
-
Field Details
-
SCHEME_PATTERN
- See Also:
-
HTTP_PATTERN
- See Also:
-
USERINFO_PATTERN
- See Also:
-
HOST_PATTERN
- See Also:
-
PORT_PATTERN
- See Also:
-
PATH_PATTERN
- See Also:
-
QUERY_PATTERN
- See Also:
-
LAST_PATTERN
- See Also:
-
URI_PATTERN
-
HTTP_URL_PATTERN
-
-
Constructor Details
-
URLCoder
public URLCoder()
-
-
Method Details
-
encodeUriComponent
Encodes single URI component. -
encodeBytes
Encodes byte array using allowed characters fromURLCoder.URIPart. -
encode
Encodes string using default RFCP rules. -
encode
-
encodeScheme
Encodes the given URI scheme with the given encoding. -
encodeScheme
-
encodeUserInfo
Encodes the given URI user info with the given encoding. -
encodeUserInfo
-
encodeHost
Encodes the given URI host with the given encoding. -
encodeHost
-
encodePort
Encodes the given URI port with the given encoding. -
encodePort
-
encodePath
Encodes the given URI path with the given encoding. -
encodePath
-
encodePathSegment
Encodes the given URI path segment with the given encoding. -
encodePathSegment
-
encodeQuery
Encodes the given URI query with the given encoding. -
encodeQuery
-
encodeQueryParam
Encodes the given URI query parameter with the given encoding. -
encodeQueryParam
-
encodeFragment
Encodes the given URI fragment with the given encoding. -
encodeFragment
-
encodeUri
- See Also:
-
encodeUri
Encodes the given source URI into an encoded String. All various URI components are encoded according to their respective valid character sets.This method does not attempt to encode "=" and "&" characters in query parameter names and query parameter values because they cannot be parsed in a reliable way.
-
encodeHttpUrl
- See Also:
-
encodeHttpUrl
Encodes the given HTTP URI into an encoded String. All various URI components are encoded according to their respective valid character sets.This method does not support fragments (
#), as these are not supposed to be sent to the server, but retained by the client.This method does not attempt to encode "=" and "&" characters in query parameter names and query parameter values because they cannot be parsed in a reliable way.
-
encodeUriComponents
-
build
Creates URL builder for user-friendly way of building URLs. Provided path is parsed andencoded.- See Also:
-
build
Creates URL builder with given path that can be optionally encoded. Since most of the time path is valid and does not require to be encoded, use this method to gain some performance. When encoding flag is turned off, provided path is used without processing.The purpose of builder is to help with query parameters. All other URI parts should be set previously or after the URL is built.
-