Package 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
@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:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Set<FileStatus.AttrFlags>Shared, empty set of attributes (a common case for FileStatus). -
Constructor Summary
ConstructorsConstructorDescriptionFileStatus(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 supportedFileStatus(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) FileStatus(FileStatus other) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic Set<FileStatus.AttrFlags>attributes(boolean acl, boolean crypt, boolean ec, boolean sn) Convert boolean attributes to a set of flags.intCompare this FileStatus to another FileStatus based on lexicographical order of path.intCompare this FileStatus to another FileStatus based on lexicographical order of path.booleanCompare if this object is equal to another objectlongGet the access time of the file.longGet the block size of the file.getGroup()Get the group associated with the file.longgetLen()Get the length of this file, in bytes.longGet the modification time of the file.getOwner()Get the owner of the file.getPath()Get FsPermission associated with the file.shortGet the replication factor of a file.booleanhasAcl()Tell whether the underlying file or directory has ACLs set.inthashCode()Returns a hash code value for the object, which is defined as the hash code of the path name.final booleanisDir()Deprecated.booleanIs this a directory?booleanTell whether the underlying file or directory is encrypted or not.booleanTell whether the underlying file or directory is erasure coded or not.booleanisFile()Is this a file?booleanCheck if directory is Snapshot enabled or not.booleanIs this a symbolic link?voidreadFields(DataInput in) Deprecated.Use thePBHelperand protobuf serialization directly.protected voidSets group.protected voidSets owner.voidprotected voidsetPermission(FsPermission permission) Sets permission.voidsetSymlink(Path p) toString()voidvoidwrite(DataOutput out) Deprecated.Use thePBHelperand protobuf serialization directly.
-
Field Details
-
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
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- SeeFileStatus.AttrFlags.HAS_ACL.crypt- SeeFileStatus.AttrFlags.HAS_CRYPT.ec- SeeFileStatus.AttrFlags.HAS_EC.sn- SeeFileStatus.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.- 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
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
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
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
-
setPath
-
setPermission
Sets permission.- Parameters:
permission- if permission is null, default value is set
-
setOwner
Sets owner.- Parameters:
owner- if it is null, default value is set
-
setGroup
Sets group.- Parameters:
group- if it is null, default value is set
-
getSymlink
- Returns:
- The contents of the symbolic link.
- Throws:
IOException- raised on errors performing I/O.
-
setSymlink
-
compareTo
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
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:
compareToin interfaceComparable<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
Compare if this object is equal to another object -
hashCode
public int hashCode()Returns a hash code value for the object, which is defined as the hash code of the path name. -
toString
-
readFields
Deprecated.Use thePBHelperand protobuf serialization directly.Read instance encoded as protobuf from stream.- Specified by:
readFieldsin interfaceWritable- Parameters:
in- Input stream- Throws:
IOException- any other problem for readFields.- See Also:
-
PBHelper.convert(FileStatus)
-
write
Deprecated.Use thePBHelperand protobuf serialization directly.Write instance encoded as protobuf to stream.- Specified by:
writein interfaceWritable- Parameters:
out- Output stream- Throws:
IOException- any other problem for write.- See Also:
-
PBHelper.convert(FileStatus)
-
validateObject
- Specified by:
validateObjectin interfaceObjectInputValidation- Throws:
InvalidObjectException
-
isFile(),isDirectory(), andisSymlink()instead.