it.unimi.di.mg4j.index
Class CachingOutputBitStream

java.lang.Object
  extended by it.unimi.dsi.io.OutputBitStream
      extended by it.unimi.di.mg4j.index.CachingOutputBitStream
All Implemented Interfaces:
Closeable, Flushable

public final class CachingOutputBitStream
extends OutputBitStream

A special output bit stream with an additional method buffer() that returns the internal buffer if the internal buffer contains all that has been written since the last call to position(0).

This bit stream is used every time that it is necessary to cache quickly a bit stream. By sizing the buffer size appropriately, most of the times data written to the stream will be readable directly from the buffer. Remember to call OutputBitStream.align() before retrieving the buffer, or some bits might be still floating in the bit buffer.


Field Summary
 
Fields inherited from class it.unimi.dsi.io.OutputBitStream
avail, buffer, DEFAULT_BUFFER_SIZE, DELTA, fileChannel, free, GAMMA, MAX_PRECOMPUTED, os, pos, position, repositionableStream, SHIFTED_GAMMA, wrapping, ZETA_3
 
Constructor Summary
CachingOutputBitStream(File file, int bufferSize)
           
CachingOutputBitStream(String filename, int bufferSize)
           
 
Method Summary
 byte[] buffer()
          Return the internal buffer, if it contains all data.
 
Methods inherited from class it.unimi.dsi.io.OutputBitStream
align, close, flush, position, write, write, write, writeBit, writeBit, writeByteOffset, writeDelta, writeDeltas, writeGamma, writeGammas, writeGolomb, writeGolomb, writeInt, writeLong, writeLongDelta, writeLongGamma, writeLongGolomb, writeLongGolomb, writeLongMinimalBinary, writeLongMinimalBinary, writeLongNibble, writeLongShiftedGamma, writeLongSkewedGolomb, writeLongUnary, writeLongZeta, writeMinimalBinary, writeMinimalBinary, writeNibble, writeShiftedGamma, writeShiftedGammas, writeSkewedGolomb, writeUnary, writeZeta, writtenBits, writtenBits
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingOutputBitStream

public CachingOutputBitStream(File file,
                              int bufferSize)
                       throws FileNotFoundException
Throws:
FileNotFoundException

CachingOutputBitStream

public CachingOutputBitStream(String filename,
                              int bufferSize)
                       throws FileNotFoundException
Throws:
FileNotFoundException
Method Detail

buffer

public byte[] buffer()
Return the internal buffer, if it contains all data.

Note that this method should always be called after an OutputBitStream.align(), or some bits might be still floating in the bit buffer.

Returns:
the internal buffer, if it contains the cached content written since the last call to position(0), or null.