org.apache.commons.io.input

## Class ReadAheadInputStream

- java.lang.Object
- - java.io.InputStream
  - - java.io.FilterInputStream
    - - org.apache.commons.io.input.ReadAheadInputStream

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public class ReadAheadInputStream
      extends FilterInputStream

  Implements `InputStream` to asynchronously read ahead from an underlying input stream when a specified amount of data has been read from the current buffer. It does so by maintaining two buffers: an active buffer and a read ahead buffer. The active buffer contains data which should be returned when a read() call is issued. The read ahead buffer is used to asynchronously read from the underlying input stream. When the current active buffer is exhausted, we flip the two buffers so that we can start reading from the read ahead buffer without being blocked by disk I/O.

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

  This class was ported and adapted from Apache Spark commit 933dc6cb7b3de1d8ccaf73d124d6eb95b947ed19.

  See Also:
    `ReadAheadInputStream.Builder`

- - ### Nested Class Summary

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

  - ### Field Summary

    - ### Fields inherited from class java.io.FilterInputStream

      `in`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `available()`
    `static ReadAheadInputStream.Builder` | `builder()` Constructs a new `ReadAheadInputStream.Builder`.
    `void` | `close()`
    `int` | `read()`
    `int` | `read(byte[] b, int offset, int len)`
    `long` | `skip(long n)`

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

      `mark, markSupported, read, 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

      Overrides:
        `available` in class `FilterInputStream`
      Throws:
        `IOException`

    - #### builder

          public static ReadAheadInputStream.Builder builder()

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

    - #### close

          public void close()
                     throws IOException

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

    - #### read

          public int read()
                   throws IOException

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

    - #### read

          public int read(byte[] b,
                          int offset,
                          int len)
                   throws IOException

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

    - #### skip

          public long skip(long n)
                    throws IOException

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