private void writeNextChunk(byte[] input, int inputOffset, int inputLength) throws IOException { int compressedSize = compressor.compress(input, inputOffset, inputLength, outputBuffer, 0, outputBuffer.length); writeBigEndianInt(inputLength); writeBigEndianInt(compressedSize); out.write(outputBuffer, 0, compressedSize); this.inputOffset = 0; }
private void writeNextChunk(byte[] input, int inputOffset, int inputLength) throws IOException { int compressedSize = compressor.compress(input, inputOffset, inputLength, outputBuffer, 0, outputBuffer.length); writeBigEndianInt(inputLength); writeBigEndianInt(compressedSize); out.write(outputBuffer, 0, compressedSize); this.inputOffset = 0; }
public static byte[] blockCompress(byte[] data) { SnappyCompressor compressor = new SnappyCompressor(); byte[] compressedOut = new byte[compressor.maxCompressedLength(data.length)]; int compressedSize = compressor.compress(data, 0, data.length, compressedOut, 0, compressedOut.length); byte[] trimmedBuffer = Arrays.copyOf(compressedOut, compressedSize); return trimmedBuffer; }
/** * {@link Crc32C#maskedCrc32c(byte[], int, int) Calculates} the crc, compresses * the data, determines if the compression ratio is acceptable and calls * {@link #writeBlock(OutputStream, byte[], int, int, boolean, int)} to * actually write the frame. * * @param input The byte[] containing the raw data to be compressed. * @param offset The offset into <i>input</i> where the data starts. * @param length The amount of data in <i>input</i>. */ private void writeCompressed(byte[] input, int offset, int length) throws IOException { // crc is based on the user supplied input data int crc32c = writeChecksums ? Crc32C.maskedCrc32c(input, offset, length) : 0; int compressed = compressor.compress(input, offset, length, outputBuffer, 0, outputBuffer.length); // only use the compressed data if compression ratio is <= the minCompressionRatio if (((double) compressed / (double) length) <= minCompressionRatio) { writeBlock(out, outputBuffer, 0, compressed, true, crc32c); } else { // otherwise use the uncompressed data. writeBlock(out, input, offset, length, false, crc32c); } }
/** * {@link Crc32C#maskedCrc32c(byte[], int, int) Calculates} the crc, compresses * the data, determines if the compression ratio is acceptable and calls * {@link #writeBlock(OutputStream, byte[], int, int, boolean, int)} to * actually write the frame. * * @param input The byte[] containing the raw data to be compressed. * @param offset The offset into <i>input</i> where the data starts. * @param length The amount of data in <i>input</i>. */ private void writeCompressed(byte[] input, int offset, int length) throws IOException { // crc is based on the user supplied input data int crc32c = writeChecksums ? Crc32C.maskedCrc32c(input, offset, length) : 0; int compressed = compressor.compress(input, offset, length, outputBuffer, 0, outputBuffer.length); // only use the compressed data if compression ratio is <= the minCompressionRatio if (((double) compressed / (double) length) <= minCompressionRatio) { writeBlock(out, outputBuffer, 0, compressed, true, crc32c); } else { // otherwise use the uncompressed data. writeBlock(out, input, offset, length, false, crc32c); } }