net.i2p.util

## Class LookaheadInputStream

- java.lang.Object
- - java.io.InputStream
  - - java.io.FilterInputStream
    - - net.i2p.util.LookaheadInputStream

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public class LookaheadInputStream
      extends FilterInputStream

  Simple lookahead buffer to keep the last K bytes in reserve, configured to easily be reused. Currently only used by the ResettableGZIPInputStream.

- - ### Field Summary

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

      `in`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LookaheadInputStream(int lookaheadSize)` Configure a stream that hides a number of bytes from the reader.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `getEOFReached()`
    `byte[]` | `getFooter()` Grab the lookahead footer.
    `void` | `initialize(InputStream src)` Start the LookaheadInputStream with the given input stream.
    `int` | `read()`
    `int` | `read(byte[] buf, int off, int len)`
    `long` | `skip(long n)`

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

      `available, close, mark, markSupported, read, reset`

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

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

- - ### Constructor Detail

    - #### LookaheadInputStream

          public LookaheadInputStream(int lookaheadSize)

      Configure a stream that hides a number of bytes from the reader. The last n bytes will never be available from read(), they can only be obtained from getFooter(). initialize() MUST be called before doing any read() calls.
      Parameters:
        `lookaheadSize` - how many bytes to hide

  - ### Method Detail

    - #### getEOFReached

          public boolean getEOFReached()

    - #### getFooter

          public byte[] getFooter()

      Grab the lookahead footer. This will be of size lookaheadsize given in constructor. The last byte received will be in the last byte of the array.

    - #### initialize

          public void initialize(InputStream src)
                          throws IOException

      Start the LookaheadInputStream with the given input stream. Resets everything if the LookaheadInputStream was previously used. WARNING - blocking until lookaheadSize bytes are read!
      Throws:
        `IOException` - if less than lookaheadSize bytes could be read.

    - #### read

          public int read()
                   throws IOException

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

    - #### read

          public int read(byte[] buf,
                          int off,
                          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`