org.apache.commons.io

## Enum RandomAccessFileMode

- java.lang.Object
- - java.lang.Enum<RandomAccessFileMode>
  - - org.apache.commons.io.RandomAccessFileMode

- All Implemented Interfaces:
    Serializable, Comparable<RandomAccessFileMode>

      public enum RandomAccessFileMode
      extends Enum<RandomAccessFileMode>

  Enumerates access modes for `RandomAccessFile` with factory methods.
  See Also:
    `RandomAccessFile(File, String)`, `RandomAccessFile(String, String)`, `Enum`

- - ### Enum Constant Summary

    Enum Constants
    Enum Constant and Description
    `READ_ONLY` Defines mode "r" to open a `RandomAccessFile` for reading only.
    `READ_WRITE` Defines mode "rw" to open a `RandomAccessFile` for reading and writing.
    `READ_WRITE_SYNC_ALL` Defines mode "rws" to open a `RandomAccessFile` 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 a `RandomAccessFile` 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.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `R`
    `static String` | `RW`
    `static String` | `RWD`
    `static String` | `RWS`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `accept(Path file, IOConsumer<RandomAccessFile> consumer)` Performs an operation on the `RandomAccessFile` specified at the given `Path`.
    `<T> T` | `apply(Path file, IOFunction<RandomAccessFile,T> function)` Applies the given function for a `RandomAccessFile` specified at the given `Path`.
    `RandomAccessFile` | `create(File file)` Constructs a random access file to read from, and optionally to write to, the file specified by the `File` argument.
    `RandomAccessFile` | `create(Path file)` Constructs a random access file to read from, and optionally to write to, the file specified by the `File` argument.
    `RandomAccessFile` | `create(String name)` Constructs a random access file to read from, and optionally to write to, the file specified by the `File` argument.
    `String` | `getMode()` Gets the access mode, one of "r", "rw", "rwd", or "rws".
    `boolean` | `implies(RandomAccessFileMode other)` Tests whether this mode implies the given `other` mode.
    `IORandomAccessFile` | `io(String name)` Constructs a random access file to read from, and optionally to write to, the file specified by the `File` argument.
    `static RandomAccessFileMode` | `valueOf(OpenOption... openOption)` Gets the enum value that best fits the given `OpenOption`s.
    `static RandomAccessFileMode` | `valueOf(String name)` Returns the enum constant of this type with the specified name.
    `static RandomAccessFileMode` | `valueOfMode(String mode)` Gets the `RandomAccessFileMode` 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.

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

      `clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf`

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

      `getClass, notify, notifyAll, wait, wait, wait`

- - ### Enum Constant Detail

    - #### READ_ONLY

          public static final RandomAccessFileMode READ_ONLY

      Defines mode "r" to open a `RandomAccessFile` for reading only.
      See Also:
        `RandomAccessFile(File, String)`, `RandomAccessFile(String, String)`

    - #### READ_WRITE

          public static final RandomAccessFileMode READ_WRITE

      Defines mode "rw" to open a `RandomAccessFile` 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 a `RandomAccessFile` 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 a `RandomAccessFile` 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`

  - ### Field Detail

    - #### R

          public static final String R

      See Also:
        Constant Field Values

    - #### RW

          public static final String RW

      See Also:
        Constant Field Values

    - #### RWD

          public static final String RWD

      See Also:
        Constant Field Values

    - #### RWS

          public static final String RWS

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### accept

          public void accept(Path file,
                             IOConsumer<RandomAccessFile> consumer)
                      throws IOException

      Performs an operation on the `RandomAccessFile` specified at the given `Path`.

      This method allocates and releases the `RandomAccessFile` given to the consumer.

      Parameters:
        `file` - the file specifying the `RandomAccessFile` to open.
        `consumer` - the function to apply.
      Throws:
        `FileNotFoundException` - See `IORandomAccessFile(File, String)`.
        `IOException` - Thrown by the given function.

    - #### apply

          public <T> T apply(Path file,
                             IOFunction<RandomAccessFile,T> function)
                      throws IOException

      Applies the given function for a `RandomAccessFile` specified at the given `Path`.

      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 the `RandomAccessFile` to open.
        `function` - the function to apply.
      Returns:
        the function's result value.
      Throws:
        `FileNotFoundException` - See `IORandomAccessFile(File, String)`.
        `IOException` - Thrown by the given function.

    - #### create

          public RandomAccessFile create(File file)
                                  throws FileNotFoundException

      Constructs a random access file to read from, and optionally to write to, the file specified by the `File` argument.

      Prefer `create(Path)` over this.

      Parameters:
        `file` - the file object
      Returns:
        a random access file
      Throws:
        `FileNotFoundException` - See `IORandomAccessFile(File, String)`.

    - #### create

          public RandomAccessFile create(Path file)
                                  throws FileNotFoundException

      Constructs a random access file to read from, and optionally to write to, the file specified by the `File` argument.
      Parameters:
        `file` - the file object
      Returns:
        a random access file
      Throws:
        `FileNotFoundException` - See `IORandomAccessFile(File, String)`.

    - #### create

          public RandomAccessFile create(String name)
                                  throws FileNotFoundException

      Constructs a random access file to read from, and optionally to write to, the file specified by the `File` argument.

      Prefer `create(Path)` over this.

      Parameters:
        `name` - the file object
      Returns:
        a random access file
      Throws:
        `FileNotFoundException` - See `IORandomAccessFile(File, String)`.

    - #### getMode

          public String getMode()

      Gets the access mode, one of "r", "rw", "rwd", or "rws".
      Returns:
        one of "r", "rw", "rwd", or "rws".

    - #### implies

          public boolean implies(RandomAccessFileMode other)

      Tests whether this mode implies the given `other` mode.

      For example:

      1. `READ_WRITE_SYNC_ALL` implies {`READ_WRITE_SYNC_CONTENT`}.
      2. `READ_WRITE_SYNC_CONTENT` implies {`READ_WRITE`}.
      3. `READ_WRITE` implies {`READ_ONLY`}.
      Parameters:
        `other` - the non-null mode to test against.
      Returns:
        whether this mode implies the given `other` mode.

    - #### io

          public IORandomAccessFile io(String name)
                                throws FileNotFoundException

      Constructs a random access file to read from, and optionally to write to, the file specified by the `File` argument.
      Parameters:
        `name` - the file object
      Returns:
        a random access file
      Throws:
        `FileNotFoundException` - See `IORandomAccessFile(File, String)`.

    - #### valueOf

          public static RandomAccessFileMode valueOf(OpenOption... openOption)

      Gets the enum value that best fits the given `OpenOption`s.

      The input must be a legal and working combination for NIO.

      Parameters:
        `openOption` - options like `StandardOpenOption`.
      Returns:
        best fit, by default `READ_ONLY`.
      See Also:
        `StandardOpenOption`

    - #### valueOf

          public static RandomAccessFileMode valueOf(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:
        `IllegalArgumentException` - if this enum type has no constant with the specified name
        `NullPointerException` - if the argument is null

    - #### valueOfMode

          public static RandomAccessFileMode valueOfMode(String mode)

      Gets the `RandomAccessFileMode` 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:
        `IllegalArgumentException` - Thrown when mode is not one of "r", "rw", "rwd", or "rws".

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