org.terrier.compression
Class BitFileBuffered.BitInBuffered

java.lang.Object
  extended by org.terrier.compression.BitFileBuffered.BitInBuffered
All Implemented Interfaces:
java.io.Closeable, BitIn
Enclosing class:
BitFileBuffered

protected static class BitFileBuffered.BitInBuffered
extends java.lang.Object
implements BitIn

Implements a BitIn around a RandomDataInput


Field Summary
protected  int bitOffset
          bit offset in this byte, and in the larger file
protected  byte[] inBuffer
          buffer for the slice of the file being read
protected  long offset
          ofset in the larger file
protected  RandomDataInput parentFile
          parent file
protected  int readByteOffset
          byte offset within the buffer
protected  int size
          size of the buffer
 
Fields inherited from interface org.terrier.compression.BitIn
USUAL_EXTENSION
 
Constructor Summary
protected BitFileBuffered.BitInBuffered()
          empty constructor for child classes
  BitFileBuffered.BitInBuffered(RandomDataInput file, long startByteOffset, byte _bitOffset, int _bufLength)
          Construct a new BitInBuffered on the specified file, starting at the given offset and with the specified buffer length.
 
Method Summary
 void align()
          Aligns the stream to the next byte
 void close()
          Does nothing
 byte getBitOffset()
          Returns the bit offset in the last byte.
 long getByteOffset()
          Returns the byte offset of the stream.
protected  void incrByte()
          Move forward one byte
protected  void incrByte(int i)
          Move forward i bytes
 int readBinary(int len)
          Reads a binary integer from the already read buffer.
 int readDelta()
          Reads a delta encoded integer from the underlying stream
 int readGamma()
          Reads a gamma encoded integer from the underlying stream
 int readGolomb(int b)
          Reads a Golomb encoded integer
protected  void readIn()
          Reads a new byte from the InputStream if we have finished with the current one.
 void readInterpolativeCoding(int[] data, int localoffset, int len, int lo, int hi)
          Reads a sequence of numbers from the stream interpolative coded.
 int readMinimalBinary(int b)
          Reads a binary encoded integer, given an upper bound
 int readMinimalBinaryZero(int b)
          Reads a minimal binary encoded number, when the upper bound can b zero.
 int readSkewedGolomb(int b)
          Reads a skewed-golomb encoded integer from the underlying stream Consider a bucket-vector v = <0, 2b, 4b, ...
 int readUnary()
          Reads a unary encoded integer from the underlying stream
 void skipBits(int len)
          Skip a number of bits in the current input stream
 void skipBytes(long len)
          Skip a number of bytes while reading the bit file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parentFile

protected RandomDataInput parentFile
parent file


offset

protected long offset
ofset in the larger file


inBuffer

protected byte[] inBuffer
buffer for the slice of the file being read


size

protected int size
size of the buffer


readByteOffset

protected int readByteOffset
byte offset within the buffer


bitOffset

protected int bitOffset
bit offset in this byte, and in the larger file

Constructor Detail

BitFileBuffered.BitInBuffered

protected BitFileBuffered.BitInBuffered()
empty constructor for child classes


BitFileBuffered.BitInBuffered

public BitFileBuffered.BitInBuffered(RandomDataInput file,
                                     long startByteOffset,
                                     byte _bitOffset,
                                     int _bufLength)
Construct a new BitInBuffered on the specified file, starting at the given offset and with the specified buffer length.

Parameters:
file - File to seek on
startByteOffset - Start byte offset
_bitOffset - Start bit offset
_bufLength - Number of bytes to buffer
Method Detail

incrByte

protected void incrByte()
Move forward one byte


incrByte

protected void incrByte(int i)
Move forward i bytes


readDelta

public int readDelta()
              throws java.io.IOException
Reads a delta encoded integer from the underlying stream

Specified by:
readDelta in interface BitIn
Returns:
the number read
Throws:
java.io.IOException - if an I/O error occurs

readGamma

public int readGamma()
Reads a gamma encoded integer from the underlying stream

Specified by:
readGamma in interface BitIn
Returns:
the number read

readSkewedGolomb

public int readSkewedGolomb(int b)
                     throws java.io.IOException
Reads a skewed-golomb encoded integer from the underlying stream Consider a bucket-vector v = <0, 2b, 4b, ... , 2^i b, ...> The sum of the elements in the vector goes b, 3b, 7b, 2^(i-1)*b

Specified by:
readSkewedGolomb in interface BitIn
Returns:
the number read
Throws:
java.io.IOException - if an I/O error occurs

readInterpolativeCoding

public void readInterpolativeCoding(int[] data,
                                    int localoffset,
                                    int len,
                                    int lo,
                                    int hi)
                             throws java.io.IOException
Reads a sequence of numbers from the stream interpolative coded.

Specified by:
readInterpolativeCoding in interface BitIn
Parameters:
data - the result vector
localoffset - offset where to write in the vector
len - the number of integers to decode.
lo - a lower bound (the same one passed to writeInterpolativeCoding)
hi - an upper bound (the same one passed to writeInterpolativeCoding)
Throws:
java.io.IOException - if an I/O error occurs

readUnary

public int readUnary()
Reads a unary encoded integer from the underlying stream

Specified by:
readUnary in interface BitIn
Returns:
the number read

readGolomb

public int readGolomb(int b)
               throws java.io.IOException
Reads a Golomb encoded integer

Specified by:
readGolomb in interface BitIn
Parameters:
b - the golomb modulus
Returns:
the int read
Throws:
java.io.IOException - if and I/O error occurs

readMinimalBinary

public int readMinimalBinary(int b)
                      throws java.io.IOException
Reads a binary encoded integer, given an upper bound

Specified by:
readMinimalBinary in interface BitIn
Parameters:
b - the upper bound
Returns:
the int read
Throws:
java.io.IOException - if an I/O error occurs

readMinimalBinaryZero

public int readMinimalBinaryZero(int b)
                          throws java.io.IOException
Reads a minimal binary encoded number, when the upper bound can b zero. Used to interpolative code

Specified by:
readMinimalBinaryZero in interface BitIn
Parameters:
b - the upper bound
Returns:
the int read
Throws:
java.io.IOException - if an I/O error occurs

readIn

protected void readIn()
Reads a new byte from the InputStream if we have finished with the current one.


align

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

Specified by:
align in interface BitIn

readBinary

public int readBinary(int len)
Reads a binary integer from the already read buffer.

Specified by:
readBinary in interface BitIn
Parameters:
len - the number of binary bits to read
Returns:
the decoded integer

skipBits

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

Specified by:
skipBits in interface BitIn
Parameters:
len - The number of bits to skip

skipBytes

public void skipBytes(long len)
               throws java.io.IOException
Skip a number of bytes while reading the bit file. After this opteration, getBitOffset() == 0, so use skipBits to get getBitOffset() to desired value.

Specified by:
skipBytes in interface BitIn
Parameters:
len - The number of bytes to skip
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. Use only when writting

Specified by:
getByteOffset in interface BitIn
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. Use only when writting.

Specified by:
getBitOffset in interface BitIn
Returns:
the bit offset in the stream.

close

public void close()
Does nothing

Specified by:
close in interface java.io.Closeable


Terrier 3.5. Copyright © 2004-2011 University of Glasgow