/** * Compress the raw data, as well as manage sizing of the {@code outputBuffer}; if the buffer is not big enough, * deallocate current, and allocate a large enough buffer. * Write the two header lengths (plain text length, compressed length) to the beginning of the buffer as we want those * values encapsulated in the encrypted block, as well. * * @return the byte buffer that was actaully written to; it may be the {@code outputBuffer} if it had enough capacity, * or it may be a new, larger instance. Callers should capture the return buffer (if calling multiple times). */ public static ByteBuffer compress(ByteBuffer inputBuffer, ByteBuffer outputBuffer, boolean allowBufferResize, ICompressor compressor) throws IOException { int inputLength = inputBuffer.remaining(); final int compressedLength = compressor.initialCompressedBufferLength(inputLength); outputBuffer = ByteBufferUtil.ensureCapacity(outputBuffer, compressedLength + COMPRESSED_BLOCK_HEADER_SIZE, allowBufferResize); outputBuffer.putInt(inputLength); compressor.compress(inputBuffer, outputBuffer); outputBuffer.flip(); return outputBuffer; }
public static int uncompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, ICompressor compressor) throws IOException { int outputLength = readInt(input, inputOffset); inputOffset += 4; inputLength -= 4; if (output.length - outputOffset < outputLength) { String msg = String.format("buffer to uncompress into is not large enough; buf size = %d, buf offset = %d, target size = %s", output.length, outputOffset, outputLength); throw new IllegalStateException(msg); } return compressor.uncompress(input, inputOffset, inputLength, output, outputOffset); }
protected void writeBuffer(ByteBuffer bb) throws IOException { int originalSize = bb.remaining(); int estimatedSize = compressor.initialCompressedBufferLength(originalSize) + METADATA_SIZE; if (compressionBuffer == null || compressionBuffer.capacity() < estimatedSize) { compressionBuffer = compressor.preferredBufferType().allocate(estimatedSize); } compressionBuffer.clear(); compressionBuffer.position(METADATA_SIZE); compressor.compress(bb, compressionBuffer); int compressedSize = compressionBuffer.position() - METADATA_SIZE; compressionBuffer.rewind(); compressionBuffer.putInt(originalSize); compressionBuffer.putInt(compressedSize); compressionBuffer.rewind(); compressionBuffer.limit(compressedSize + METADATA_SIZE); super.writeBuffer(compressionBuffer); }
compressedBuffer = BufferPool.get(bufferSize, compressor.preferredBufferType()); buffer = BufferPool.get(bufferSize, compressor.preferredBufferType()); try compressor.uncompress(compressedBuffer, buffer); buffer.flip();
.bufferType(option.bufferType()) .bufferSize(parameters.chunkLength()) .bufferType(parameters.getSstableCompressor().preferredBufferType()) .finishOnClose(option.finishOnClose()) .build()); compressed = compressor.preferredBufferType().allocate(compressor.initialCompressedBufferLength(buffer.capacity()));
public CompressedChecksummedDataInput(ChannelProxy channel, ICompressor compressor, long filePosition) { super(channel, compressor.preferredBufferType()); this.compressor = compressor; this.sourcePosition = this.filePosition = filePosition; }
protected CompressedRandomAccessReader(String dataFilePath, CompressionMetadata metadata, PoolingSegmentedFile owner) throws FileNotFoundException { super(new File(dataFilePath), metadata.chunkLength(), metadata.compressedFileLength, owner); this.metadata = metadata; checksum = metadata.hasPostCompressionAdlerChecksums ? new Adler32() : new CRC32(); compressed = ByteBuffer.wrap(new byte[metadata.compressor().initialCompressedBufferLength(metadata.chunkLength())]); }
compressor.compress(buffer, compressed);
if (!compressor.supportedOptions().contains(provided)) throw new ConfigurationException("Unknown compression options " + provided); return compressor;
compressedBuffer = BufferPool.get(bufferSize, compressor.preferredBufferType()); buffer = BufferPool.get(bufferSize, compressor.preferredBufferType()); try compressor.uncompress(compressedBuffer, buffer); buffer.flip();
.bufferType(option.bufferType()) .bufferSize(parameters.chunkLength()) .bufferType(parameters.getSstableCompressor().preferredBufferType()) .finishOnClose(option.finishOnClose()) .build()); compressed = compressor.preferredBufferType().allocate(compressor.initialCompressedBufferLength(buffer.capacity()));
public CompressedChecksummedDataInput(ChannelProxy channel, ICompressor compressor, long filePosition) { super(channel, compressor.preferredBufferType()); this.compressor = compressor; this.sourcePosition = this.filePosition = filePosition; }
public ByteBuffer allocateBuffer() { return allocateBuffer(metadata.compressor().initialCompressedBufferLength(metadata.chunkLength())); }
compressor.compress(buffer, compressed);
if (!compressor.supportedOptions().contains(provided)) throw new ConfigurationException("Unknown compression options " + provided); return compressor;
/** * Compress the raw data, as well as manage sizing of the {@code outputBuffer}; if the buffer is not big enough, * deallocate current, and allocate a large enough buffer. * Write the two header lengths (plain text length, compressed length) to the beginning of the buffer as we want those * values encapsulated in the encrypted block, as well. * * @return the byte buffer that was actaully written to; it may be the {@code outputBuffer} if it had enough capacity, * or it may be a new, larger instance. Callers should capture the return buffer (if calling multiple times). */ public static ByteBuffer compress(ByteBuffer inputBuffer, ByteBuffer outputBuffer, boolean allowBufferResize, ICompressor compressor) throws IOException { int inputLength = inputBuffer.remaining(); final int compressedLength = compressor.initialCompressedBufferLength(inputLength); outputBuffer = ByteBufferUtil.ensureCapacity(outputBuffer, compressedLength + COMPRESSED_BLOCK_HEADER_SIZE, allowBufferResize); outputBuffer.putInt(inputLength); compressor.compress(inputBuffer, outputBuffer); outputBuffer.flip(); return outputBuffer; }
protected void writeBuffer(ByteBuffer bb) throws IOException { int originalSize = bb.remaining(); int estimatedSize = compressor.initialCompressedBufferLength(originalSize) + METADATA_SIZE; if (compressionBuffer == null || compressionBuffer.capacity() < estimatedSize) { compressionBuffer = compressor.preferredBufferType().allocate(estimatedSize); } compressionBuffer.clear(); compressionBuffer.position(METADATA_SIZE); compressor.compress(bb, compressionBuffer); int compressedSize = compressionBuffer.position() - METADATA_SIZE; compressionBuffer.rewind(); compressionBuffer.putInt(originalSize); compressionBuffer.putInt(compressedSize); compressionBuffer.rewind(); compressionBuffer.limit(compressedSize + METADATA_SIZE); super.writeBuffer(compressionBuffer); }
public static int uncompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, ICompressor compressor) throws IOException { int outputLength = readInt(input, inputOffset); inputOffset += 4; inputLength -= 4; if (output.length - outputOffset < outputLength) { String msg = String.format("buffer to uncompress into is not large enough; buf size = %d, buf offset = %d, target size = %s", output.length, outputOffset, outputLength); throw new IllegalStateException(msg); } return compressor.uncompress(input, inputOffset, inputLength, output, outputOffset); }
compressedBuffer = BufferPool.get(bufferSize, compressor.preferredBufferType()); buffer = BufferPool.get(bufferSize, compressor.preferredBufferType()); try compressor.uncompress(compressedBuffer, buffer); buffer.flip();
.bufferType(option.bufferType()) .bufferSize(parameters.chunkLength()) .bufferType(parameters.getSstableCompressor().preferredBufferType()) .finishOnClose(option.finishOnClose()) .build()); compressed = compressor.preferredBufferType().allocate(compressor.initialCompressedBufferLength(buffer.capacity()));