Class PathData

java.lang.Object
org.apache.hadoop.fs.shell.PathData
All Implemented Interfaces:
Comparable<PathData>

@Private @Unstable public class PathData extends Object implements 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.
  • Field Details

    • uri

      protected final URI uri
    • fs

      public final FileSystem fs
    • path

      public final Path path
    • stat

      public FileStatus stat
    • exists

      public boolean exists
  • Constructor Details

    • PathData

      public PathData(String pathString, Configuration conf) throws IOException
      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 path
      conf - the configuration file
      Throws:
      IOException - if anything goes wrong...
    • PathData

      public PathData(URI localPath, Configuration conf) throws IOException
      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 URI
      conf - the configuration file
      Throws:
      IOException - if anything goes wrong...
  • Method Details

    • refreshStatus

      public FileStatus refreshStatus() throws IOException
      Updates the paths's file status
      Returns:
      the updated FileStatus
      Throws:
      IOException - if anything goes wrong...
    • suffix

      public PathData suffix(String extension) throws IOException
      Returns a new PathData with the given extension.
      Parameters:
      extension - for the suffix
      Returns:
      PathData
      Throws:
      IOException - shouldn't happen
    • parentExists

      public boolean parentExists() throws IOException
      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

      public PathData[] getDirectoryContents() throws IOException
      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

      public RemoteIterator<PathData> getDirectoryContentsIterator() throws IOException
      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

      public PathData getPathDataForChild(PathData child) throws IOException
      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

      public static PathData[] expandAsGlob(String pattern, Configuration conf) throws IOException
      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 glob
      conf - the hadoop configuration
      Returns:
      list of PathData objects. 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

      public String toString()
      Returns the printable version of the path that is either the path as given on the commandline, or the full path
      Overrides:
      toString in class Object
      Returns:
      String of the path
    • toFile

      public File toFile()
      Get the path to a local file
      Returns:
      File representing the local path
      Throws:
      IllegalArgumentException - if this.fs is not the LocalFileSystem
    • compareTo

      public int compareTo(PathData o)
      Specified by:
      compareTo in interface Comparable<PathData>
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • openForSequentialIO

      protected FSDataInputStream openForSequentialIO() throws IOException
      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

      protected FSDataInputStream openFile(String policy) throws IOException
      Open a file.
      Parameters:
      policy - fadvise policy.
      Returns:
      an input stream
      Throws:
      IOException - failure