Terrier IR Platform
2.2.1

uk.ac.gla.terrier.compression
Class OldBitFile

java.lang.Object
  extended by uk.ac.gla.terrier.compression.BitFile
      extended by uk.ac.gla.terrier.compression.OldBitFile
All Implemented Interfaces:
java.io.Closeable, BitIn, BitInSeekable, BitOut

public class OldBitFile
extends BitFile

This class encapsulates a random access file and provides the functionalities to write highly compressed data structures, eg binary encoded, unary encoded and gamma encoded integers greater than zero, as well as specifying their offset in the file. It is employed by the DirectIndex and the InvertedIndex classes. The sequence of method calls to write a sequence of gamma encoded and unary encoded numbers is: file.writeReset();
long startByte1 = file.getByteOffset();
byte startBit1 = file.getBitOffset();
file.writeGamma(20000);
file.writeUnary(2);
file.writeGamma(35000);
file.writeUnary(1);
file.writeGamma(3);
file.writeUnary(2);
file.writeFlush();
long endByte1 = file.getByteOffset();
byte endBit1 = file.getBitOffset();
if (endBit1 == 0 && endByte1 > 0) {
endBit1 = 7;
endByte1--;
}
while for reading a sequence of numbers the sequence of calls is: file.readReset((long) startByte1, (byte) startBit1, (long) endByte1, (byte) endBit1);
int gamma = file.readGamma(); int unary = file.readUnary();

Version:
$Revision: 1.4 $
Author:
Gianni Amati, Vassilis Plachouras, Douglas Johnson

Constructor Summary
OldBitFile(java.io.File file)
          A constuctor for an instance of this class, given an abstract file.
OldBitFile(java.io.File file, java.lang.String access)
          A constuctor for an instance of this class, given an abstract file.
OldBitFile(java.lang.String filename)
          A constuctor for an instance of this class.
OldBitFile(java.lang.String filename, java.lang.String access)
          A constuctor for an instance of this class.
 
Method Summary
 void align()
          Aligns the stream to the next byte
 void close()
          Closes the random access file.
 byte getBitOffset()
          Returns the bit offset of the last current byte in the buffer.
 long getByteOffset()
          Returns the byte offset in the buffer.
 byte[] getInBuffer()
          Returns the current buffer being processed
 int readBinary(int noBits)
          Reads a binary integer from the already read buffer.
 int readGamma()
          Reads and decodes a gamma encoded integer from the already read buffer.
 BitIn readReset(long startByteOffset, byte startBitOffset, long endByteOffset, byte endBitOffset)
          Reads from the file a specific number of bytes and after this call, a sequence of read calls may follow.
 int readUnary()
          Reads a unary integer from the already read buffer.
 void skipBits(int noBits)
          Skip a number of bits in the current input stream
 int writeBinary(int bitsToWrite, int n)
          Deprecated.  
 void writeFlush()
          Deprecated.  
 int writeGamma(int n)
          Deprecated.  
 void writeReset()
          Deprecated.  
 int writeUnary(int n)
          Deprecated.  
 
Methods inherited from class uk.ac.gla.terrier.compression.BitFile
readGolomb, readInterpolativeCoding, readMinimalBinary, readMinimalBinaryZero, readSkewedGolomb, writeGolomb, writeInt, writeInterpolativeCode, writeMinimalBinary, writeSkewedGolomb
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OldBitFile

public OldBitFile(java.io.File file)
A constuctor for an instance of this class, given an abstract file. File access mode is DEFAULT_FILE_MODE.


OldBitFile

public OldBitFile(java.io.File file,
                  java.lang.String access)
A constuctor for an instance of this class, given an abstract file.


OldBitFile

public OldBitFile(java.lang.String filename)
A constuctor for an instance of this class. File access mode is DEFAULT_FILE_MODE


OldBitFile

public OldBitFile(java.lang.String filename,
                  java.lang.String access)
A constuctor for an instance of this class.

Method Detail

close

public void close()
Closes the random access file.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class BitFile

