Terrier IR Platform
2.2.1

uk.ac.gla.terrier.compression
Class OldBitInputStream

java.lang.Object
  extended by uk.ac.gla.terrier.compression.BitInputStream
      extended by uk.ac.gla.terrier.compression.OldBitInputStream
All Implemented Interfaces:
java.io.Closeable, BitIn

public class OldBitInputStream
extends BitInputStream

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

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

Constructor Summary
OldBitInputStream(java.io.File file)
          Constructs an instance of the class for a given file
OldBitInputStream(java.io.InputStream is)
          Constructs an instance of the class for a given stream.
OldBitInputStream(java.lang.String filename)
          Constructs an instance of the class for a given filename
 
Method Summary
 void align()
          Aligns the stream to the next byte
 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.
 void skipBits(int noBits)
          Skip a number of bits in the current input stream
 
Methods inherited from class uk.ac.gla.terrier.compression.BitInputStream
readDelta, readGolomb, readInterpolativeCoding, readMinimalBinary, readMinimalBinaryZero, readSkewedGolomb
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OldBitInputStream

public OldBitInputStream(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

OldBitInputStream

public OldBitInputStream(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

OldBitInputStream

public OldBitInputStream(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.

Specified by:
readBinary in interface BitIn
Overrides:
readBinary in class BitInputStream
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

skipBits

public void skipBits(int noBits)
              throws java.io.IOException
Skip a number of bits in the current input stream

Specified by:
skipBits in interface BitIn
Overrides:
skipBits in class BitInputStream
Parameters:
noBits - The number of bits to skip
Throws:
java.io.IOException - if an I/O error occurs

close

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

Specified by:
close in interface java.io.Closeable
Overrides:
close in class BitInputStream
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.

Specified by:
readUnary in interface BitIn
Overrides:
readUnary in class BitInputStream
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

Specified by:
readGamma in interface BitIn
Overrides:
readGamma in class BitInputStream
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.

Specified by:
getByteOffset in interface BitIn
Overrides:
getByteOffset in class BitInputStream
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.

Specified by:
getBitOffset in interface BitIn
Overrides:
getBitOffset in class BitInputStream
Returns:
the bit offset in the stream.

align

public void align()
           throws java.io.IOException
Aligns the stream to the next byte

Specified by:
align in interface BitIn
Overrides:
align in class BitInputStream
Throws:
java.io.IOException - if an I/O error occurs

Terrier IR Platform
2.2.1

Terrier Information Retrieval Platform 2.2.1. Copyright 2004-2008 University of Glasgow