org.apache.hadoop.fs
Class Path

java.lang.Object
  extended by org.apache.hadoop.fs.Path
All Implemented Interfaces:
Comparable

@Stringable
@InterfaceAudience.Public
@InterfaceStability.Stable
public class Path
extends Object
implements Comparable

Names a file or directory in a FileSystem. Path strings use slash as the directory separator. A path string is absolute if it begins with a slash.


Field Summary
static String CUR_DIR
           
static String SEPARATOR
          The directory separator, a slash.
static char SEPARATOR_CHAR
           
static boolean WINDOWS
           
 
Constructor Summary
Path(Path parent, Path child)
          Resolve a child path against a parent path.
Path(Path parent, String child)
          Resolve a child path against a parent path.
Path(String pathString)
          Construct a path from a String.
Path(String parent, Path child)
          Resolve a child path against a parent path.
Path(String parent, String child)
          Resolve a child path against a parent path.
Path(String scheme, String authority, String path)
          Construct a Path from components.
Path(URI aUri)
          Construct a path from a URI
 
Method Summary
 int compareTo(Object o)
           
 int depth()
          Return the number of elements in this path.
 boolean equals(Object o)
           
 FileSystem getFileSystem(Configuration conf)
          Return the FileSystem that owns this Path.
 String getName()
          Returns the final component of this path.
 Path getParent()
          Returns the parent of a path or null if at root.
static Path getPathWithoutSchemeAndAuthority(Path path)
           
 int hashCode()
           
 boolean isAbsolute()
          There is some ambiguity here.
 boolean isAbsoluteAndSchemeAuthorityNull()
          Is an absolute path (ie a slash relative path part) AND a scheme is null AND authority is null.
 boolean isRoot()
           
 boolean isUriPathAbsolute()
          True if the path component (i.e.
static boolean isWindowsAbsolutePath(String pathString, boolean slashed)
          Determine whether a given path string represents an absolute path on Windows.
 Path makeQualified(FileSystem fs)
          Deprecated. 
static Path mergePaths(Path path1, Path path2)
          Merge 2 paths such that the second path is appended relative to the first.
 Path suffix(String suffix)
          Adds a suffix to the final name in the path.
 String toString()
           
 URI toUri()
          Convert this to a URI.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SEPARATOR

public static final String SEPARATOR
The directory separator, a slash.

See Also:
Constant Field Values

SEPARATOR_CHAR

public static final char SEPARATOR_CHAR
See Also:
Constant Field Values

CUR_DIR

public static final String CUR_DIR
See Also:
Constant Field Values

WINDOWS

public static final boolean WINDOWS
Constructor Detail

Path

public Path(String parent,
            String child)
Resolve a child path against a parent path.


Path

public Path(Path parent,
            String child)
Resolve a child path against a parent path.


Path

public Path(String parent,
            Path child)
Resolve a child path against a parent path.


Path

public Path(Path parent,
            Path child)
Resolve a child path against a parent path.


Path

public Path(String pathString)
     throws IllegalArgumentException
Construct a path from a String. Path strings are URIs, but with unescaped elements and some additional normalization.

Throws:
IllegalArgumentException

Path

public Path(URI aUri)
Construct a path from a URI


Path

public Path(String scheme,
            String authority,
            String path)
Construct a Path from components.

Method Detail

getPathWithoutSchemeAndAuthority

public static Path getPathWithoutSchemeAndAuthority(Path path)

mergePaths

public static Path mergePaths(Path path1,
                              Path path2)
Merge 2 paths such that the second path is appended relative to the first. The returned path has the scheme and authority of the first path. On Windows, the drive specification in the second path is discarded.

Parameters:
path1 - Path first path
path2 - Path second path, to be appended relative to path1
Returns:
Path merged path

isWindowsAbsolutePath

public static boolean isWindowsAbsolutePath(String pathString,
                                            boolean slashed)
Determine whether a given path string represents an absolute path on Windows. e.g. "C:/a/b" is an absolute path. "C:a/b" is not.

Parameters:
pathString - Supplies the path string to evaluate.
slashed - true if the given path is prefixed with "/".
Returns:
true if the supplied path looks like an absolute path with a Windows drive-specifier.

toUri

public URI toUri()
Convert this to a URI.


getFileSystem

public FileSystem getFileSystem(Configuration conf)
                         throws IOException
Return the FileSystem that owns this Path.

Throws:
IOException

isAbsoluteAndSchemeAuthorityNull

public boolean isAbsoluteAndSchemeAuthorityNull()
Is an absolute path (ie a slash relative path part) AND a scheme is null AND authority is null.


isUriPathAbsolute

public boolean isUriPathAbsolute()
True if the path component (i.e. directory) of this URI is absolute.


isAbsolute

public boolean isAbsolute()
There is some ambiguity here. An absolute path is a slash relative name without a scheme or an authority. So either this method was incorrectly named or its implementation is incorrect. This method returns true even if there is a scheme and authority.


isRoot

public boolean isRoot()
Returns:
true if and only if this path represents the root of a file system

getName

public String getName()
Returns the final component of this path.


getParent

public Path getParent()
Returns the parent of a path or null if at root.


suffix

public Path suffix(String suffix)
Adds a suffix to the final name in the path.


toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

compareTo

public int compareTo(Object o)
Specified by:
compareTo in interface Comparable

depth

public int depth()
Return the number of elements in this path.


makeQualified

@Deprecated
public Path makeQualified(FileSystem fs)
Deprecated. 

Returns a qualified path object. Deprecated - use makeQualified(URI, Path)



Copyright © 2014 Apache Software Foundation. All Rights Reserved.