Terrier IR Platform
1.1.1

uk.ac.gla.terrier.compression
Class BitOutputStream

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

public class BitOutputStream
extends java.lang.Object

This class creates sequentially a BitFile file from a stream.

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

Constructor Summary
BitOutputStream(java.io.File file)
          Constructs an instance of the class for a given file
BitOutputStream(java.io.OutputStream is)
          Constructs an instance of the class for a given stream.
BitOutputStream(java.lang.String filename)
          Constructs an instance of the class for a given filename
 
Method Summary
 void close()
          Flushes and closes the stream.
 void flush()
          Flush the underlying DataOutputStream to disk
 byte getBitOffset()
          Returns the bit offset in the last byte.
 long getByteOffset()
          Returns the byte offset of the stream.
 void writeBinary(int bitsToWrite, int n)
          Writes a binary integer to the already read buffer.
 void writeGamma(int n)
          Writes an gamma encoded integer to the stream.
 void writeUnary(int n)
          Writes a unary encoded integer to the stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitOutputStream

public BitOutputStream(java.io.OutputStream is)
                throws java.io.IOException
Constructs an instance of the class for a given stream. The OutputStream is should probably be buffered using java.io.BufferedOutputStream

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

BitOutputStream

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

BitOutputStream

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

writeBinary

public void writeBinary(int bitsToWrite,
                        int n)
                 throws java.io.IOException
Writes a binary integer to the already read buffer. NB: bitsToWrite > than 32 will give undefined results.

Parameters:
bitsToWrite - the number of bits to use for encoding
n - the integer
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Flushes and closes the stream.

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

writeUnary

public void writeUnary(int n)
                throws java.io.IOException
Writes a unary encoded integer to the stream.

Parameters:
n - int the integer to write.
Throws:
java.io.IOException - if an I/O error occurs

writeGamma

public void writeGamma(int n)
                throws java.io.IOException
Writes an gamma encoded integer to the stream.

Parameters:
n - The integer to be encoded and saved in the buffer.
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.

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.

Returns:
the bit offset in the stream.

flush

public void flush()
Flush the underlying DataOutputStream to disk


Terrier IR Platform
1.1.1

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