Java Code Examples for net.jpountz.util.SafeUtils#readIntLE()
The following examples show how to use
net.jpountz.util.SafeUtils#readIntLE() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Lz4BlockDecompressor.java From flink with Apache License 2.0 | 5 votes |
@Override public int decompress(byte[] src, int srcOff, int srcLen, byte[] dst, int dstOff) throws InsufficientBufferException, DataCorruptionException { final int compressedLen = SafeUtils.readIntLE(src, srcOff); final int originalLen = SafeUtils.readIntLE(src, srcOff + 4); validateLength(compressedLen, originalLen); if (dst.length - dstOff < originalLen) { throw new InsufficientBufferException("Buffer length too small"); } if (src.length - srcOff - HEADER_LENGTH < compressedLen) { throw new DataCorruptionException("Source data is not integral for decompression."); } try { final int compressedLen2 = decompressor.decompress( src, srcOff + HEADER_LENGTH, dst, dstOff, originalLen ); if (compressedLen != compressedLen2) { throw new DataCorruptionException("Input is corrupted"); } } catch (LZ4Exception e) { throw new DataCorruptionException("Input is corrupted", e); } return originalLen; }
Example 2
Source File: ChannelLZ4Decompressor.java From datakernel with Apache License 2.0 | 5 votes |
private static void readHeader(Header header, byte[] buf, int off) throws ParseException { for (int i = 0; i < MAGIC_LENGTH; ++i) { if (buf[off + i] != MAGIC[i]) { throw STREAM_IS_CORRUPTED; } } int token = buf[off + MAGIC_LENGTH] & 0xFF; header.compressionMethod = token & 0xF0; int compressionLevel = COMPRESSION_LEVEL_BASE + (token & 0x0F); if (header.compressionMethod != COMPRESSION_METHOD_RAW && header.compressionMethod != COMPRESSION_METHOD_LZ4) { throw STREAM_IS_CORRUPTED; } header.compressedLen = SafeUtils.readIntLE(buf, off + MAGIC_LENGTH + 1); header.originalLen = SafeUtils.readIntLE(buf, off + MAGIC_LENGTH + 5); header.check = SafeUtils.readIntLE(buf, off + MAGIC_LENGTH + 9); if (header.originalLen > 1 << compressionLevel || (header.originalLen < 0 || header.compressedLen < 0) || (header.originalLen == 0 && header.compressedLen != 0) || (header.originalLen != 0 && header.compressedLen == 0) || (header.compressionMethod == COMPRESSION_METHOD_RAW && header.originalLen != header.compressedLen)) { throw STREAM_IS_CORRUPTED; } if (header.originalLen == 0) { if (header.check != 0) { throw STREAM_IS_CORRUPTED; } header.finished = true; } }
Example 3
Source File: Lz4BlockDecompressor.java From flink with Apache License 2.0 | 5 votes |
@Override public int decompress(byte[] src, int srcOff, int srcLen, byte[] dst, int dstOff) throws InsufficientBufferException, DataCorruptionException { final int compressedLen = SafeUtils.readIntLE(src, srcOff); final int originalLen = SafeUtils.readIntLE(src, srcOff + 4); validateLength(compressedLen, originalLen); if (dst.length - dstOff < originalLen) { throw new InsufficientBufferException("Buffer length too small"); } if (src.length - srcOff - HEADER_LENGTH < compressedLen) { throw new DataCorruptionException("Source data is not integral for decompression."); } try { final int compressedLen2 = decompressor.decompress( src, srcOff + HEADER_LENGTH, dst, dstOff, originalLen ); if (compressedLen != compressedLen2) { throw new DataCorruptionException("Input is corrupted"); } } catch (LZ4Exception e) { throw new DataCorruptionException("Input is corrupted", e); } return originalLen; }