org.terrier.compression
Class BitFileBuffered

java.lang.Object
  extended by org.terrier.compression.BitFileBuffered
All Implemented Interfaces:
java.io.Closeable, BitInSeekable

public class BitFileBuffered
extends java.lang.Object
implements BitInSeekable

Implementation of BitInSeekable/BitIn interfaces similar to BitFile. However this class buffers only a small area of the posting list, to minimise large memory allocations during retrieval. In contrast to BitFile, this class is read-only.

Author:
Patrice Lacour, Craig Macdonald

Nested Class Summary
protected static class BitFileBuffered.BitInBuffered
          Implements a BitIn around a RandomDataInput
 
Field Summary
protected  int buffer_size
          how much of this file we will buffer
protected static int DEFAULT_BUFFER_LENGTH
          how much of a file to buffer by default
protected  RandomDataInput file
          The underlying file
protected  long fileSize
          how big the file is, so we know when to stop reading
protected static org.apache.log4j.Logger logger
          The logger used
 
Constructor Summary
BitFileBuffered(java.io.File _file)
          Constructs an instance of the class for a given filename, using the default buffer size
BitFileBuffered(java.io.File _file, int bufSize)
          Constructs an instance of the class for a given filename
BitFileBuffered(RandomDataInput f)
          Constructor for a RandomDataInput object
BitFileBuffered(java.lang.String filename)
          Constructs an instance of the class for a given filename.
BitFileBuffered(java.lang.String filename, int bufSize)
          Constructs an instance of the class for a given filename
 
Method Summary
 void close()
          
 BitIn readReset(long startByteOffset, byte startBitOffset)
          Reads from the file from a specific offset.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_LENGTH

protected static final int DEFAULT_BUFFER_LENGTH
how much of a file to buffer by default

See Also:
Constant Field Values

logger

protected static final org.apache.log4j.Logger logger
The logger used


file

protected RandomDataInput file
The underlying file


buffer_size

protected final int buffer_size
how much of this file we will buffer


fileSize

protected long fileSize
how big the file is, so we know when to stop reading

Constructor Detail

BitFileBuffered

public BitFileBuffered(RandomDataInput f)
Constructor for a RandomDataInput object


BitFileBuffered

public BitFileBuffered(java.io.File _file)
Constructs an instance of the class for a given filename, using the default buffer size

Parameters:
_file - the underlying file

BitFileBuffered

public BitFileBuffered(java.lang.String filename)
Constructs an instance of the class for a given filename. Default buffer size

Parameters:
filename - java.lang.String the name of the underlying file

BitFileBuffered

public BitFileBuffered(java.io.File _file,
                       int bufSize)
Constructs an instance of the class for a given filename

Parameters:
_file - the underlying file
bufSize - how much of the file to buffer

BitFileBuffered

public BitFileBuffered(java.lang.String filename,
                       int bufSize)
Constructs an instance of the class for a given filename

Parameters:
filename - java.lang.String the name of the underlying file
bufSize - how much of the file to buffer
Method Detail

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
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

readReset

public BitIn readReset(long startByteOffset,
                       byte startBitOffset)
Reads from the file from a specific offset. After this call, a sequence of read calls may follow.

Specified by:
readReset in interface BitInSeekable
Parameters:
startByteOffset - the starting byte to read from
startBitOffset - the bit offset in the starting byte
Returns:
Returns the BitIn object to use to read that data

close

public void close()

Specified by:
close in interface java.io.Closeable


Terrier 3.5. Copyright © 2004-2011 University of Glasgow