Class CompressedBlockReader

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public final class CompressedBlockReader
    extends Object
    implements Closeable
    Reader for a virtual contiguous address range backed by compressed blocks of data. Format: | version (byte) | compression (byte) | block size (int) | num blocks (int) | end offsets | compressed data | This mechanism supports two modes of use, the first where callers may ask for a range of data from the underlying blocks, provided by getRange(long, int). The ByteBuffer provided by this method may or may not be valid after additional calls to getRange(long, int) or calls to seekBlock(int). For fixed width values which are aligned with the block size, callers may also use the method getDecompressedDataBuffer() to have direct access to the current uncompressed block, and use the methods loadBlock(long) to load the correct block and translate a virtual offset into the relative offset, or seekBlock(int) to change which block is currently loaded. getRange(long, int) uses these same mechanisms internally to supply data.
    See Also:
    for writer
    • Constructor Detail

      • CompressedBlockReader

        public CompressedBlockReader​(CompressionStrategy compressionStrategy,
                                     int numBlocks,
                                     int blockSize,
                                     boolean copyValuesOnRead,
                                     IntBuffer endOffsetsBuffer,
                                     ByteBuffer compressedDataBuffer,
                                     ByteOrder compressionByteOrder,
                                     ByteOrder valueByteOrder)
    • Method Detail

      • getSize

        public long getSize()
        Get size in bytes of virtual contiguous buffer
      • getCurrentBlockNumber

        public int getCurrentBlockNumber()
        Get current block number of data loaded in decompressedDataBuffer
      • getDecompressedDataBuffer

        public ByteBuffer getDecompressedDataBuffer()
        Current decompressed data buffer of the data located in currentBlockNumber
      • getRange

        public ByteBuffer getRange​(long startOffset,
                                   int size)
        Get ByteBuffer containing data from starting offset of contiguous virtual address range of the specified size. If this data spans more than a single block, it will be copied on heap, but if not, will be a view into decompressedDataBuffer. The data returned by this method is not guaranteed to still be readable after another call to getRange(long, int) or a call to seekBlock(int).
      • loadBlock

        public int loadBlock​(long startOffset)
        Load the block for the specified virtual offset, returning the relative offset into decompressedDataBuffer of the currentBlockNumber.
      • seekBlock

        public void seekBlock​(int block)
        Swap the current data in decompressedDataBuffer to the specified block