Package org.eclipse.jetty.util
Class URIUtil
- java.lang.Object
-
- org.eclipse.jetty.util.URIUtil
-
- All Implemented Interfaces:
Cloneable
public class URIUtil extends Object implements Cloneable
URI Utility methods.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.
- See Also:
UrlEncoded
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringaddEncodedPaths(String p1, String p2)Add two encoded URI path segments.static URIaddPath(URI uri, String path)static StringaddPaths(String p1, String p2)Add two Decoded URI path segments.static voidappendSchemeHostPort(StringBuffer url, String scheme, String server, int port)Append scheme, host and port URI prefix, handling IPv6 address encoding and default portsstatic voidappendSchemeHostPort(StringBuilder url, String scheme, String server, int port)Append scheme, host and port URI prefix, handling IPv6 address encoding and default portsstatic StringcanonicalEncodedPath(String path)Convert a path to a cananonical form.static StringcanonicalPath(String path)Convert a decoded path to a canonical form.static StringcompactPath(String path)Convert a path to a compact form.static StringdecodePath(String path)static StringdecodePath(String path, int offset, int length)static StringencodePath(String path)Encode a URI path.static StringBuilderencodePath(StringBuilder buf, String path)Encode a URI path.static StringBuilderencodeString(StringBuilder buf, String path, String encode)Encode a URI path.static booleanequalsIgnoreEncodings(String uriA, String uriB)static booleanequalsIgnoreEncodings(URI uriA, URI uriB)static StringgetJarSource(String uri)static URIgetJarSource(URI uri)static booleanhasScheme(String uri)static StringnewURI(String scheme, String server, int port, String path, String query)Create a new URI from the arguments, handling IPv6 host encoding and default portsstatic StringBuildernewURIBuilder(String scheme, String server, int port)Create a new URI StringBuilder from the arguments, handling IPv6 host encoding and default portsstatic StringparentPath(String p)Return the parent Path.
-
-
-
Field Detail
-
SLASH
public static final String SLASH
- See Also:
- Constant Field Values
-
HTTP
public static final String HTTP
- See Also:
- Constant Field Values
-
HTTPS
public static final String HTTPS
- See Also:
- Constant Field Values
-
__CHARSET
public static final Charset __CHARSET
-
-
Method Detail
-
encodePath
public static String encodePath(String path)
Encode a URI path. This is the same encoding offered by URLEncoder, except that the '/' character is not encoded.- Parameters:
path- The path the encode- Returns:
- The encoded path
-
encodePath
public static StringBuilder encodePath(StringBuilder buf, String path)
Encode a URI path.- Parameters:
path- The path the encodebuf- StringBuilder to encode path into (or null)- Returns:
- The StringBuilder or null if no substitutions required.
-
encodeString
public static StringBuilder encodeString(StringBuilder buf, String path, String encode)
Encode a URI path.- Parameters:
path- The path the encodebuf- StringBuilder to encode path into (or null)encode- String of characters to encode. % is always encoded.- Returns:
- The StringBuilder or null if no substitutions required.
-
addEncodedPaths
public static String addEncodedPaths(String p1, String p2)
Add two encoded URI path segments. Handles null and empty paths, path and query params (eg ?a=b or ;JSESSIONID=xxx) and avoids duplicate '/'- Parameters:
p1- URI path segment (should be encoded)p2- URI path segment (should be encoded)- Returns:
- Legally combined path segments.
-
addPaths
public static String addPaths(String p1, String p2)
Add two Decoded URI path segments. Handles null and empty paths. Path and query params (eg ?a=b or ;JSESSIONID=xxx) are not handled- Parameters:
p1- URI path segment (should be decoded)p2- URI path segment (should be decoded)- Returns:
- Legally combined path segments.
-
parentPath
public static String parentPath(String p)
Return the parent Path. Treat a URI like a directory path and return the parent directory.- Parameters:
p- the path to return a parent reference to- Returns:
- the parent path of the URI
-
canonicalPath
public static String canonicalPath(String path)
Convert a decoded path to a canonical form.All instances of "." and ".." are factored out.
Null is returned if the path tries to .. above its root.
- Parameters:
path- the path to convert, decoded, with path separators '/' and no queries.- Returns:
- the canonical path, or null if path traversal above root.
-
canonicalEncodedPath
public static String canonicalEncodedPath(String path)
Convert a path to a cananonical form.All instances of "." and ".." are factored out.
Null is returned if the path tries to .. above its root.
- Parameters:
path- the path to convert (expects URI/URL form, encoded, and with path separators '/')- Returns:
- the canonical path, or null if path traversal above root.
-
compactPath
public static String compactPath(String path)
Convert a path to a compact form. All instances of "//" and "///" etc. are factored out to single "/"- Parameters:
path- the path to compact- Returns:
- the compacted path
-
hasScheme
public static boolean hasScheme(String uri)
- Parameters:
uri- URI- Returns:
- True if the uri has a scheme
-
newURI
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- Parameters:
scheme- the URI schemeserver- the URI serverport- the URI portpath- the URI pathquery- the URI query- Returns:
- A String URI
-
newURIBuilder
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- Parameters:
scheme- the URI schemeserver- the URI serverport- the URI port- Returns:
- a StringBuilder containing URI prefix
-
appendSchemeHostPort
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- Parameters:
url- StringBuilder to append toscheme- the URI schemeserver- the URI serverport- the URI port
-
appendSchemeHostPort
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- Parameters:
url- StringBuffer to append toscheme- the URI schemeserver- the URI serverport- the URI port
-
addPath
public static URI addPath(URI uri, String path)
- Parameters:
uri- A URI to add the path topath- A decoded path element- Returns:
- URI with path added.
-
-