org.apache.commons.io.input

## Class RandomAccessFileInputStream

- java.lang.Object
- - java.io.InputStream
  - - org.apache.commons.io.input.AbstractInputStream
    - - org.apache.commons.io.input.RandomAccessFileInputStream

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public class RandomAccessFileInputStream
      extends AbstractInputStream

  Streams data from a `RandomAccessFile` starting at its current position.

  To build an instance, use `RandomAccessFileInputStream.Builder`.

  See Also:
    `RandomAccessFileInputStream.Builder`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `RandomAccessFileInputStream.Builder` Builds a new `RandomAccessFileInputStream`.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `available()` Gets an estimate of the number of bytes that can be read (or skipped over) from this input stream.
    `long` | `availableLong()` Gets the number of bytes that can be read (or skipped over) from this input stream.
    `static RandomAccessFileInputStream.Builder` | `builder()` Constructs a new `RandomAccessFileInputStream.Builder`.
    `void` | `close()`
    `long` | `copy(long pos, long size, OutputStream os)` Copies our bytes from the given starting position for a size to the output stream.
    `RandomAccessFile` | `getRandomAccessFile()` Gets the underlying file.
    `boolean` | `isCloseOnClose()` Tests whether to close the underlying file when this stream is closed, defaults to false for compatibility.
    `int` | `read()`
    `int` | `read(byte[] bytes)`
    `int` | `read(byte[] bytes, int offset, int length)`
    `long` | `skip(long skipCount)`

    - ### Methods inherited from class org.apache.commons.io.input.AbstractInputStream

      `checkOpen, isClosed, setClosed`

    - ### Methods inherited from class java.io.InputStream

      `mark, markSupported, reset`

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

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### available

          public int available()
                        throws IOException

      Gets an estimate of the number of bytes that can be read (or skipped over) from this input stream.

      If there are more than `Integer.MAX_VALUE` bytes available, return `Integer.MAX_VALUE`.

      Overrides:
        `available` in class `InputStream`
      Returns:
        An estimate of the number of bytes that can be read.
      Throws:
        `IOException` - If an I/O error occurs.

    - #### availableLong

          public long availableLong()
                             throws IOException

      Gets the number of bytes that can be read (or skipped over) from this input stream.
      Returns:
        The number of bytes that can be read.
      Throws:
        `IOException` - If an I/O error occurs.

    - #### builder

          public static RandomAccessFileInputStream.Builder builder()

      Constructs a new `RandomAccessFileInputStream.Builder`.
      Returns:
        a new `RandomAccessFileInputStream.Builder`.

    - #### close

          public void close()
                     throws IOException

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Overrides:
        `close` in class `AbstractInputStream`
      Throws:
        `IOException`

    - #### copy

          public long copy(long pos,
                           long size,
                           OutputStream os)
                    throws IOException

      Copies our bytes from the given starting position for a size to the output stream.
      Parameters:
        `pos` - Where to start copying. The offset position, measured in bytes from the beginning of the file, at which to set the file pointer.
        `size` - The number of bytes to copy.
        `os` - Where to copy.
      Returns:
        The number of bytes copied..
      Throws:
        `IOException` - if `pos` is less than `0` or if an I/O error occurs.

    - #### getRandomAccessFile

          public RandomAccessFile getRandomAccessFile()

      Gets the underlying file.
      Returns:
        the underlying file.

    - #### isCloseOnClose

          public boolean isCloseOnClose()

      Tests whether to close the underlying file when this stream is closed, defaults to false for compatibility.
      Returns:
        Whether to close the underlying file when this stream is closed.

    - #### read

          public int read()
                   throws IOException

      Specified by:
        `read` in class `InputStream`
      Throws:
        `IOException`

    - #### read

          public int read(byte[] bytes)
                   throws IOException

      Overrides:
        `read` in class `InputStream`
      Throws:
        `IOException`

    - #### read

          public int read(byte[] bytes,
                          int offset,
                          int length)
                   throws IOException

      Overrides:
        `read` in class `InputStream`
      Throws:
        `IOException`

    - #### skip

          public long skip(long skipCount)
                    throws IOException

      Overrides:
        `skip` in class `InputStream`
      Throws:
        `IOException`