Package alluxio.util
Class URIUtils
- java.lang.Object
-
- alluxio.util.URIUtils
-
@ThreadSafe public final class URIUtils extends java.lang.Object
Utility methods for working with URIs.
-
-
Field Summary
Fields Modifier and Type Field Description static char
QUERY_KEY_VALUE_SEPARATOR
static char
QUERY_SEPARATOR
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.net.URI
appendPath(java.net.URI base, java.lang.String path)
Appends the given path to the given base URI.static java.net.URI
appendPathOrDie(java.net.URI base, java.lang.String path)
Appends the given path to the given base URI.static int
compare(java.lang.String s1, java.lang.String s2)
static boolean
equals(java.lang.String s1, java.lang.String s2)
Checks if two (nullable) strings are equal.static java.lang.String
generateQueryString(java.util.Map<java.lang.String,java.lang.String> queryMap)
Generates a query string from aMap
of key/value pairs.static int
hash(int hash, java.lang.String s)
Hashes a string for a URI hash.static int
hashIgnoreCase(int hash, java.lang.String s)
Hashes a string for a URI hash, while ignoring the case.static boolean
isLocalFilesystem(java.lang.String uri)
static boolean
needsNormalization(java.lang.String path)
Returns true if the path requires normalization.static java.util.Map<java.lang.String,java.lang.String>
parseQueryString(java.lang.String query)
Parses the given query string, and returns a map of the query parameters.static int
toLower(char c)
-
-
-
Field Detail
-
QUERY_SEPARATOR
public static final char QUERY_SEPARATOR
- See Also:
- Constant Field Values
-
QUERY_KEY_VALUE_SEPARATOR
public static final char QUERY_KEY_VALUE_SEPARATOR
- See Also:
- Constant Field Values
-
-
Method Detail
-
appendPath
public static java.net.URI appendPath(java.net.URI base, java.lang.String path) throws java.net.URISyntaxException
Appends the given path to the given base URI.- Parameters:
base
- the base URIpath
- the path to append- Returns:
- the URI resulting from appending the base and the path
- Throws:
java.net.URISyntaxException
- if URI syntax error is encountered
-
appendPathOrDie
public static java.net.URI appendPathOrDie(java.net.URI base, java.lang.String path)
Appends the given path to the given base URI. It throws anRuntimeException
if the inputs are malformed.- Parameters:
base
- the base URIpath
- the path to append- Returns:
- the URI resulting from appending the base and the path
-
generateQueryString
@Nullable public static java.lang.String generateQueryString(java.util.Map<java.lang.String,java.lang.String> queryMap)
Generates a query string from aMap
of key/value pairs.- Parameters:
queryMap
- the map of query key/value pairs- Returns:
- the generated query string, null if the input map is null or empty
-
parseQueryString
public static java.util.Map<java.lang.String,java.lang.String> parseQueryString(java.lang.String query)
Parses the given query string, and returns a map of the query parameters.- Parameters:
query
- the query string to parse- Returns:
- the map of query keys and values
-
isLocalFilesystem
public static boolean isLocalFilesystem(java.lang.String uri)
- Parameters:
uri
- a uri to check- Returns:
- whether the uri represents a local filesystem UFS path
-
compare
public static int compare(java.lang.String s1, java.lang.String s2)
- Parameters:
s1
- first string (can be null)s2
- second string (can be null)- Returns:
- negative integer, zero, or positive integer, if the first string is less than, equal to, or greater than the second string
-
equals
public static boolean equals(java.lang.String s1, java.lang.String s2)
Checks if two (nullable) strings are equal. Handles `%` codes in URIs.- Parameters:
s1
- the first string to compare (can be null)s2
- the second string to compare (can be null)- Returns:
- true if the strings are equal
-
toLower
public static int toLower(char c)
- Parameters:
c
- the character to convert- Returns:
- the lowercase counterpart to the input character
-
needsNormalization
public static boolean needsNormalization(java.lang.String path)
Returns true if the path requires normalization. A path needs normalization if it has segments of: ".", "..", or consecutive "/".- Parameters:
path
- path to check- Returns:
- true if the path requires normalization
-
hash
public static int hash(int hash, java.lang.String s)
Hashes a string for a URI hash. Handles octets.- Parameters:
hash
- the input hashs
- the string to hash and combine with the input hash- Returns:
- the resulting hash
-
hashIgnoreCase
public static int hashIgnoreCase(int hash, java.lang.String s)
Hashes a string for a URI hash, while ignoring the case.- Parameters:
hash
- the input hashs
- the string to hash and combine with the input hash- Returns:
- the resulting hash
-
-