Package alluxio
Class AlluxioURI
- java.lang.Object
-
- alluxio.AlluxioURI
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<AlluxioURI>
@PublicApi @ThreadSafe public final class AlluxioURI extends java.lang.Object implements java.lang.Comparable<AlluxioURI>, java.io.Serializable
This class represents a URI in the Alluxio system. ThisAlluxioURI
can represent resources in the Alluxio namespace, as well as UFS namespaces.AlluxioURI
supports more than just strictURI
. Some examples: * Windows paths * C:\ * D:\path\to\file * E:\path\to\skip\..\file * URI with multiple scheme components * scheme://host:123/path * scheme:part2//host:123/path * scheme:part2://host:123/path * scheme:part2:part3//host:123/path * scheme:part2:part3://host:123/path Does not support fragment in the URI.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CUR_DIR
static AlluxioURI
EMPTY_URI
static java.lang.String
SEPARATOR
static java.lang.String
WILDCARD
-
Constructor Summary
Constructors Constructor Description AlluxioURI(AlluxioURI parent, AlluxioURI child)
Resolves a childAlluxioURI
against a parentAlluxioURI
.AlluxioURI(AlluxioURI baseURI, java.lang.String newPath, boolean checkNormalization)
Constructs anAlluxioURI
from a base URI and a new path component.AlluxioURI(java.lang.String pathStr)
Constructs anAlluxioURI
from a String.AlluxioURI(java.lang.String scheme, Authority authority, java.lang.String path)
Constructs anAlluxioURI
from components.AlluxioURI(java.lang.String scheme, Authority authority, java.lang.String path, java.util.Map<java.lang.String,java.lang.String> queryMap)
Constructs anAlluxioURI
from components.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(AlluxioURI other)
boolean
containsWildcard()
Whether or not theAlluxioURI
contains wildcard(s).boolean
equals(java.lang.Object o)
Authority
getAuthority()
int
getDepth()
Returns the number of elements of the path component of theAlluxioURI
.java.lang.String
getLeadingPath(int n)
Gets the first n components of theAlluxioURI
path.java.lang.String
getName()
Gets the final component of theAlluxioURI
.AlluxioURI
getParent()
Get the parent of thisAlluxioURI
or null if at root.java.lang.String
getPath()
Gets the path component of theAlluxioURI
.java.util.Map<java.lang.String,java.lang.String>
getQueryMap()
Gets the map of query parameters.java.lang.String
getRootPath()
java.lang.String
getScheme()
Gets the scheme of theAlluxioURI
.boolean
hasAuthority()
Tells if theAlluxioURI
has authority or not.java.lang.String
hash()
Computes the hash of this URI, with SHA-256, or MD5, or simple hashCode().int
hashCode()
boolean
hasScheme()
Tells if thisAlluxioURI
has scheme or not.static boolean
hasWindowsDrive(java.lang.String path, boolean slashed)
Checks if the path is a windows path.boolean
isAbsolute()
Tells whether or not theAlluxioURI
is absolute.boolean
isAncestorOf(AlluxioURI alluxioURI)
Returns true if the current AlluxioURI is an ancestor of another AlluxioURI.boolean
isPathAbsolute()
Tells whether or not the path component of theAlluxioURI
is absolute.boolean
isRoot()
Tells whether or not theAlluxioURI
is root.AlluxioURI
join(AlluxioURI suffix)
Append additional path elements to the end of anAlluxioURI
.AlluxioURI
join(java.lang.String suffix)
Append additional path elements to the end of anAlluxioURI
.AlluxioURI
joinUnsafe(java.lang.String suffix)
Append additional path elements to the end of anAlluxioURI
.static java.lang.String
normalizePath(java.lang.String path)
Normalize the path component of theAlluxioURI
, by replacing all "//" and "\\" with "/", and trimming trailing slash from non-root path (ignoring windows drive).java.lang.String
toString()
Illegal characters unescaped in the string, for glob processing, etc.
-
-
-
Field Detail
-
SEPARATOR
public static final java.lang.String SEPARATOR
- See Also:
- Constant Field Values
-
CUR_DIR
public static final java.lang.String CUR_DIR
- See Also:
- Constant Field Values
-
WILDCARD
public static final java.lang.String WILDCARD
- See Also:
- Constant Field Values
-
EMPTY_URI
public static final AlluxioURI EMPTY_URI
-
-
Constructor Detail
-
AlluxioURI
public AlluxioURI(java.lang.String pathStr)
Constructs anAlluxioURI
from a String. Path strings are URIs, but with unescaped elements and some additional normalization.- Parameters:
pathStr
- path to construct theAlluxioURI
from
-
AlluxioURI
public AlluxioURI(java.lang.String scheme, Authority authority, java.lang.String path)
Constructs anAlluxioURI
from components.- Parameters:
scheme
- the scheme of the path. e.g. alluxio, hdfs, s3, file, null, etcauthority
- the authority of the pathpath
- the path component of the URI. e.g. /abc/c.txt, /a b/c/c.txt
-
AlluxioURI
public AlluxioURI(java.lang.String scheme, Authority authority, java.lang.String path, java.util.Map<java.lang.String,java.lang.String> queryMap)
Constructs anAlluxioURI
from components.- Parameters:
scheme
- the scheme of the path. e.g. alluxio, hdfs, s3, file, null, etcauthority
- the authority of the pathpath
- the path component of the URI. e.g. /abc/c.txt, /a b/c/c.txtqueryMap
- the (nullable) map of key/value pairs for the query component of the URI
-
AlluxioURI
public AlluxioURI(AlluxioURI parent, AlluxioURI child)
Resolves a childAlluxioURI
against a parentAlluxioURI
.- Parameters:
parent
- the parentchild
- the child
-
AlluxioURI
public AlluxioURI(AlluxioURI baseURI, java.lang.String newPath, boolean checkNormalization)
Constructs anAlluxioURI
from a base URI and a new path component.- Parameters:
baseURI
- the base urinewPath
- the new path componentcheckNormalization
- if true, will check if the path requires normalization
-
-
Method Detail
-
compareTo
public int compareTo(AlluxioURI other)
- Specified by:
compareTo
in interfacejava.lang.Comparable<AlluxioURI>
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
getAuthority
public Authority getAuthority()
- Returns:
- the authority of the
AlluxioURI
-
getDepth
public int getDepth()
Returns the number of elements of the path component of theAlluxioURI
./ = 0 . = 0 /a = 1 /a/b/c.txt = 3 /a/b/ = 3 a/b = 2 a\b = 2 alluxio://localhost:19998/ = 0 alluxio://localhost:19998/a = 1 alluxio://localhost:19998/a/b.txt = 2 C:\a = 1 C: = 0
- Returns:
- the depth
-
getLeadingPath
@Nullable public java.lang.String getLeadingPath(int n)
Gets the first n components of theAlluxioURI
path. There is no trailing separator as the path will be normalized by normalizePath()./a/b/c, 0 = / /a/b/c, 1 = /a /a/b/c, 2 = /a/b /a/b/c, 3 = /a/b/c /a/b/c, 4 = null
- Parameters:
n
- identifies the number of path components to get- Returns:
- the first n path components, null if the path has less than n components
-
containsWildcard
public boolean containsWildcard()
Whether or not theAlluxioURI
contains wildcard(s).- Returns:
boolean
that indicates whether theAlluxioURI
contains wildcard(s)
-
getName
public java.lang.String getName()
Gets the final component of theAlluxioURI
.- Returns:
- the final component of the
AlluxioURI
-
getParent
@Nullable public AlluxioURI getParent()
Get the parent of thisAlluxioURI
or null if at root.- Returns:
- the parent of this
AlluxioURI
or null if at root
-
getPath
public java.lang.String getPath()
Gets the path component of theAlluxioURI
.- Returns:
- the path
-
getQueryMap
public java.util.Map<java.lang.String,java.lang.String> getQueryMap()
Gets the map of query parameters.- Returns:
- the map of query parameters
-
getScheme
@Nullable public java.lang.String getScheme()
Gets the scheme of theAlluxioURI
.- Returns:
- the scheme, null if there is no scheme
-
getRootPath
public java.lang.String getRootPath()
- Returns:
- the normalized path stripped of the folder path component
-
hasAuthority
public boolean hasAuthority()
Tells if theAlluxioURI
has authority or not.- Returns:
- true if it has, false otherwise
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
hasScheme
public boolean hasScheme()
Tells if thisAlluxioURI
has scheme or not.- Returns:
- true if it has, false otherwise
-
hasWindowsDrive
public static boolean hasWindowsDrive(java.lang.String path, boolean slashed)
Checks if the path is a windows path. This should be platform independent.- Parameters:
path
- the path to checkslashed
- if the path starts with a slash- Returns:
- true if it is a windows path, false otherwise
-
isAbsolute
public boolean isAbsolute()
Tells whether or not theAlluxioURI
is absolute.An
AlluxioURI
is absolute if, and only if, it has a scheme component.- Returns:
- true if, and only if, this
AlluxioURI
is absolute
-
isPathAbsolute
public boolean isPathAbsolute()
Tells whether or not the path component of theAlluxioURI
is absolute.A path is absolute if, and only if, it starts with root.
- Returns:
- true if, and only if, the
AlluxioURI
's path component is absolute
-
isRoot
public boolean isRoot()
Tells whether or not theAlluxioURI
is root.A URI is root if its path equals to "/"
- Returns:
- true if, and only if, this URI is root
-
join
public AlluxioURI join(java.lang.String suffix)
Append additional path elements to the end of anAlluxioURI
.- Parameters:
suffix
- the suffix to add- Returns:
- the new
AlluxioURI
-
join
public AlluxioURI join(AlluxioURI suffix)
Append additional path elements to the end of anAlluxioURI
.- Parameters:
suffix
- the suffix to add- Returns:
- the new
AlluxioURI
-
joinUnsafe
public AlluxioURI joinUnsafe(java.lang.String suffix)
Append additional path elements to the end of anAlluxioURI
. This does not check if the new path needs normalization, and is less CPU intensive thanjoin(String)
.- Parameters:
suffix
- the suffix to add- Returns:
- the new
AlluxioURI
-
normalizePath
public static java.lang.String normalizePath(java.lang.String path)
Normalize the path component of theAlluxioURI
, by replacing all "//" and "\\" with "/", and trimming trailing slash from non-root path (ignoring windows drive).- Parameters:
path
- the path to normalize- Returns:
- the normalized path
-
isAncestorOf
public boolean isAncestorOf(AlluxioURI alluxioURI) throws InvalidPathException
Returns true if the current AlluxioURI is an ancestor of another AlluxioURI. otherwise, return false.- Parameters:
alluxioURI
- potential children to check- Returns:
- true the current alluxioURI is an ancestor of the AlluxioURI
- Throws:
InvalidPathException
-
toString
public java.lang.String toString()
Illegal characters unescaped in the string, for glob processing, etc.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the String representation of the
AlluxioURI
-
hash
public java.lang.String hash()
Computes the hash of this URI, with SHA-256, or MD5, or simple hashCode().- Returns:
- HEX encoded hash string
-
-