public class URIUtil extends Object implements Cloneable
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 |
---|---|
static Charset |
__CHARSET |
static String |
HTTP |
static String |
HTTPS |
static String |
SLASH |
Modifier and Type | Method and Description |
---|---|
static String |
addEncodedPaths(String p1,
String p2)
Add two encoded URI path segments.
|
static URI |
addPath(URI uri,
String path) |
static String |
addPathQuery(String path,
String query)
Add a path and a query string
|
static String |
addPaths(String p1,
String p2)
Add two Decoded URI path segments.
|
static String |
addQueries(String query1,
String query2)
Combine two query strings into one.
|
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
|
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
|
static String |
canonicalEncodedPath(String path)
Convert a path to a cananonical form.
|
static String |
canonicalPath(String path)
Convert a decoded path to a canonical form.
|
static String |
compactPath(String path)
Convert a path to a compact form.
|
static String |
decodePath(String path) |
static String |
decodePath(String path,
int offset,
int length) |
static String |
decodeSpecific(String str,
String charsToDecode)
Decode a raw String and convert any specific URI encoded sequences into characters.
|
static String |
encodePath(String path)
Encode a URI path.
|
static StringBuilder |
encodePath(StringBuilder buf,
String path)
Encode a URI path.
|
static String |
encodeSpaces(String str)
Encode a raw URI String and convert any raw spaces to
their "%20" equivalent.
|
static String |
encodeSpecific(String str,
String charsToEncode)
Encode a raw String and convert any specific characters to their URI encoded equivalent.
|
static StringBuilder |
encodeString(StringBuilder buf,
String path,
String encode)
Encode a URI path.
|
static boolean |
equalsIgnoreEncodings(String uriA,
String uriB) |
static boolean |
equalsIgnoreEncodings(URI uriA,
URI uriB) |
static String |
getJarSource(String uri) |
static URI |
getJarSource(URI uri) |
static String |
getUriLastPathSegment(URI uri)
Given a URI, attempt to get the last segment.
|
static boolean |
hasScheme(String uri) |
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
|
static StringBuilder |
newURIBuilder(String scheme,
String server,
int port)
Create a new URI StringBuilder from the arguments, handling IPv6 host encoding and default ports
|
static String |
parentPath(String p)
Return the parent Path.
|
public static final String SLASH
public static final String HTTP
public static final String HTTPS
public static final Charset __CHARSET
public static String encodePath(String path)
path
- The path the encodepublic static StringBuilder encodePath(StringBuilder buf, String path)
path
- The path the encodebuf
- StringBuilder to encode path into (or null)public static String encodeSpaces(String str)
str
- input raw stringpublic static String encodeSpecific(String str, String charsToEncode)
str
- input raw stringcharsToEncode
- the list of raw characters that need to be encoded (if encountered)public static String decodeSpecific(String str, String charsToDecode)
str
- input raw stringcharsToDecode
- the list of raw characters that need to be decoded (if encountered), leaving all other encoded sequences alone.public static StringBuilder encodeString(StringBuilder buf, String path, String encode)
path
- The path the encodebuf
- StringBuilder to encode path into (or null)encode
- String of characters to encode. % is always encoded.public static String addEncodedPaths(String p1, String p2)
p1
- URI path segment (should be encoded)p2
- URI path segment (should be encoded)public static String addPaths(String p1, String p2)
p1
- URI path segment (should be decoded)p2
- URI path segment (should be decoded)public static String addPathQuery(String path, String query)
path
- The path which may already contain contain a queryquery
- The query string or null if no query to be addedpublic static String getUriLastPathSegment(URI uri)
If this is a jar:file://
style URI, then
the JAR filename is returned (not the deep !/path
location)
uri
- the URI to look inpublic static String parentPath(String p)
p
- the path to return a parent reference topublic static String canonicalPath(String path)
All instances of "." and ".." are factored out.
Null is returned if the path tries to .. above its root.
path
- the path to convert, decoded, with path separators '/' and no queries.public static String canonicalEncodedPath(String path)
All instances of "." and ".." are factored out.
Null is returned if the path tries to .. above its root.
path
- the path to convert (expects URI/URL form, encoded, and with path separators '/')public static String compactPath(String path)
path
- the path to compactpublic static boolean hasScheme(String uri)
uri
- URIpublic static String newURI(String scheme, String server, int port, String path, String query)
scheme
- the URI schemeserver
- the URI serverport
- the URI portpath
- the URI pathquery
- the URI querypublic static StringBuilder newURIBuilder(String scheme, String server, int port)
scheme
- the URI schemeserver
- the URI serverport
- the URI portpublic static void appendSchemeHostPort(StringBuilder url, String scheme, String server, int port)
url
- StringBuilder to append toscheme
- the URI schemeserver
- the URI serverport
- the URI portpublic static void appendSchemeHostPort(StringBuffer url, String scheme, String server, int port)
url
- StringBuffer to append toscheme
- the URI schemeserver
- the URI serverport
- the URI portpublic static URI addPath(URI uri, String path)
uri
- A URI to add the path topath
- A decoded path elementpublic static String addQueries(String query1, String query2)
query1
- the first query string.query2
- the second query string.Copyright © 2010 - 2020 Adobe. All Rights Reserved