i2p.susi.util

## Class EOFOnMatchInputStream

- java.lang.Object
- - java.io.InputStream
  - - java.io.FilterInputStream
    - - java.io.PushbackInputStream
      - - i2p.susi.util.EOFOnMatchInputStream

- All Implemented Interfaces:
    ReadCounter, Closeable, AutoCloseable

      public class EOFOnMatchInputStream
      extends PushbackInputStream
      implements ReadCounter

  InputStream that returns EOF when input matches specified bytes. The reader never sees bytes from a full match. Extends PushbackInputStream for convenience but uses its buffer as a FIFO, not a stack. Do not call unread() methods externally.

- - ### Field Summary

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

      `buf, pos`

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

      `in`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `EOFOnMatchInputStream(InputStream in, byte[] match)` Non-counter mode.
    `EOFOnMatchInputStream(InputStream in, ReadCounter ctr, byte[] match)` Counter mode.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `long` | `getRead()` If constructed with a counter, returns the count (not necessarily starting at 0) minus the buffered/matched count.
    `int` | `read()` Debug only.
    `int` | `read(byte[] buf, int off, int len)`
    `long` | `skip(long n)`
    `boolean` | `wasFound()`

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

      `available, close, mark, markSupported, reset, unread, unread, unread`

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

      `read`

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

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

- - ### Constructor Detail

    - #### EOFOnMatchInputStream

          public EOFOnMatchInputStream(InputStream in,
                                       byte[] match)

      Non-counter mode. getRead() will return 0.
      Parameters:
        `match` - will be copied

    - #### EOFOnMatchInputStream

          public EOFOnMatchInputStream(InputStream in,
                                       ReadCounter ctr,
                                       byte[] match)

      Counter mode. getRead() will the ReadCounter's value, not including the match bytes.
      Parameters:
        `match` - will be copied

  - ### Method Detail

    - #### getRead

          public long getRead()

      If constructed with a counter, returns the count (not necessarily starting at 0) minus the buffered/matched count. Otherwise returns 0.
      Specified by:
        `getRead` in interface `ReadCounter`

    - #### read

          public int read()
                   throws IOException

      Debug only. Return the buffer.
      Overrides:
        `read` in class `PushbackInputStream`
      Returns:
        the buffer
      Throws:
        `IOException`

    - #### read

          public int read(byte[] buf,
                          int off,
                          int len)
                   throws IOException

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

    - #### skip

          public long skip(long n)
                    throws IOException

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

    - #### wasFound

          public boolean wasFound()

      Returns:
        true if we returned EOF because we hit the match