Package org.apache.commons.io
Enum RandomAccessFileMode
- java.lang.Object
-
- java.lang.Enum<RandomAccessFileMode>
-
- org.apache.commons.io.RandomAccessFileMode
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<RandomAccessFileMode>
public enum RandomAccessFileMode extends java.lang.Enum<RandomAccessFileMode>
Enumerates access modes forRandomAccessFile
with factory methods.- Since:
- 2.12.0
- See Also:
RandomAccessFile(File, String)
,RandomAccessFile(String, String)
,Enum
-
-
Enum Constant Summary
Enum Constants Enum Constant Description READ_ONLY
Defines mode "r" to open aRandomAccessFile
for reading only.READ_WRITE
Defines mode "rw" to open aRandomAccessFile
for reading and writing.READ_WRITE_SYNC_ALL
Defines mode "rws" to open aRandomAccessFile
for reading and writing, as with "rw", and also require that every update to the file's content or metadata be written synchronously to the underlying storage device.READ_WRITE_SYNC_CONTENT
Defines mode "rwd" to open aRandomAccessFile
for reading and writing, as with "rw", and also require that every update to the file's content be written synchronously to the underlying storage device.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(java.nio.file.Path file, IOConsumer<java.io.RandomAccessFile> consumer)
Performs an operation on theRandomAccessFile
specified at the givenPath
.<T> T
apply(java.nio.file.Path file, IOFunction<java.io.RandomAccessFile,T> function)
Applies the given function for aRandomAccessFile
specified at the givenPath
.java.io.RandomAccessFile
create(java.io.File file)
Constructs a random access file to read from, and optionally to write to, the file specified by theFile
argument.java.io.RandomAccessFile
create(java.lang.String name)
Constructs a random access file to read from, and optionally to write to, the file specified by theFile
argument.java.io.RandomAccessFile
create(java.nio.file.Path file)
Constructs a random access file to read from, and optionally to write to, the file specified by theFile
argument.java.lang.String
getMode()
Gets the access mode, one of "r", "rw", "rwd", or "rws".boolean
implies(RandomAccessFileMode other)
Tests whether this mode implies the givenother
mode.IORandomAccessFile
io(java.lang.String name)
Constructs a random access file to read from, and optionally to write to, the file specified by theFile
argument.static RandomAccessFileMode
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static RandomAccessFileMode
valueOf(java.nio.file.OpenOption... openOption)
Gets the enum value that best fits the givenOpenOption
s.static RandomAccessFileMode
valueOfMode(java.lang.String mode)
Gets theRandomAccessFileMode
value for the given mode, one of "r", "rw", "rwd", or "rws".static RandomAccessFileMode[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
READ_ONLY
public static final RandomAccessFileMode READ_ONLY
Defines mode "r" to open aRandomAccessFile
for reading only.- See Also:
RandomAccessFile(File, String)
,RandomAccessFile(String, String)
-
READ_WRITE
public static final RandomAccessFileMode READ_WRITE
Defines mode "rw" to open aRandomAccessFile
for reading and writing.- See Also:
RandomAccessFile(File, String)
,RandomAccessFile(String, String)
-
READ_WRITE_SYNC_ALL
public static final RandomAccessFileMode READ_WRITE_SYNC_ALL
Defines mode "rws" to open aRandomAccessFile
for reading and writing, as with "rw", and also require that every update to the file's content or metadata be written synchronously to the underlying storage device.- See Also:
RandomAccessFile(File, String)
,RandomAccessFile(String, String)
,StandardOpenOption.SYNC
-
READ_WRITE_SYNC_CONTENT
public static final RandomAccessFileMode READ_WRITE_SYNC_CONTENT
Defines mode "rwd" to open aRandomAccessFile
for reading and writing, as with "rw", and also require that every update to the file's content be written synchronously to the underlying storage device.- See Also:
RandomAccessFile(File, String)
,RandomAccessFile(String, String)
,StandardOpenOption.DSYNC
-
-
Method Detail
-
values
public static RandomAccessFileMode[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (RandomAccessFileMode c : RandomAccessFileMode.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static RandomAccessFileMode valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
valueOf
public static RandomAccessFileMode valueOf(java.nio.file.OpenOption... openOption)
Gets the enum value that best fits the givenOpenOption
s.The input must be a legal and working combination for NIO.
- Parameters:
openOption
- options likeStandardOpenOption
.- Returns:
- best fit, by default
READ_ONLY
. - Since:
- 2.18.0
- See Also:
StandardOpenOption
-
valueOfMode
public static RandomAccessFileMode valueOfMode(java.lang.String mode)
Gets theRandomAccessFileMode
value for the given mode, one of "r", "rw", "rwd", or "rws".- Parameters:
mode
- one of "r", "rw", "rwd", or "rws".- Returns:
- A RandomAccessFileMode.
- Throws:
java.lang.IllegalArgumentException
- Thrown when mode is not one of "r", "rw", "rwd", or "rws".- Since:
- 2.18.0
-
accept
public void accept(java.nio.file.Path file, IOConsumer<java.io.RandomAccessFile> consumer) throws java.io.IOException
Performs an operation on theRandomAccessFile
specified at the givenPath
.This method allocates and releases the
RandomAccessFile
given to the consumer.- Parameters:
file
- the file specifying theRandomAccessFile
to open.consumer
- the function to apply.- Throws:
java.io.FileNotFoundException
- SeeIORandomAccessFile(File, String)
.java.io.IOException
- Thrown by the given function.- Since:
- 2.18.0
-
apply
public <T> T apply(java.nio.file.Path file, IOFunction<java.io.RandomAccessFile,T> function) throws java.io.IOException
Applies the given function for aRandomAccessFile
specified at the givenPath
.This method allocates and releases the
RandomAccessFile
given to the function.- Type Parameters:
T
- the return type of the function.- Parameters:
file
- the file specifying theRandomAccessFile
to open.function
- the function to apply.- Returns:
- the function's result value.
- Throws:
java.io.FileNotFoundException
- SeeIORandomAccessFile(File, String)
.java.io.IOException
- Thrown by the given function.- Since:
- 2.18.0
-
create
public java.io.RandomAccessFile create(java.io.File file) throws java.io.FileNotFoundException
Constructs a random access file to read from, and optionally to write to, the file specified by theFile
argument.Prefer
create(Path)
over this.- Parameters:
file
- the file object- Returns:
- a random access file
- Throws:
java.io.FileNotFoundException
- SeeIORandomAccessFile(File, String)
.
-
create
public java.io.RandomAccessFile create(java.nio.file.Path file) throws java.io.FileNotFoundException
Constructs a random access file to read from, and optionally to write to, the file specified by theFile
argument.- Parameters:
file
- the file object- Returns:
- a random access file
- Throws:
java.io.FileNotFoundException
- SeeIORandomAccessFile(File, String)
.
-
create
public java.io.RandomAccessFile create(java.lang.String name) throws java.io.FileNotFoundException
Constructs a random access file to read from, and optionally to write to, the file specified by theFile
argument.Prefer
create(Path)
over this.- Parameters:
name
- the file object- Returns:
- a random access file
- Throws:
java.io.FileNotFoundException
- SeeIORandomAccessFile(File, String)
.
-
getMode
public java.lang.String getMode()
Gets the access mode, one of "r", "rw", "rwd", or "rws".- Returns:
- one of "r", "rw", "rwd", or "rws".
- Since:
- 2.18.0
-
implies
public boolean implies(RandomAccessFileMode other)
Tests whether this mode implies the givenother
mode.For example:
READ_WRITE_SYNC_ALL
implies {READ_WRITE_SYNC_CONTENT
}.READ_WRITE_SYNC_CONTENT
implies {READ_WRITE
}.READ_WRITE
implies {READ_ONLY
}.
- Parameters:
other
- the non-null mode to test against.- Returns:
- whether this mode implies the given
other
mode. - Since:
- 2.18.0
-
io
public IORandomAccessFile io(java.lang.String name) throws java.io.FileNotFoundException
Constructs a random access file to read from, and optionally to write to, the file specified by theFile
argument.- Parameters:
name
- the file object- Returns:
- a random access file
- Throws:
java.io.FileNotFoundException
- SeeIORandomAccessFile(File, String)
.- Since:
- 2.18.0
-
-