Terrier IR Platform
2.2.1

uk.ac.gla.terrier.compression
Class BitInputStream

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

public class BitInputStream
extends java.lang.Object
implements BitIn

This class reads from a file or an InputStream integers that can be coded with different encoding algorithms. It does not use any internal buffering, and operates with bytes.

Author:
Roi Blanco

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 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 len)
          Reads a binary integer from the already read buffer.
 int readDelta()
          Reads a delta encoded integer from the underlying stream
 int readGamma()
          Reads a gamma encoded integer from the underlying stream
 int readGolomb(int b)
          Reads a Golomb encoded integer
 void readInterpolativeCoding(int[] data, int offset, int len, int lo, int hi)
          Reads a sequence of numbers from the stream interpolative coded.
 int readMinimalBinary(int b)
          Reads a binary encoded integer, given an upper bound
 int readMinimalBinaryZero(int b)
          Reads a minimal binary encoded number, when the upper bound can b zero.
 int readSkewedGolomb(int b)
          Reads a skewed-golomb encoded integer from the underlying stream Consider a bucket-vector v =
 int readUnary()
          Reads a unary encoded integer from the underlying stream
 void skipBits(int len)
          Skip a number of bits in the current input 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

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

close

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

Specified by:
close in interface java.io.Closeable
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
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
Returns:
the bit offset in the stream.

readUnary

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

Specified by:
readUnary in interface BitIn
Returns:
the number read
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 underlying stream

Specified by:
readGamma in interface BitIn
Returns:
the number read
Throws:
java.io.IOException - if an I/O error occurs

readBinary

public int readBinary(int len)
               throws java.io.IOException
Reads a binary integer from the already read buffer.

Specified by:
readBinary in interface BitIn
Parameters:
len - the number of binary bits to read
Returns:
the decoded integer
Throws:
java.io.IOException - if an I/O error occurs

skipBits

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

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

readMinimalBinary

public int readMinimalBinary(int b)
                      throws java.io.IOException
Reads a binary encoded integer, given an upper bound

Parameters:
b - the upper bound
Returns:
the int read
Throws:
java.io.IOException - if an I/O error occurs

readGolomb

public int readGolomb(int b)
               throws java.io.IOException
Reads a Golomb encoded integer

Parameters:
b - the golomb modulus
Returns:
the int read
Throws:
java.io.IOException - if and I/O error occurs

readDelta

public int readDelta()
              throws java.io.IOException
Reads a delta encoded integer from the underlying stream

Returns:
the number read
Throws:
java.io.IOException - if an I/O error occurs

readSkewedGolomb

public int readSkewedGolomb(int b)
                     throws java.io.IOException
Reads a skewed-golomb encoded integer from the underlying stream Consider a bucket-vector v = The sum of the elements in the vector goes b, 3b, 7b, 2^(i-1)*b

Returns:
the number read
Throws:
java.io.IOException - if an I/O error occurs

readInterpolativeCoding

public void readInterpolativeCoding(int[] data,
                                    int offset,
                                    int len,
                                    int lo,
                                    int hi)
                             throws java.io.IOException
Reads a sequence of numbers from the stream interpolative coded.

Parameters:
data - the result vector
offset - offset where to write in the vector
len - the number of integers to decode.
lo - a lower bound (the same one passed to writeInterpolativeCoding)
hi - an upper bound (the same one passed to writeInterpolativeCoding)
Throws:
java.io.IOException - if an I/O error occurs

readMinimalBinaryZero

public int readMinimalBinaryZero(int b)
                          throws java.io.IOException
Reads a minimal binary encoded number, when the upper bound can b zero. Used to interpolative code

Parameters:
b - the upper bound
Returns:
the int read
Throws:
java.io.IOException - if an I/O error occurs

align

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

Specified by:
align in interface BitIn
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