Package alluxio

Class 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. This AlluxioURI can represent resources in the Alluxio namespace, as well as UFS namespaces. AlluxioURI supports more than just strict URI. 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
    • Constructor Detail

      • AlluxioURI

        public AlluxioURI​(java.lang.String pathStr)
        Constructs an AlluxioURI from a String. Path strings are URIs, but with unescaped elements and some additional normalization.
        Parameters:
        pathStr - path to construct the AlluxioURI from
      • AlluxioURI

        public AlluxioURI​(java.lang.String scheme,
                          Authority authority,
                          java.lang.String path)
        Constructs an AlluxioURI from components.
        Parameters:
        scheme - the scheme of the path. e.g. alluxio, hdfs, s3, file, null, etc
        authority - the authority of the path
        path - 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 an AlluxioURI from components.
        Parameters:
        scheme - the scheme of the path. e.g. alluxio, hdfs, s3, file, null, etc
        authority - the authority of the path
        path - the path component of the URI. e.g. /abc/c.txt, /a b/c/c.txt
        queryMap - the (nullable) map of key/value pairs for the query component of the URI
      • AlluxioURI

        public AlluxioURI​(AlluxioURI baseURI,
                          java.lang.String newPath,
                          boolean checkNormalization)
        Constructs an AlluxioURI from a base URI and a new path component.
        Parameters:
        baseURI - the base uri
        newPath - the new path component
        checkNormalization - if true, will check if the path requires normalization
    • Method Detail

      • compareTo

        public int compareTo​(AlluxioURI other)
        Specified by:
        compareTo in interface java.lang.Comparable<AlluxioURI>
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • getDepth

        public int getDepth()
        Returns the number of elements of the path component of the AlluxioURI.
         /                                  = 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 the AlluxioURI 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 the AlluxioURI contains wildcard(s).
        Returns:
        boolean that indicates whether the AlluxioURI contains wildcard(s)
      • getName

        public java.lang.String getName()
        Gets the final component of the AlluxioURI.
        Returns:
        the final component of the AlluxioURI
      • getParent

        @Nullable
        public AlluxioURI getParent()
        Get the parent of this AlluxioURI 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 the AlluxioURI.
        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 the AlluxioURI.
        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 the AlluxioURI has authority or not.
        Returns:
        true if it has, false otherwise
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • hasScheme

        public boolean hasScheme()
        Tells if this AlluxioURI 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 check
        slashed - 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 the AlluxioURI 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 the AlluxioURI 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 the AlluxioURI 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 an AlluxioURI.
        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 an AlluxioURI. This does not check if the new path needs normalization, and is less CPU intensive than join(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 the AlluxioURI, 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 class java.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