Terrier IR Platform
2.2.1

uk.ac.gla.terrier.compression
Class BitByteOutputStream

java.lang.Object
  extended by uk.ac.gla.terrier.compression.BitOutputStream
      extended by uk.ac.gla.terrier.compression.BitByteOutputStream
All Implemented Interfaces:
java.io.Closeable, BitOut
Direct Known Subclasses:
MemorySBOS

public class BitByteOutputStream
extends BitOutputStream

This class provides methods to write compressed integers to an outputstream.
The numbers are written into a byte starting from the most significant bit (i.e, left to right). This class does not use any buffering, it relies on the underlying OutputStream to decide when to flush to disk. It is used for indexing, when keeping many compressed streams in memory (MemoryOutputStream) and a two-level buffering is unnecessary (and slower).

Author:
Roi Blanco

Constructor Summary
BitByteOutputStream()
          Empty constructor, used for subclassing
BitByteOutputStream(java.io.File file)
          Constructs an instance of the class for a given file
BitByteOutputStream(java.io.OutputStream is)
          Constructs an instance of the class for a given stream
BitByteOutputStream(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.
 byte getByteToWrite()
           
 void pad()
          Fills the remaining bits of the current byte with 0s
 int writeInt(int x, int len)
          Writes an integer x into the underlying OutputStream.
 int writeUnary(int x)
          Writes an integer x using unary encoding.
 
Methods inherited from class uk.ac.gla.terrier.compression.BitOutputStream
append, append, flush, padAndFlush, writeBinary, writeDelta, writeGamma, writeGolomb, writeInterpolativeCode, writeMinimalBinary, writeSkewedGolomb
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitByteOutputStream

public BitByteOutputStream(java.io.OutputStream is)
                    throws java.io.IOException
Constructs an instance of the class for a given stream

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

BitByteOutputStream

public BitByteOutputStream(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 underlying file
Throws:
java.io.IOException - if an I/O error occurs

BitByteOutputStream

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

BitByteOutputStream

public BitByteOutputStream()
Empty constructor, used for subclassing

Method Detail

close

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

Specified by:
close in interface java.io.Closeable
Overrides:
close in class BitOutputStream
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 position of the byte in which the next bit will be written.

Specified by:
getByteOffset in interface BitOut
Overrides:
getByteOffset in class BitOutputStream
Returns:
the byte offset in the stream.

getBitOffset

public byte getBitOffset()
Returns the bit offset in the last byte. It corresponds to the position in which the next bit will be written.

Specified by:
getBitOffset in interface BitOut
Overrides:
getBitOffset in class BitOutputStream
Returns:
the bit offset in the stream.

writeUnary

public int writeUnary(int x)
               throws java.io.IOException
Writes an integer x using unary encoding. The encoding is a sequence of x -1 zeroes and 1 one: 1, 01, 001, 0001, etc .. This method is not failsafe, it doesn't check if the argument is 0 or negative.

Specified by:
writeUnary in interface BitOut
Overrides:
writeUnary in class BitOutputStream
Parameters:
x - the number to write
Returns:
the number of bis written
Throws:
java.io.IOException - if an I/O error occurs.

writeInt

public int writeInt(int x,
                    int len)
             throws java.io.IOException
Writes an integer x into the underlying OutputStream. First, it checks if it fits into the current byte we are using for writting, and then it writes as many bytes as necessary

Overrides:
writeInt in class BitOutputStream
Parameters:
x - the int to write
len - length of the int in bits
Returns:
the number of bits written
Throws:
java.io.IOException - if an I/O error occurs.

pad

public void pad()
         throws java.io.IOException
Fills the remaining bits of the current byte with 0s

Throws:
java.io.IOException

getByteToWrite

public byte getByteToWrite()
Returns:
the actual byte it is being written.

Terrier IR Platform
2.2.1

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