org.terrier.compression
Class BitFileInMemory

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

public class BitFileInMemory
extends java.lang.Object
implements BitInSeekable

Class which enables a bit compressed file to be read wholly into memory and accessed from there with low latency. This file cannot handle files larger than Integer.MAX_VALUE (2GB)

Author:
Craig Macdonald

Field Summary
protected  byte[] inBuffer
          buffer in memory for the entire compressed file
protected static org.apache.log4j.Logger logger
          The logger used
 
Constructor Summary
BitFileInMemory(byte[] buffer)
          Create an object using the specified data as the compressed data
BitFileInMemory(java.io.InputStream is, long length)
          Loads the entire specified inputstream into memory.
BitFileInMemory(java.lang.String filename)
          Loads the entire file represented by filename into memory
 
Method Summary
 void close()
          Close this object.
 BitIn readReset(long startByteOffset, byte startBitOffset)
          Reads from the file a specific number of bytes and after this call, a sequence of read calls may follow.
 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

logger

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


inBuffer

protected final byte[] inBuffer
buffer in memory for the entire compressed file

Constructor Detail

BitFileInMemory

public BitFileInMemory(java.lang.String filename)
                throws java.io.IOException
Loads the entire file represented by filename into memory

Parameters:
filename - Location of bit file to read into memory
Throws:
java.io.IOException - if anything goes wrong reading the file

BitFileInMemory

public BitFileInMemory(java.io.InputStream is,
                       long length)
                throws java.io.IOException
Loads the entire specified inputstream into memory. Length is assumed to be as specified.

Parameters:
is - InputStream containing the compressed bitfile
length - Expected length of the input stream
Throws:
java.io.IOException - if anything goes wrong reading the inputstream

BitFileInMemory

public BitFileInMemory(byte[] buffer)
Create an object using the specified data as the compressed data

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 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
Returns:
Returns the BitIn object to use to read that data

close

public void close()
Close this object. Does nothing.

Specified by:
close in interface java.io.Closeable


Terrier 3.5. Copyright © 2004-2011 University of Glasgow