org.apache.hadoop.fs

## Class FileStatus

- java.lang.Object
- - org.apache.hadoop.fs.FileStatus

- All Implemented Interfaces:
    ObjectInputValidation, Serializable, Comparable<Object>, Writable
  Direct Known Subclasses:
    LocatedFileStatus

      @InterfaceAudience.Public
       @InterfaceStability.Stable
      public class FileStatus
      extends Object
      implements Writable, Comparable<Object>, Serializable, ObjectInputValidation

  Interface that represents the client side information for a file.
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `FileStatus.AttrFlags` Flags for entity attributes.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static Set<FileStatus.AttrFlags>` | `NONE` Shared, empty set of attributes (a common case for FileStatus).

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FileStatus()`
    `FileStatus(FileStatus other)` Copy constructor.
    `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
    `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(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(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(long length, boolean isdir, int block_replication, long blocksize, long modification_time, Path path)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Set<FileStatus.AttrFlags>` | `attributes(boolean acl, boolean crypt, boolean ec, boolean sn)` Convert boolean attributes to a set of flags.
    `int` | `compareTo(FileStatus o)` Compare this FileStatus to another FileStatus
    `int` | `compareTo(Object o)` Compare this FileStatus to another FileStatus.
    `boolean` | `equals(Object o)` Compare if this object is equal to another object
    `long` | `getAccessTime()` Get the access time of the file.
    `long` | `getBlockSize()` Get the block size of the file.
    `String` | `getGroup()` Get the group associated with the file.
    `long` | `getLen()` Get the length of this file, in bytes.
    `long` | `getModificationTime()` Get the modification time of the file.
    `String` | `getOwner()` Get the owner of the file.
    `Path` | `getPath()`
    `FsPermission` | `getPermission()` Get FsPermission associated with the file.
    `short` | `getReplication()` Get the replication factor of a file.
    `Path` | `getSymlink()`
    `boolean` | `hasAcl()` Tell whether the underlying file or directory has ACLs set.
    `int` | `hashCode()` Returns a hash code value for the object, which is defined as the hash code of the path name.
    `boolean` | `isDir()` Deprecated. Use `isFile()`, `isDirectory()`, and `isSymlink()` instead.
    `boolean` | `isDirectory()` Is this a directory?
    `boolean` | `isEncrypted()` Tell whether the underlying file or directory is encrypted or not.
    `boolean` | `isErasureCoded()` Tell whether the underlying file or directory is erasure coded or not.
    `boolean` | `isFile()` Is this a file?
    `boolean` | `isSnapshotEnabled()` Check if directory is Snapshot enabled or not.
    `boolean` | `isSymlink()` Is this a symbolic link?
    `void` | `readFields(DataInput in)` Deprecated. Use the `PBHelper` and protobuf serialization directly.
    `protected void` | `setGroup(String group)` Sets group.
    `protected void` | `setOwner(String owner)` Sets owner.
    `void` | `setPath(Path p)`
    `protected void` | `setPermission(FsPermission permission)` Sets permission.
    `void` | `setSymlink(Path p)`
    `String` | `toString()`
    `void` | `validateObject()`
    `void` | `write(DataOutput out)` Deprecated. Use the `PBHelper` and protobuf serialization directly.

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### NONE

          public static final Set<FileStatus.AttrFlags> NONE

      Shared, empty set of attributes (a common case for FileStatus).

  - ### Constructor Detail

    - #### 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

    - #### 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`

  - ### Method Detail

    - #### 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. Use `isFile()`, `isDirectory()`, and `isSymlink()` instead.
      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`

    - #### setSymlink

          public void setSymlink(Path p)

    - #### compareTo

          public int compareTo(FileStatus o)

      Compare this FileStatus to another FileStatus
      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. 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`
      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`
      See Also:
        `PBHelper.convert(FileStatus)`

    - #### validateObject

          public void validateObject()
                              throws InvalidObjectException

      Specified by:
        `validateObject` in interface `ObjectInputValidation`
      Throws:
        `InvalidObjectException`

Copyright © 2008–2022 Apache Software Foundation. All rights reserved.