public BlockCompressedRecordFile(final Supplier<? extends Either<IOException, ? extends RandomAccessDataInput>> inputSupplier, final Closeable closeable, String file, Serializer<E> serializer, CompressionCodec codec, BlockingQueue<Decompressor> decompressorPool, int blockSize, int recordIndexBits, int padBits, int maxChunkSize) throws IOException { this.inputSupplier = inputSupplier; this.file = file; this.serializer = serializer; this.codec = codec; this.blockSize = blockSize; this.padBits = padBits; this.maxChunkSize = maxChunkSize; pad = 1<<padBits; padMask = ~(long)(pad-1); shift = Math.max(recordIndexBits - padBits, 0); mask = (1L<<recordIndexBits)-1; closeableRef = SharedReference.create(closeable); try { blockCache = new BlockCache(decompressorPool); } catch (Throwable t) { Closeables2.closeQuietly(closeableRef, log); Throwables.propagateIfInstanceOf(t, IOException.class); throw Throwables.propagate(t); } }
public BlockCompressedRecordFile(final Supplier<? extends Either<IOException, ? extends RandomAccessDataInput>> inputSupplier, final Closeable closeable, String file, Serializer<E> serializer, CompressionCodec codec, BlockingQueue<Decompressor> decompressorPool, int blockSize, int recordIndexBits, int padBits, int maxChunkSize) throws IOException { this.inputSupplier = inputSupplier; this.file = file; this.serializer = serializer; this.codec = codec; this.blockSize = blockSize; this.padBits = padBits; this.maxChunkSize = maxChunkSize; pad = 1<<padBits; padMask = ~(long)(pad-1); shift = Math.max(recordIndexBits - padBits, 0); mask = (1L<<recordIndexBits)-1; closeableRef = SharedReference.create(closeable); try { blockCache = new BlockCache(decompressorPool); } catch (Throwable t) { Closeables2.closeQuietly(closeableRef, log); Throwables.propagateIfInstanceOf(t, IOException.class); throw Throwables.propagate(t); } }
@Override public E get(long address) throws IOException { final long blockAddress = (address>>>shift)&padMask; final Option<BlockCacheEntry> blockOption = blockCache.get(blockAddress).get(); if (blockOption.isNone()) throw new IOException("illegal address "+address+" in file "+file); final BlockCacheEntry block = blockOption.some(); final int recordIndex = (int) (address&mask); if (recordIndex >= block.size()) { throw new IOException("there are only "+block.size()+" in block at address "+blockAddress+", seek request is for record number "+recordIndex); } return serializer.read(new MemoryDataInput(block.get(recordIndex))); }
@Override public E get(long address) throws IOException { final long blockAddress = (address>>>shift)&padMask; final Option<BlockCacheEntry> blockOption = blockCache.get(blockAddress).get(); if (blockOption.isNone()) throw new IOException("illegal address "+address+" in file "+file); final BlockCacheEntry block = blockOption.some(); final int recordIndex = (int) (address&mask); if (recordIndex >= block.size()) { throw new IOException("there are only "+block.size()+" in block at address "+blockAddress+", seek request is for record number "+recordIndex); } return serializer.read(new MemoryDataInput(block.get(recordIndex))); }