Package org.apache.hadoop.fs.shell
Class PathData
java.lang.Object
org.apache.hadoop.fs.shell.PathData
- All Implemented Interfaces:
Comparable<PathData>
Encapsulates a Path (path), its FileStatus (stat), and its FileSystem (fs).
PathData ensures that the returned path string will be the same as the
one passed in during initialization (unlike Path objects which can
modify the path string).
The stat field will be null if the path does not exist.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumprotected static enum -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPathData(String pathString, Configuration conf) Creates an object to wrap the given parameters as fields.PathData(URI localPath, Configuration conf) Creates an object to wrap the given parameters as fields. -
Method Summary
Modifier and TypeMethodDescriptionintbooleanstatic PathData[]expandAsGlob(String pattern, Configuration conf) Expand the given path as a glob pattern.PathData[]Returns a list of PathData objects of the items contained in the given directory.Returns a RemoteIterator for PathData objects of the items contained in the given directory.getPathDataForChild(PathData child) Creates a new object for a child entry in this directoryinthashCode()protected FSDataInputStreamOpen a file.protected FSDataInputStreamOpen a file for sequential IO.booleanTest if the parent directory existsUpdates the paths's file statusbooleanCheck if the path represents a directory as determined by the basename being "." or "..", or the path ending with a directory separatorReturns a new PathData with the given extension.toFile()Get the path to a local filetoString()Returns the printable version of the path that is either the path as given on the commandline, or the full path
-
Field Details
-
uri
-
fs
-
path
-
stat
-
exists
public boolean exists
-
-
Constructor Details
-
PathData
Creates an object to wrap the given parameters as fields. The string used to create the path will be recorded since the Path object does not return exactly the same string used to initialize it- Parameters:
pathString- a string for a pathconf- the configuration file- Throws:
IOException- if anything goes wrong...
-
PathData
Creates an object to wrap the given parameters as fields. The string used to create the path will be recorded since the Path object does not return exactly the same string used to initialize it- Parameters:
localPath- a local URIconf- the configuration file- Throws:
IOException- if anything goes wrong...
-
-
Method Details
-
refreshStatus
Updates the paths's file status- Returns:
- the updated FileStatus
- Throws:
IOException- if anything goes wrong...
-
suffix
Returns a new PathData with the given extension.- Parameters:
extension- for the suffix- Returns:
- PathData
- Throws:
IOException- shouldn't happen
-
parentExists
Test if the parent directory exists- Returns:
- boolean indicating parent exists
- Throws:
IOException- upon unexpected error
-
representsDirectory
public boolean representsDirectory()Check if the path represents a directory as determined by the basename being "." or "..", or the path ending with a directory separator- Returns:
- boolean if this represents a directory
-
getDirectoryContents
Returns a list of PathData objects of the items contained in the given directory.- Returns:
- list of PathData objects for its children
- Throws:
IOException- if anything else goes wrong...
-
getDirectoryContentsIterator
Returns a RemoteIterator for PathData objects of the items contained in the given directory.- Returns:
- remote iterator of PathData objects for its children
- Throws:
IOException- if anything else goes wrong...
-
getPathDataForChild
Creates a new object for a child entry in this directory- Parameters:
child- the basename will be appended to this object's path- Returns:
- PathData for the child
- Throws:
IOException- if this object does not exist or is not a directory
-
expandAsGlob
Expand the given path as a glob pattern. Non-existent paths do not throw an exception because creation commands like touch and mkdir need to create them. The "stat" field will be null if the path does not exist.- Parameters:
pattern- the pattern to expand as a globconf- the hadoop configuration- Returns:
- list of
PathDataobjects. if the pattern is not a glob, and does not exist, the list will contain a single PathData with a null stat - Throws:
IOException- anything else goes wrong...
-
toString
Returns the printable version of the path that is either the path as given on the commandline, or the full path -
toFile
Get the path to a local file- Returns:
- File representing the local path
- Throws:
IllegalArgumentException- if this.fs is not the LocalFileSystem
-
compareTo
- Specified by:
compareToin interfaceComparable<PathData>
-
equals
-
hashCode
public int hashCode() -
openForSequentialIO
Open a file for sequential IO.This uses FileSystem.openFile() to request sequential IO; the file status is also passed in. Filesystems may use to optimize their IO.
- Returns:
- an input stream
- Throws:
IOException- failure
-
openFile
Open a file.- Parameters:
policy- fadvise policy.- Returns:
- an input stream
- Throws:
IOException- failure
-