Class FileStatus

java.lang.Object
org.apache.hadoop.fs.FileStatus
All Implemented Interfaces:
ObjectInputValidation, Serializable, Comparable<Object>, Writable
Direct Known Subclasses:
LocatedFileStatus

@Public @Stable public class FileStatus extends Object implements Writable, Comparable<Object>, Serializable, ObjectInputValidation
Interface that represents the client side information for a file.
See Also:
  • Field Details

    • NONE

      public static final Set<FileStatus.AttrFlags> NONE
      Shared, empty set of attributes (a common case for FileStatus).
  • Constructor Details

    • FileStatus

      public FileStatus()
    • FileStatus

      public FileStatus(long length, boolean isdir, int block_replication, long blocksize, long modification_time, Path path)
    • FileStatus

      public FileStatus(long length, boolean isdir, int block_replication, long blocksize, long modification_time, long access_time, FsPermission permission, String owner, String group, Path path)
      Constructor for file systems on which symbolic links are not supported
      Parameters:
      length - length.
      isdir - isdir.
      block_replication - block replication.
      blocksize - block size.
      modification_time - modification time.
      access_time - access_time.
      permission - permission.
      owner - owner.
      group - group.
      path - the path.
    • FileStatus

      public FileStatus(long length, boolean isdir, int block_replication, long blocksize, long modification_time, long access_time, FsPermission permission, String owner, String group, Path symlink, Path path)
    • FileStatus

      public FileStatus(long length, boolean isdir, int block_replication, long blocksize, long modification_time, long access_time, FsPermission permission, String owner, String group, Path symlink, Path path, boolean hasAcl, boolean isEncrypted, boolean isErasureCoded)
    • FileStatus

      public FileStatus(long length, boolean isdir, int block_replication, long blocksize, long modification_time, long access_time, FsPermission permission, String owner, String group, Path symlink, Path path, Set<FileStatus.AttrFlags> attr)
    • FileStatus

      public FileStatus(FileStatus other) throws IOException
      Copy constructor.
      Parameters:
      other - FileStatus to copy
      Throws:
      IOException - raised on errors performing I/O.
  • Method Details

    • attributes

      public static Set<FileStatus.AttrFlags> attributes(boolean acl, boolean crypt, boolean ec, boolean sn)
      Convert boolean attributes to a set of flags.
      Parameters:
      acl - See FileStatus.AttrFlags.HAS_ACL.
      crypt - See FileStatus.AttrFlags.HAS_CRYPT.
      ec - See FileStatus.AttrFlags.HAS_EC.
      sn - See FileStatus.AttrFlags.SNAPSHOT_ENABLED.
      Returns:
      converted set of flags.
    • getLen

      public long getLen()
      Get the length of this file, in bytes.
      Returns:
      the length of this file, in bytes.
    • isFile

      public boolean isFile()
      Is this a file?
      Returns:
      true if this is a file
    • isDirectory

      public boolean isDirectory()
      Is this a directory?
      Returns:
      true if this is a directory
    • isDir

      @Deprecated public final boolean isDir()
      Deprecated.
      Old interface, instead use the explicit isFile(), isDirectory(), and isSymlink()
      Returns:
      true if this is a directory.
    • isSymlink

      public boolean isSymlink()
      Is this a symbolic link?
      Returns:
      true if this is a symbolic link
    • getBlockSize

      public long getBlockSize()
      Get the block size of the file.
      Returns:
      the number of bytes
    • getReplication

      public short getReplication()
      Get the replication factor of a file.
      Returns:
      the replication factor of a file.
    • getModificationTime

      public long getModificationTime()
      Get the modification time of the file.
      Returns:
      the modification time of file in milliseconds since January 1, 1970 UTC.
    • getAccessTime

      public long getAccessTime()
      Get the access time of the file.
      Returns:
      the access time of file in milliseconds since January 1, 1970 UTC.
    • getPermission

      public FsPermission getPermission()
      Get FsPermission associated with the file.
      Returns:
      permission. If a filesystem does not have a notion of permissions or if permissions could not be determined, then default permissions equivalent of "rwxrwxrwx" is returned.
    • hasAcl

      public boolean hasAcl()
      Tell whether the underlying file or directory has ACLs set.
      Returns:
      true if the underlying file or directory has ACLs set.
    • isEncrypted

      public boolean isEncrypted()
      Tell whether the underlying file or directory is encrypted or not.
      Returns:
      true if the underlying file is encrypted.
    • isErasureCoded

      public boolean isErasureCoded()
      Tell whether the underlying file or directory is erasure coded or not.
      Returns:
      true if the underlying file or directory is erasure coded.
    • isSnapshotEnabled

      public boolean isSnapshotEnabled()
      Check if directory is Snapshot enabled or not.
      Returns:
      true if directory is snapshot enabled
    • getOwner

      public String getOwner()
      Get the owner of the file.
      Returns:
      owner of the file. The string could be empty if there is no notion of owner of a file in a filesystem or if it could not be determined (rare).
    • getGroup

      public String getGroup()
      Get the group associated with the file.
      Returns:
      group for the file. The string could be empty if there is no notion of group of a file in a filesystem or if it could not be determined (rare).
    • getPath

      public Path getPath()
    • setPath

      public void setPath(Path p)
    • setPermission

      protected void setPermission(FsPermission permission)
      Sets permission.
      Parameters:
      permission - if permission is null, default value is set
    • setOwner

      protected void setOwner(String owner)
      Sets owner.
      Parameters:
      owner - if it is null, default value is set
    • setGroup

      protected void setGroup(String group)
      Sets group.
      Parameters:
      group - if it is null, default value is set
    • getSymlink

      public Path getSymlink() throws IOException
      Returns:
      The contents of the symbolic link.
      Throws:
      IOException - raised on errors performing I/O.
    • setSymlink

      public void setSymlink(Path p)
    • compareTo

      public int compareTo(FileStatus o)
      Compare this FileStatus to another FileStatus based on lexicographical order of path.
      Parameters:
      o - the FileStatus to be compared.
      Returns:
      a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
    • compareTo

      public int compareTo(Object o)
      Compare this FileStatus to another FileStatus based on lexicographical order of path. This method was added back by HADOOP-14683 to keep binary compatibility.
      Specified by:
      compareTo in interface Comparable<Object>
      Parameters:
      o - the FileStatus to be compared.
      Returns:
      a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
      Throws:
      ClassCastException - if the specified object is not FileStatus
    • equals

      public boolean equals(Object o)
      Compare if this object is equal to another object
      Overrides:
      equals in class Object
      Parameters:
      o - the object to be compared.
      Returns:
      true if two file status has the same path name; false if not.
    • hashCode

      public int hashCode()
      Returns a hash code value for the object, which is defined as the hash code of the path name.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value for the path name.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • readFields

      @Deprecated public void readFields(DataInput in) throws IOException
      Deprecated.
      Use the PBHelper and protobuf serialization directly.
      Read instance encoded as protobuf from stream.
      Specified by:
      readFields in interface Writable
      Parameters:
      in - Input stream
      Throws:
      IOException - any other problem for readFields.
      See Also:
      • PBHelper.convert(FileStatus)
    • write

      @Deprecated public void write(DataOutput out) throws IOException
      Deprecated.
      Use the PBHelper and protobuf serialization directly.
      Write instance encoded as protobuf to stream.
      Specified by:
      write in interface Writable
      Parameters:
      out - Output stream
      Throws:
      IOException - any other problem for write.
      See Also:
      • PBHelper.convert(FileStatus)
    • validateObject

      public void validateObject() throws InvalidObjectException
      Specified by:
      validateObject in interface ObjectInputValidation
      Throws:
      InvalidObjectException