Class BitReader

java.lang.Object
  extended by BitReader

public class BitReader
extends Object

A class that wraps any InputStream to support bitwise reads.

Author:
Michael Goldwasser

Constructor Summary
BitReader(InputStream s)
          Creates a new BitInStream instance that wraps the given InputStream.
 
Method Summary
 void close()
          Closes the underlying InputStream.
static void main(String[] args)
          Unit test on file test.txt presumed to have contents "Hello."
 boolean readBit()
          Reads the next bit, returning true if 1, false if 0.
 int readBits(int n)
          Reads the next n bits, and returns them as the least significant n bits of an int, with earliest read bit at high-end.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitReader

public BitReader(InputStream s)
Creates a new BitInStream instance that wraps the given InputStream.

Parameters:
s - an underlying InputStream
Method Detail

close

public void close()
           throws IOException
Closes the underlying InputStream.

Throws:
IOException - if underlying InputStream throws such an exception

readBit

public boolean readBit()
                throws IOException
Reads the next bit, returning true if 1, false if 0.

Returns:
true if next bit is 1; false otherwise
Throws:
IOException - if underlying InputStream throws such an exception

readBits

public int readBits(int n)
             throws IOException
Reads the next n bits, and returns them as the least significant n bits of an int, with earliest read bit at high-end.

Parameters:
n - Number of bits (must be 0 <= n <= 32)
Returns:
integer with least-significant n bits read
Throws:
IOException - if underlying InputStrea throws such an exception

main

public static void main(String[] args)
                 throws IOException
Unit test on file test.txt presumed to have contents "Hello."

Parameters:
args -
Throws:
IOException