# BitInputStream (Apache Commons Compress 1.13 API)

org.apache.commons.compress.utils

## Class BitInputStream

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

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public class BitInputStream
      extends Object
      implements Closeable

  Reads bits from an InputStream.
  Since:
    1.10
  This class is not thread-safe

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BitInputStream(InputStream in, 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(InputStream in,
                        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 IOException

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Throws:
        `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 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:
        `IOException` - on error

Copyright © 2016 The Apache Software Foundation. All rights reserved.