Terrier IR Platform
1.1.1

uk.ac.gla.terrier.compression
Class BitInputStream

java.lang.Object
  extended by uk.ac.gla.terrier.compression.BitInputStream

public class BitInputStream
extends java.lang.Object

This class provides sequential stream access to a compressed BitFile file.

Version:
$Revision: 1.18 $
Author:
Gianni Amati, Vassilis Plachouras, Douglas Johnson
See Also:
BitFile

Constructor Summary
BitInputStream(java.io.File file)
          Constructs an instance of the class for a given file
BitInputStream(java.io.InputStream is)
          Constructs an instance of the class for a given stream.
BitInputStream(java.lang.String filename)
          Constructs an instance of the class for a given filename
 
Method Summary
 void close()
          Closes the stream.
 byte getBitOffset()
          Returns the bit offset in the last byte.
 long getByteOffset()
          Returns the byte offset of the stream.
 int readBinary(int noBits)
          Reads a binary integer from the already read buffer.
 int readGamma()
          Reads a gamma encoded integer from the stream
 int readUnary()
          Reads a unary encoded integer from the stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitInputStream

public BitInputStream(java.io.InputStream is)
               throws java.io.IOException
Constructs an instance of the class for a given stream. We recommend that the inputstream passed to this class if buffered in some way - ie using java.io.BufferedInputStream

Parameters:
is - java.io.InputStream the underlying input stream
Throws:
java.io.IOException - if an I/O error occurs

BitInputStream

public BitInputStream(java.lang.String filename)
               throws java.io.IOException
Constructs an instance of the class for a given filename

Parameters:
filename - java.lang.String the name of the undelying file
Throws:
java.io.IOException - if an I/O error occurs

BitInputStream

public BitInputStream(java.io.File file)
               throws java.io.IOException
Constructs an instance of the class for a given file

Parameters:
file - java.io.File the underlying file
Throws:
java.io.IOException - if an I/O error occurs
Method Detail

readBinary

public int readBinary(int noBits)
               throws java.io.IOException
Reads a binary integer from the already read buffer. No IO is performed and 0 is returned if noBits == 0. NB: noBits > than 32 will give undefined results.

Parameters:
noBits - the number of binary bits to read
Returns:
the decoded integer, -1 if eof was reached unexpectedly
Throws:
java.io.IOException - if an I/O error occurs

close

public void close()
           throws java.io.IOException
Closes the stream.

Throws:
java.io.IOException - if an I/O error occurs

readUnary

public int readUnary()
              throws java.io.IOException
Reads a unary encoded integer from the stream.

Returns:
the decoded integer, or -1 if EOF is found
Throws:
java.io.IOException - if an I/O error occurs

readGamma

public int readGamma()
              throws java.io.IOException
Reads a gamma encoded integer from the stream

Returns:
the decoded integer, or -1 if EOF is found
Throws:
java.io.IOException - if an I/O error occurs

getByteOffset

public long getByteOffset()
Returns the byte offset of the stream. It corresponds to the offset of the byte from which the next bit will be read.

Returns:
the byte offset in the stream.

getBitOffset

public byte getBitOffset()
Returns the bit offset in the last byte. It corresponds to the next bit that it will be read.

Returns:
the bit offset in the stream.

Terrier IR Platform
1.1.1

Terrier Information Retrieval Platform 1.1.1. Copyright 2004-2007 University of Glasgow