Package org.terrier.compression.bit
Class BitFileInMemory
- java.lang.Object
-
- org.terrier.compression.bit.BitFileInMemory
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,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 lot latency. This class will fail if the file is larger than Integer.MAX_VALUE. Use BitFileInMemoryLarge instead.- Author:
- Craig Macdonald
-
-
Constructor Summary
Constructors Constructor Description BitFileInMemory(byte[] buffer)Create an object using the specified data as the compressed dataBitFileInMemory(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close this object.BitInreadReset(long startByteOffset, byte startBitOffset)Reads from the file a specific number of bytes and after this call, a sequence of read calls may follow.BitInreadReset(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.
-
-
-
Constructor Detail
-
BitFileInMemory
public BitFileInMemory(java.lang.String filename) throws java.io.IOExceptionLoads 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.IOExceptionLoads the entire specified inputstream into memory. Length is assumed to be as specified.- Parameters:
is- InputStream containing the compressed bitfilelength- 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:
readResetin interfaceBitInSeekable- Parameters:
startByteOffset- the starting byte to read fromstartBitOffset- the bit offset in the starting byteendByteOffset- the ending byteendBitOffset- 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:
readResetin interfaceBitInSeekable- Parameters:
startByteOffset- the starting byte to read fromstartBitOffset- 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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
-