/** * Verify and return the block CRC. This method may only be called * after all of the block's bytes have been read. * @return The block CRC */ int checkCRC() { final int computedBlockCRC = crc.getCRC(); if (blockCRC != computedBlockCRC) { throw new DecompressionException("block CRC error"); } return computedBlockCRC; } }
/** * Reads a single bit from the {@link ByteBuf}. * @return {@code true} if the bit read was {@code 1}, otherwise {@code false} */ boolean readBoolean() { return readBits(1) != 0; }
public static ZlibEncoder newZlibEncoder(ZlibWrapper wrapper) { if (PlatformDependent.javaVersion() < 7 || noJdkZlibEncoder) { return new JZlibEncoder(wrapper); } else { return new JdkZlibEncoder(wrapper); } }
/** * Close current block and update {@link #streamCRC}. */ private void closeBlock(ByteBuf out) { final Bzip2BlockCompressor blockCompressor = this.blockCompressor; if (!blockCompressor.isEmpty()) { blockCompressor.close(out); final int blockCRC = blockCompressor.crc(); streamCRC = (streamCRC << 1 | streamCRC >>> 31) ^ blockCRC; } }
public static ZlibDecoder newZlibDecoder(ZlibWrapper wrapper) { if (PlatformDependent.javaVersion() < 7 || noJdkZlibDecoder) { return new JZlibDecoder(wrapper); } else { return new JdkZlibDecoder(wrapper, true); } }
static ByteBufChecksum wrapChecksum(Checksum checksum) { ObjectUtil.checkNotNull(checksum, "checksum"); if (checksum instanceof Adler32 && ADLER32_UPDATE_METHOD != null) { return new ReflectiveByteBufChecksum(checksum, ADLER32_UPDATE_METHOD); } if (checksum instanceof CRC32 && CRC32_UPDATE_METHOD != null) { return new ReflectiveByteBufChecksum(checksum, CRC32_UPDATE_METHOD); } return new SlowByteBufChecksum(checksum); }
/** * Update the CRC with a sequence of identical bytes. * @param value The value to update the CRC with * @param count The number of bytes */ public void updateCRC(final int value, int count) { while (count-- > 0) { updateCRC(value); } } }
private static void checkByte(byte actual, byte expect) { if (actual != expect) { throw new DecompressionException("Unexpected stream identifier contents. Mismatched snappy " + "protocol version?"); } }
/** * Writes an integer as 32 bits to the output {@link ByteBuf}. * @param value The integer to write */ void writeInt(ByteBuf out, final int value) { writeBits(out, 32, value); }
@Override public boolean process(byte value) throws Exception { return write(value); } };
/** * Gets the CRC of the completed block. Only valid after calling {@link #close(ByteBuf)}. * @return The block's CRC */ int crc() { return crc.getCRC(); } }
private static void ssBlockSwap(final int[] array1, final int first1, final int[] array2, final int first2, final int size) { int a, b; int i; for (i = size, a = first1, b = first2; 0 < i; --i, ++a, ++b) { swapElements(array1, a, array2, b); } }
@Override public void update(byte[] buffer, int offset, int length) { int end = offset + length; for (int i = offset; i < end; i++) { update(buffer[i]); } }
@Override public boolean process(byte value) throws Exception { update(value); return true; } };
public static ZlibEncoder newZlibEncoder(ZlibWrapper wrapper, int compressionLevel, int windowBits, int memLevel) { if (PlatformDependent.javaVersion() < 7 || noJdkZlibEncoder || windowBits != DEFAULT_JDK_WINDOW_SIZE || memLevel != DEFAULT_JDK_MEM_LEVEL) { return new JZlibEncoder(wrapper, compressionLevel, windowBits, memLevel); } else { return new JdkZlibEncoder(wrapper, compressionLevel); } }
/** * Reads 32 bits of input as an integer. * @return The integer read */ int readInt() { return readBits(32); }
public static ZlibEncoder newZlibEncoder(int compressionLevel, byte[] dictionary) { if (PlatformDependent.javaVersion() < 7 || noJdkZlibEncoder) { return new JZlibEncoder(compressionLevel, dictionary); } else { return new JdkZlibEncoder(compressionLevel, dictionary); } }
public static ZlibEncoder newZlibEncoder(int compressionLevel, int windowBits, int memLevel, byte[] dictionary) { if (PlatformDependent.javaVersion() < 7 || noJdkZlibEncoder || windowBits != DEFAULT_JDK_WINDOW_SIZE || memLevel != DEFAULT_JDK_MEM_LEVEL) { return new JZlibEncoder(compressionLevel, windowBits, memLevel, dictionary); } else { return new JdkZlibEncoder(compressionLevel, dictionary); } }