Package org.apache.hadoop.fs
Enum Class CreateFlag
- All Implemented Interfaces:
Serializable,Comparable<CreateFlag>,Constable
CreateFlag specifies the file create semantic. Users can combine flags like:
EnumSet.of(CreateFlag.CREATE, CreateFlag.APPEND)
Use the CreateFlag as follows:
- CREATE - to create a file if it does not exist, else throw FileAlreadyExists.
- APPEND - to append to a file if it exists, else throw FileNotFoundException.
- OVERWRITE - to truncate a file if it exists, else throw FileNotFoundException.
- CREATE|APPEND - to create a file if it does not exist, else append to an existing file.
- CREATE|OVERWRITE - to create a file if it does not exist, else overwrite an existing file.
- SYNC_BLOCK - to force closed blocks to the disk device.
In addition
Syncable.hsync()should be called after each write, if true synchronous behavior is required. - LAZY_PERSIST - Create the block on transient storage (RAM) if available.
- APPEND_NEWBLOCK - Append data to a new block instead of end of the last partial block.
HadoopIllegalArgumentException:
- APPEND|OVERWRITE
- CREATE|APPEND|OVERWRITE
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionAppend to a file.Create a file.Advise that the first block replica NOT take into account DataNode locality.Create the block on transient storage (RAM) if available.Append data to a new block instead of the end of the last partial block.Advise that a block replica NOT be written to the local rack DataNode where 'local' means the same rack as the client is being run on.NO_LOCAL_WRITEAdvise that a block replica NOT be written to the local DataNode where 'local' means the same host as the client is being run on.Truncate/overwrite a file.Enforce the file to be a replicated file, no matter what its parent directory's replication or erasure coding policy is.Force closed blocks to disk. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidvalidate(Object path, boolean pathExists, EnumSet<CreateFlag> flag) Validate the CreateFlag for create operationstatic voidvalidate(EnumSet<CreateFlag> flag) Validate the CreateFlag and throw exception if it is invalidstatic voidvalidateForAppend(EnumSet<CreateFlag> flag) Validate the CreateFlag for the append operation.static CreateFlagReturns the enum constant of this class with the specified name.static CreateFlag[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
CREATE
Create a file. See javadoc for more description already exists -
OVERWRITE
Truncate/overwrite a file. Same as POSIX O_TRUNC. See javadoc for description. -
APPEND
Append to a file. See javadoc for more description. -
SYNC_BLOCK
Force closed blocks to disk. Similar to POSIX O_SYNC. See javadoc for description. -
LAZY_PERSIST
Create the block on transient storage (RAM) if available. If transient storage is unavailable then the block will be created on disk. HDFS will make a best effort to lazily write these files to persistent storage, however file contents may be lost at any time due to process/ node restarts, hence there is no guarantee of data durability. This flag must only be used for intermediate data whose loss can be tolerated by the application. -
NEW_BLOCK
Append data to a new block instead of the end of the last partial block. This is only useful for APPEND. -
NO_LOCAL_WRITE
Advise that a block replica NOT be written to the local DataNode where 'local' means the same host as the client is being run on. -
SHOULD_REPLICATE
Enforce the file to be a replicated file, no matter what its parent directory's replication or erasure coding policy is. -
IGNORE_CLIENT_LOCALITY
Advise that the first block replica NOT take into account DataNode locality. The first block replica should be placed randomly within the cluster. Subsequent block replicas should follow DataNode locality rules. -
NO_LOCAL_RACK
Advise that a block replica NOT be written to the local rack DataNode where 'local' means the same rack as the client is being run on.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
validate
Validate the CreateFlag and throw exception if it is invalid- Parameters:
flag- set of CreateFlag- Throws:
HadoopIllegalArgumentException- if the CreateFlag is invalid
-
validate
public static void validate(Object path, boolean pathExists, EnumSet<CreateFlag> flag) throws IOException Validate the CreateFlag for create operation- Parameters:
path- Object representing the path; usually String orPathpathExists- pass true if the path exists in the file systemflag- set of CreateFlag- Throws:
IOException- on errorHadoopIllegalArgumentException- if the CreateFlag is invalid
-
validateForAppend
Validate the CreateFlag for the append operation. The flag must contain APPEND, and cannot contain OVERWRITE.- Parameters:
flag- enum set flag.
-