Package com.sleepycat.util

## Class FastInputStream

- java.lang.Object
- - java.io.InputStream
  - - com.sleepycat.util.FastInputStream

- All Implemented Interfaces:
    `java.io.Closeable`, `java.lang.AutoCloseable`
  Direct Known Subclasses:
    `TupleInput`

      public class FastInputStream
      extends java.io.InputStream

  A replacement for ByteArrayInputStream that does not synchronize every byte read.

  This class extends `InputStream` and its `read()` methods allow it to be used as a standard input stream. In addition, it provides `readFast()` methods that are not declared to throw `IOException`. `IOException` is never thrown by this class.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected byte[]` | `buf` |
    `protected int` | `len` |
    `protected int` | `mark` |
    `protected int` | `off` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `FastInputStream​(byte[] buffer)` | Creates an input stream.
    `FastInputStream​(byte[] buffer, int offset, int length)` | Creates an input stream.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `int` | `available()` |
    `byte[]` | `getBufferBytes()` | Returns the underlying data being read.
    `int` | `getBufferLength()` | Returns the end of the buffer being read.
    `int` | `getBufferOffset()` | Returns the offset at which data is being read from the buffer.
    `void` | `mark​(int readLimit)` |
    `boolean` | `markSupported()` |
    `int` | `read()` |
    `int` | `read​(byte[] toBuf)` |
    `int` | `read​(byte[] toBuf, int offset, int length)` |
    `int` | `readFast()` | Equivalent to `read()` but does not throw `IOException`.
    `int` | `readFast​(byte[] toBuf)` | Equivalent to `read(byte[])` but does not throw `IOException`.
    `int` | `readFast​(byte[] toBuf, int offset, int length)` | Equivalent to `read(byte[],int,int)` but does not throw `IOException`.
    `void` | `reset()` |
    `long` | `skip​(long count)` |
    `void` | `skipFast​(int count)` | Equivalent to `skip()` but takes an int parameter instead of a long, and does not check whether the count given is larger than the number of remaining bytes.

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

      `close, nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo`

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

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

- - ### Field Detail

    - #### len

          protected int len

    - #### off

          protected int off

    - #### mark

          protected int mark

    - #### buf

          protected byte[] buf

  - ### Constructor Detail

    - #### FastInputStream

          public FastInputStream​(byte[] buffer)

      Creates an input stream.
      Parameters:
        `buffer` - the data to read.

    - #### FastInputStream

          public FastInputStream​(byte[] buffer,
                                 int offset,
                                 int length)

      Creates an input stream.
      Parameters:
        `buffer` - the data to read.
        `offset` - the byte offset at which to begin reading.
        `length` - the number of bytes to read.

  - ### Method Detail

    - #### available

          public int available()

      Overrides:
        `available` in class `java.io.InputStream`

    - #### markSupported

          public boolean markSupported()

      Overrides:
        `markSupported` in class `java.io.InputStream`

    - #### mark

          public void mark​(int readLimit)

      Overrides:
        `mark` in class `java.io.InputStream`

    - #### reset

          public void reset()

      Overrides:
        `reset` in class `java.io.InputStream`

    - #### skip

          public long skip​(long count)

      Overrides:
        `skip` in class `java.io.InputStream`

    - #### read

          public int read()

      Specified by:
        `read` in class `java.io.InputStream`

    - #### read

          public int read​(byte[] toBuf)

      Overrides:
        `read` in class `java.io.InputStream`

    - #### read

          public int read​(byte[] toBuf,
                          int offset,
                          int length)

      Overrides:
        `read` in class `java.io.InputStream`

    - #### skipFast

          public final void skipFast​(int count)

      Equivalent to `skip()` but takes an int parameter instead of a long, and does not check whether the count given is larger than the number of remaining bytes.
      Parameters:
        `count` - the number of bytes to skip.
      See Also:
        `skip(long)`

    - #### readFast

          public final int readFast()

      Equivalent to `read()` but does not throw `IOException`.
      Returns:
        the next byte of data, or -1 if at the end of the stream.
      See Also:
        `read()`

    - #### readFast

          public final int readFast​(byte[] toBuf)

      Equivalent to `read(byte[])` but does not throw `IOException`.
      Parameters:
        `toBuf` - the buffer into which the data is read.
      Returns:
        the number of bytes read, or -1 if at the end of the stream.
      See Also:
        `read(byte[])`

    - #### readFast

          public final int readFast​(byte[] toBuf,
                                    int offset,
                                    int length)

      Equivalent to `read(byte[],int,int)` but does not throw `IOException`.
      Parameters:
        `toBuf` - the buffer into which the data is read.
        `offset` - the start offset in array at which the data is written.
        `length` - the maximum number of bytes to read.
      Returns:
        the number of bytes read, or -1 if at the end of the stream.
      See Also:
        `read(byte[],int,int)`

    - #### getBufferBytes

          public final byte[] getBufferBytes()

      Returns the underlying data being read.
      Returns:
        the underlying data.

    - #### getBufferOffset

          public final int getBufferOffset()

      Returns the offset at which data is being read from the buffer.
      Returns:
        the offset at which data is being read.

    - #### getBufferLength

          public final int getBufferLength()

      Returns the end of the buffer being read.
      Returns:
        the end of the buffer.

Copyright (c) 1996, 2020 Oracle and/or its affiliates. All rights reserved.