BitInputStream
Date: 2017-02-08

org.apache.commons.compress.utils

## Class BitInputStream

- java.lang.Object
- - org.apache.commons.compress.utils.BitInputStream

- All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

      public class BitInputStream
      extends java.lang.Object
      implements java.io.Closeable

  Reads bits from an InputStream.
  Since:
    1.10

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BitInputStream(java.io.InputStream in, java.nio.ByteOrder byteOrder)` Constructor taking an InputStream and its bit arrangement.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clearBitCache()` Clears the cache of bits that have been read from the underlying stream but not yet provided via `readBits(int)`.
    `void` | `close()`
    `long` | `readBits(int count)` Returns at most 63 bits read from the underlying stream.

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

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

- - ### Constructor Detail

    - #### BitInputStream

          public BitInputStream(java.io.InputStream in,
                        java.nio.ByteOrder byteOrder)

      Constructor taking an InputStream and its bit arrangement.
      Parameters:
        `in` - the InputStream
        `byteOrder` - the bit arrangement across byte boundaries, either BIG_ENDIAN (aaaaabbb bb000000) or LITTLE_ENDIAN (bbbaaaaa 000000bb)

  - ### Method Detail

    - #### close

          public void close()
                     throws java.io.IOException

      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Throws:
        `java.io.IOException`

    - #### clearBitCache

          public void clearBitCache()

      Clears the cache of bits that have been read from the underlying stream but not yet provided via `readBits(int)`.

    - #### readBits

          public long readBits(int count)
                        throws java.io.IOException

      Returns at most 63 bits read from the underlying stream.
      Parameters:
        `count` - the number of bits to read, must be a positive number not bigger than 63.
      Returns:
        the bits concatenated as a long using the stream's byte order. -1 if the end of the underlying stream has been reached before reading the requested number of bits
      Throws:
        `java.io.IOException` - on error