This class assists with the decoding and encoding or HTTP URI's. It differs from the java.net.URL class as it does not provide communications ability, but it does assist with query string formatting.
UrlEncoded
| Modifier and Type | Field and Description |
|---|---|
| private static final boolean[] | |
| private static final Logger | |
| private static final String | |
| private static final boolean[] | |
| private static final String | |
| private static final String | |
| private static final boolean[] | URI_SUPPORTED_CHARACTERS
The characters that are supported by the URI class and that can be decoded by |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static String | Returns: Legally combined path segments.URI path segment (should be encoded) p1, String URI path segment (should be encoded) p2)Add two encoded URI path segments. |
| public static URI | |
| public static String | Returns: The path with any non-blank query added after a '?' or '&' as appropriate.The path which may already contain a query path, String The query string to add (if blank, no query is added) query)Add a path and a query string |
| public static String | |
| public static String | Returns: the combination of the two query strings.the first query string. query1, String the second query string. query2)Combine two query strings into one. |
| private static void | |
| public static void | appendSchemeHostPort(StringBuilder
StringBuilder to append to url, String the URI scheme scheme, String the URI server server, int the URI port port)Append scheme, host and port URI prefix, handling IPv6 address encoding and default ports |
| public static void | appendSchemeHostPort(StringBuffer
StringBuffer to append to url, String the URI scheme scheme, String the URI server server, int the URI port port)Append scheme, host and port URI prefix, handling IPv6 address encoding and default ports |
| public static String | Returns: the canonical path or null if it is non-normalAn encoded URI path encodedPath)Canonicalize a URI path to a form that is unambiguous and safe to use with the JVM |
| public static <X extends Throwable> String | Returns: the canonical path or null if it is non-normalAn encoded URI path encodedPath, Supplier<X> A supplier of exceptions if bad UTF8 is encountered, or null for no exception thrown. onBadUtf8)Canonicalize a URI path to a form that is unambiguous and safe to use with the JVM |
| public static String | Returns: the compacted paththe path to compact path)Convert a path to a compact form. |
| public static URI | Returns: the new URI with thefile:/ substring corrected, or the original URI.the URI to (possibly) correct uri)
Corrects any bad
This correction is limited to only the |
| public static String | decodePath(String
The URI path to decode path)Decodes a percent-encoded URI path (assuming UTF-8 characters) and strips path parameters. |
| public static String | decodePath(String
A String holding the URI path to decode path, int The start of the URI within the path string offset, int The length of the URI within the path string length)Decodes a percent-encoded URI path (assuming UTF-8 characters) and strips path parameters. |
| public static String | Returns: output with specified characters decoded.input raw string str, String the list of raw characters that need to be decoded (if encountered), leaving all the other encoded sequences alone. charsToDecode)Decode a raw String and convert any specific URI encoded sequences into characters. |
| private static boolean | |
| private static boolean | |
| private static void | |
| public static String | |
| private static String | |
| public static String | Returns: the returned path with only safe encodingsthe path to encode path)Encode characters in a path to ensure they only contain safe encodings suitable for both
|
| private static String | |
| public static String | Returns: output with specified characters encoded.input raw string str, String the list of raw characters that need to be encoded (if encountered) charsToEncode)Encode a raw String and convert any specific characters to their URI encoded equivalent. |
| public static StringBuilder | Returns: The StringBuilder or null if no substitutions required.StringBuilder to encode path into (or null) buf, String The path to encode path, String String of characters to encode. ' encode)%' is always encoded.Encode a URI path. |
| public static String | Returns: the last segment.the URI to look in uri)Given a URI, attempt to get the last segment. |
| public static boolean | |
| public static boolean | Returns: True if the normal form of the path is within the root of the path.The path to check path)Check if a path would be normalized within itself. |
| public static boolean | Returns: True if the path does not contain any invalid path charactersThe path to check for validity path)
|
| private static boolean | |
| private static boolean | Returns: true if the decoded value is safe to pass as input toURI, otherwise false;the codepoint to check code, Utf8StringBuilder The builder to encode into builder)If the codepoint is safe, do nothing, else add the UTF-8 URI encoded form of the codepoint. |
| public static boolean | Returns: true if the token passes as a valid Host Registered Namethe to test token)True if token is a RFC3986 |
| private static boolean | Returns: true if the codepoint must be encoded, false otherwisethe codepoint to check codepoint)Check codepoint for rules on URI encoding. |
| public static String | |
| public static StringBuilder | Returns: a StringBuilder containing URI prefixthe URI scheme scheme, String the URI server server, int the URI port port)Create a new URI StringBuilder from the arguments, handling IPv6 host encoding and default ports |
| public static String | Returns: the normalized path, or null if path traversal above root.the decoded URI path to convert. Any special characters (e.g. path)?, #) are assumed to be part of
the path segments.Normalize a URI path by factoring out all segments of |
| public static String | Returns: the normalized path, or null if path traversal above root.the encoded URI from the path onwards, which may contain query strings and/or fragments pathQuery)
Normalize a URI path and query by factoring out all segments of ' |
| public static String | Returns: the parent path of the URIthe path to return a parent reference to p)Return the parent Path. |
| public static List | |
| public static Stream | Returns: the Stream ofURIthe classloader to load from urlClassLoader)Stream the |
| public static URI | Returns: thejar:${uri_to_java_archive}!/${internal-reference} URI or the unchanged URI if not a Java Archive.the URI to mutate to a uri)jar:file:... URI.Take an arbitrary URI and provide a URI that is suitable for mounting the URI as a Java FileSystem. |
| public static URI | |
| public static URI | Returns: the container String if ajar scheme, or just the URI untouched.the input URI uri)Unwrap a URI to expose its container path reference. |
| public static URI | Returns: thejar:file: based URI with a deep referencethe input URI (supporting uri, String jar or file based schemesthe suffix to set. Must start with encodedSuffix)!/. Must be properly URI encoded.Take a URI and add a deep reference |
| ENCODE_PATH_NEEDS_ENCODING | back to summary |
|---|---|
| private static final boolean[] ENCODE_PATH_NEEDS_ENCODING | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| REGNAME | back to summary |
|---|---|
| private static final String REGNAME | |
| REGNAME_ALLOWED | back to summary |
|---|---|
| private static final boolean[] REGNAME_ALLOWED | |
| SUBDELIMS | back to summary |
|---|---|
| private static final String SUBDELIMS | |
| UNRESERVED | back to summary |
|---|---|
| private static final String UNRESERVED | |
| URI_SUPPORTED_CHARACTERS | back to summary |
|---|---|
| private static final boolean[] URI_SUPPORTED_CHARACTERS The characters that are supported by the URI class and that can be decoded by | |
| URIUtil | back to summary |
|---|---|
| private URIUtil() | |
| addEncodedPaths | back to summary |
|---|---|
| public static String addEncodedPaths(String p1, String p2) Add two encoded URI path segments.
Handles null and empty paths, path and query params
(e.g. | |
| addPath | back to summary |
|---|---|
| public static URI addPath(URI uri, String path) Add a sub path to an existing URI.
| |
| addPathQuery | back to summary |
|---|---|
| public static String addPathQuery(String path, String query) Add a path and a query string | |
| addPaths | back to summary |
|---|---|
| public static String addPaths(String p1, String p2) Add two Decoded URI path segments.
Handles null and empty paths.
Path and query params (e.g. | |
| addQueries | back to summary |
|---|---|
| public static String addQueries(String query1, String query2) Combine two query strings into one. Each query string should not contain the beginning ' | |
| appendHexValue | back to summary |
|---|---|
| private static void appendHexValue(Utf8StringBuilder builder, byte value) | |
| appendSchemeHostPort | back to summary |
|---|---|
| public static void appendSchemeHostPort(StringBuilder url, String scheme, String server, int port) Append scheme, host and port URI prefix, handling IPv6 address encoding and default ports
| |
| appendSchemeHostPort | back to summary |
|---|---|
| public static void appendSchemeHostPort(StringBuffer url, String scheme, String server, int port) Append scheme, host and port URI prefix, handling IPv6 address encoding and default ports
| |
| canonicalPath | back to summary |
|---|---|
| public static String canonicalPath(String encodedPath) Canonicalize a URI path to a form that is unambiguous and safe to use with the JVM
Decode only the safe characters in a URI path and strip parameters of UTF-8 path.
Safe characters are ones that are not special delimiters and that can be passed to the JVM
For example the path
| |
| canonicalPath | back to summary |
|---|---|
| public static <X extends Throwable> String canonicalPath(String encodedPath, Supplier<X> onBadUtf8) throws Supplier-:X Canonicalize a URI path to a form that is unambiguous and safe to use with the JVM
Decode only the safe characters in a URI path and strip parameters of UTF-8 path.
Safe characters are ones that are not special delimiters and that can be passed to the JVM
For example the path
| |
| compactPath | back to summary |
|---|---|
| public static String compactPath(String path) Convert a path to a compact form.
All instances of | |
| correctFileURI | back to summary |
|---|---|
| public static URI correctFileURI(URI uri)
Corrects any bad
This correction is limited to only the Note that Windows UNC based URIs are left alone, along with non-absolute URIs. | |
| decodePath | back to summary |
|---|---|
| public static String decodePath(String path) Decodes a percent-encoded URI path (assuming UTF-8 characters) and strips path parameters.
| |
| decodePath | back to summary |
|---|---|
| public static String decodePath(String path, int offset, int length) Decodes a percent-encoded URI path (assuming UTF-8 characters) and strips path parameters.
| |
| decodeSpecific | back to summary |
|---|---|
| public static String decodeSpecific(String str, String charsToDecode) Decode a raw String and convert any specific URI encoded sequences into characters.
| |
| doDots | back to summary |
|---|---|
| private static boolean doDots(StringBuilder canonical, int dots) | |
| doDotsSlash | back to summary |
|---|---|
| private static boolean doDotsSlash(StringBuilder canonical, int dots) | |
| encodeCodepoint | back to summary |
|---|---|
| private static void encodeCodepoint(int code, Utf8StringBuilder builder) | |
| encodePath | back to summary |
|---|---|
| public static String encodePath(String path) Encode a URI path.
This is the same encoding offered by URLEncoder, except that
the ' | |
| encodePathBytes | back to summary |
|---|---|
| private static String encodePathBytes(String path) | |
| encodePathSafeEncoding | back to summary |
|---|---|
| public static String encodePathSafeEncoding(String path) Encode characters in a path to ensure they only contain safe encodings suitable for both
| |
| encodePathString | back to summary |
|---|---|
| private static String encodePathString(String path) | |
| encodeSpecific | back to summary |
|---|---|
| public static String encodeSpecific(String str, String charsToEncode) Encode a raw String and convert any specific characters to their URI encoded equivalent.
| |
| encodeString | back to summary |
|---|---|
| public static StringBuilder encodeString(StringBuilder buf, String path, String encode) Encode a URI path.
| |
| getUriLastPathSegment | back to summary |
|---|---|
| public static String getUriLastPathSegment(URI uri) Given a URI, attempt to get the last segment.
If this is a | |
| hasScheme | back to summary |
|---|---|
public static boolean hasScheme(String uri)
| |
| isNotNormalWithinSelf | back to summary |
|---|---|
| public static boolean isNotNormalWithinSelf(String path) Check if a path would be normalized within itself. For example,
| |
| isPathValid | back to summary |
|---|---|
public static boolean isPathValid(String path)
| |
| isSafe | back to summary |
|---|---|
| private static boolean isSafe(int code) Test if codepoint is safe and unambiguous to pass as input to
| |
| isSafeElseEncode | back to summary |
|---|---|
| private static boolean isSafeElseEncode(int code, Utf8StringBuilder builder) If the codepoint is safe, do nothing, else add the UTF-8 URI encoded form of the codepoint.
| |
| isValidHostRegisteredName | back to summary |
|---|---|
| public static boolean isValidHostRegisteredName(String token) True if token is a RFC3986
| |
| mustBeEncoded | back to summary |
|---|---|
| private static boolean mustBeEncoded(int codepoint) Check codepoint for rules on URI encoding.
This does not allow 8-bit characters, unlike
| |
| newURI | back to summary |
|---|---|
| public static String newURI(String scheme, String server, int port, String path, String query) Create a new URI from the arguments, handling IPv6 host encoding and default ports | |
| newURIBuilder | back to summary |
|---|---|
| public static StringBuilder newURIBuilder(String scheme, String server, int port) Create a new URI StringBuilder from the arguments, handling IPv6 host encoding and default ports
| |
| normalizePath | back to summary |
|---|---|
| public static String normalizePath(String path) Normalize a URI path by factoring out all segments of
| |
| normalizePathQuery | back to summary |
|---|---|
| public static String normalizePathQuery(String pathQuery)
Normalize a URI path and query by factoring out all segments of '
| |
| parentPath | back to summary |
|---|---|
| public static String parentPath(String p) Return the parent Path. Treat a URI like a directory path and return the parent directory. | |
| split | back to summary |
|---|---|
| public static List Split a string of references, that may be split with ' Each part of the input string could be path references (unix or windows style), or string URI references.
If the result of processing the input segment is a java archive, then its resulting URI will be a mountable URI as
| |
| streamOf | back to summary |
|---|---|
| public static Stream Stream the
| |
| toJarFileUri | back to summary |
|---|---|
| public static URI toJarFileUri(URI uri) Take an arbitrary URI and provide a URI that is suitable for mounting the URI as a Java FileSystem.
The resulting URI will point to the
| |
| toURI | back to summary |
|---|---|
| public static URI toURI(String resource) Convert a String into a URI suitable for use as a Resource. | |
| unwrapContainer | back to summary |
|---|---|
| public static URI unwrapContainer(URI uri) Unwrap a URI to expose its container path reference.
Take out the container archive name URI from a | |
| uriJarPrefix | back to summary |
|---|---|
| public static URI uriJarPrefix(URI uri, String encodedSuffix) Take a URI and add a deep reference | |