korat.utils.io
Class BitRandomAccessFile

java.lang.Object
  extended by korat.utils.io.BitRandomAccessFile
All Implemented Interfaces:
IBitReader

public class BitRandomAccessFile
extends Object
implements IBitReader

Utility for reading bits from the random access file.

Author:
Aleksandar Milicevic

Field Summary
private  RandomAccessFile file
           
private  int inBuff
           
private  int inBuffSize
           
private static long[] MASKS
           
 
Constructor Summary
BitRandomAccessFile(String fileName)
           
 
Method Summary
 void close()
           
 long getFilePointer()
          Get file pointer in bits
 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.
 void seek(long numBits)
          Positions file pointer to the given location.
 
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

file

private RandomAccessFile file

inBuff

private int inBuff

inBuffSize

private int inBuffSize
Constructor Detail

BitRandomAccessFile

public BitRandomAccessFile(String fileName)
                    throws FileNotFoundException
Throws:
FileNotFoundException
Method Detail

readBitsAsLong

public long readBitsAsLong(int numOfBits)
                    throws IOException
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.

seek

public void seek(long numBits)
          throws IOException
Positions file pointer to the given location. Location is given in a number of bits.

Parameters:
numBits -
Throws:
IOException

readBitsAsInt

public int readBitsAsInt(int numOfBits)
                  throws IOException
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.

getFilePointer

public long getFilePointer()
                    throws IOException
Get file pointer in bits

Returns:
file pointer meassured in bits
Throws:
IOException

close

public void close()
           throws IOException
Throws:
IOException