getBitOffset

public byte getBitOffset()
Returns the bit offset of the last current byte in the buffer. This offset corresponds to the position where the next bit is going to be written.

Specified by:
getBitOffset in interface BitIn
Specified by:
getBitOffset in interface BitOut
Overrides:
getBitOffset in class BitFile
Returns:
the bit offset of the current byte in the buffer.

getByteOffset

public long getByteOffset()
Returns the byte offset in the buffer. This offset corresponds to the byte in which the next bit is going to be written or read from.

Specified by:
getByteOffset in interface BitIn
Specified by:
getByteOffset in interface BitOut
Overrides:
getByteOffset in class BitFile
Returns:
the byte offset in the buffer.

readGamma

public int readGamma()
Reads and decodes a gamma encoded integer from the already read buffer.

Specified by:
readGamma in interface BitIn
Overrides:
readGamma in class BitFile
Returns:
the decoded integer

align

public void align()
Aligns the stream to the next byte

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

readReset

public BitIn readReset(long startByteOffset,
                       byte startBitOffset,
                       long endByteOffset,
                       byte endBitOffset)
Reads from the file a specific number of bytes and after this call, a sequence of read calls may follow. The offsets given as arguments are inclusive. For example, if we call this method with arguments 0, 2, 1, 7, it will read in a buffer the contents of the underlying file from the third bit of the first byte to the last bit of the second byte.

Specified by:
readReset in interface BitInSeekable
Overrides:
readReset in class BitFile
Parameters:
startByteOffset - the starting byte to read from
startBitOffset - the bit offset in the starting byte
endByteOffset - the ending byte
endBitOffset - the bit offset in the ending byte. This bit is the last bit of this entry.
Returns:
Returns the BitIn object to use to read that data

readUnary

public int readUnary()
Reads a unary integer from the already read buffer.

Specified by:
readUnary in interface BitIn
Overrides:
readUnary in class BitFile
Returns:
the decoded integer

getInBuffer

public byte[] getInBuffer()
Returns the current buffer being processed


writeFlush

public void writeFlush()
Deprecated. 

Flushes the in-memory buffer to the file after finishing a sequence of write calls.

Overrides:
writeFlush in class BitFile

readBinary

public int readBinary(int noBits)
Reads a binary integer from the already read buffer. No IO 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 BitFile
Parameters:
noBits - the number of binary bits to read
Returns:
the decoded integer

skipBits

public void skipBits(int noBits)
Skip a number of bits in the current input stream

Specified by:
skipBits in interface BitIn
Overrides:
skipBits in class BitFile
Parameters:
noBits - The number of bits to skip

writeBinary

public int writeBinary(int bitsToWrite,
                       int n)
Deprecated. 

Writes a binary integer, of a given length, to the already read buffer.

Specified by:
writeBinary in interface BitOut
Overrides:
writeBinary in class BitFile
Parameters:
bitsToWrite - the number of bits to write
n - the integer to write
Returns:
SHOULD returns number of bits written, but doesnt

writeGamma

public int writeGamma(int n)
Deprecated. 

Writes an gamma encoded integer in the buffer.

Specified by:
writeGamma in interface BitOut
Overrides:
writeGamma in class BitFile
Parameters:
n - The integer to be encoded and saved in the buffer.
Returns:
SHOULD returns number of bits written, but doesnt

writeReset

public void writeReset()
                throws java.io.IOException
Deprecated. 

Prepares for writing to the file unary or gamma encoded integers. It reads the last incomplete byte from the file, according to the bitOffset value

Overrides:
writeReset in class BitFile
Throws:
java.io.IOException

writeUnary

public int writeUnary(int n)
Deprecated. 

Writes a unary integer to the buffer.

Specified by:
writeUnary in interface BitOut
Overrides:
writeUnary in class BitFile
Parameters:
n - The integer to be encoded and writen in the buffer.
Returns:
SHOULD returns number of bits written, but doesnt

Terrier IR Platform
2.2.1

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