korat.utils.io
Class BitInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by korat.utils.io.BitInputStream
All Implemented Interfaces:
Closeable, IBitReader

public class BitInputStream
extends FilterInputStream
implements IBitReader

Utility for reading bits from underlying InputStream.

Author:
Aleksandar Milicevic

Field Summary
private  int buff
           
private  int buffSize
           
private static long[] MASKS
           
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
BitInputStream(InputStream in)
           
 
Method Summary
 int readBitsAsInt(int numOfBits)
          Reads the given number of bits and interprets them as int.
 long readBitsAsLong(int numOfBits)
          Reads the given number of bits and interprets them as long
 double readDouble()
          Reads 64 bits and interprets them as double.
 float readFloat()
          Reads 32 bits and interprets them as float.
 int readInt()
          Reads 32 bits and interprets them as int.
 long readLong()
          Reads 64 bits and interprets them as long.
 
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MASKS

private static final long[] MASKS

buff

private int buff

buffSize

private int buffSize
Constructor Detail

BitInputStream

public BitInputStream(InputStream in)
Parameters:
in - As per the general contract of the FilterInputStream.
Method Detail

readBitsAsLong

public long readBitsAsLong(int numOfBits)
                    throws IOException
Description copied from interface: IBitReader
Reads the given number of bits and interprets them as long

Specified by:
readBitsAsLong in interface IBitReader
Parameters:
numOfBits - number of bits to read. Has to be in the range from 1 to 64.
Returns:
value of the read bits interpreted as long.
Throws:
IOException - if an I/O error occurs.

readBitsAsInt

public int readBitsAsInt(int numOfBits)
                  throws IOException
Description copied from interface: IBitReader
Reads the given number of bits and interprets them as int.

Specified by:
readBitsAsInt in interface IBitReader
Parameters:
numOfBits - number of bits to read. Has to be in the range from 1 to 31.
Returns:
value of the read bits interpreted as int.
Throws:
IOException - if an I/O error occurs.

readInt

public int readInt()
            throws IOException
Description copied from interface: IBitReader
Reads 32 bits and interprets them as int.

Specified by:
readInt in interface IBitReader
Returns:
value of 32 read bits interpreted as int.
Throws:
IOException - if an I/O error occurs.

readLong

public long readLong()
              throws IOException
Description copied from interface: IBitReader
Reads 64 bits and interprets them as long.

Specified by:
readLong in interface IBitReader
Returns:
value of 64 read bits interpreted as long.
Throws:
IOException - if an I/O error occurs.

readFloat

public float readFloat()
                throws IOException
Description copied from interface: IBitReader
Reads 32 bits and interprets them as float.

Specified by:
readFloat in interface IBitReader
Returns:
value of 32 read bits interpreted as float.
Throws:
IOException - if an I/O error occurs.

readDouble

public double readDouble()
                  throws IOException
Description copied from interface: IBitReader
Reads 64 bits and interprets them as double.

Specified by:
readDouble in interface IBitReader
Returns:
value of 64 read bits interpreted as double.
Throws:
IOException - if an I/O error occurs.