/** * Read 8-byte integer from buffer. * * @param buffer * @param offset * @return the 8-byte entry as a long */ public static final long convert64(final byte[] buffer, final int offset) { return ByteUtils.fromLittleEndian(buffer, offset, 8); }
/** * Reads the given byte array as a little endian long. * @param bytes the byte array to convert * @return the number read */ public static long fromLittleEndian(byte[] bytes) { return fromLittleEndian(bytes, 0, bytes.length); }
/** * Read 4-byte integer from buffer. * * @param buffer * @param offset * @return the 4-byte entry as an int */ public static final int convert32(final byte[] buffer, final int offset) { return (int) ByteUtils.fromLittleEndian(buffer, offset, 4); }
/** * Read 2-byte integer from buffer. * * @param buffer * @param offset * @return the 2-byte entry as an int */ public static final int convert16(final byte[] buffer, final int offset) { return (int) ByteUtils.fromLittleEndian(buffer, offset, 2); }
/** * Helper method to get the value as a Java long from four bytes starting at given array offset * @param bytes the array of bytes * @param offset the offset to start * @return the corresponding Java long value */ public static long getValue(final byte[] bytes, final int offset) { return ByteUtils.fromLittleEndian(bytes, offset, 4); }
/** * Helper method to get the value as a java int from two bytes starting at given array offset * @param bytes the array of bytes * @param offset the offset to start * @return the corresponding java int value */ public static int getValue(final byte[] bytes, final int offset) { return (int) ByteUtils.fromLittleEndian(bytes, offset, 2); }
private int readSize() throws IOException { return (int) ByteUtils.fromLittleEndian(supplier, 3); }
private int getDictionarySize(final Coder coder) throws IllegalArgumentException { return (int) ByteUtils.fromLittleEndian(coder.properties, 1, 4); }
private static int getInt(byte[] buffer, int idx) { return (int) (fromLittleEndian(buffer, idx, 4) & 0xffffffffL); }
private int readLiteralLength(final int b) throws IOException { int length; switch (b >> 2) { case 60: length = readOneByte(); if (length == -1) { throw new IOException("Premature end of stream reading literal length"); } break; case 61: length = (int) ByteUtils.fromLittleEndian(supplier, 2); break; case 62: length = (int) ByteUtils.fromLittleEndian(supplier, 3); break; case 63: length = (int) ByteUtils.fromLittleEndian(supplier, 4); break; default: length = b >> 2; break; } return length + 1; }
private long readCrc() throws IOException { final byte[] b = new byte[4]; final int read = IOUtils.readFully(in, b); count(read); if (read != 4) { throw new IOException("premature end of stream"); } return ByteUtils.fromLittleEndian(b); }
private void verifyChecksum(XXHash32 hash, String kind) throws IOException { byte[] checksum = new byte[4]; int read = IOUtils.readFully(in, checksum); count(read); if (4 != read) { throw new IOException("Premature end of stream while reading " + kind + " checksum"); } long expectedHash = hash.getValue(); if (expectedHash != ByteUtils.fromLittleEndian(checksum)) { throw new IOException(kind + " checksum mismatch."); } }
/** * @return false if there is no more back-reference - this means this is the * last block of the stream. */ private boolean initializeBackReference() throws IOException { int backReferenceOffset = 0; try { backReferenceOffset = (int) ByteUtils.fromLittleEndian(supplier, 2); } catch (IOException ex) { if (nextBackReferenceSize == 0) { // the last block has no back-reference return false; } throw ex; } long backReferenceSize = nextBackReferenceSize; if (nextBackReferenceSize == BACK_REFERENCE_SIZE_MASK) { backReferenceSize += readSizeBytes(); } // minimal match length 4 is encoded as 0 startBackReference(backReferenceOffset, backReferenceSize + 4); state = State.IN_BACK_REFERENCE; return true; }
final long crcStored = ByteUtils.fromLittleEndian(inData, 4); final long isize = ByteUtils.fromLittleEndian(inData, 4);
parameters.setModificationTime(ByteUtils.fromLittleEndian(inData, 4) * 1000); switch (inData.readUnsignedByte()) { // extra flags case 2:
/** * Skips over the contents of a skippable frame as well as * skippable frames following it. * * <p>It then tries to read four more bytes which are supposed to * hold an LZ4 signature and returns the number of bytes read * while storing the bytes in the given array.</p> */ private int skipSkippableFrame(byte[] b) throws IOException { int read = 4; while (read == 4 && isSkippableFrameSignature(b)) { long len = ByteUtils.fromLittleEndian(supplier, 4); long skipped = IOUtils.skip(in, len); count(skipped); if (len != skipped) { throw new IOException("Premature end of stream while skipping frame"); } read = IOUtils.readFully(in, b); count(read); } return read; }
uncompressedBytesRemaining -= length; offset = (int) ByteUtils.fromLittleEndian(supplier, 2); uncompressedBytesRemaining -= length; offset = (int) ByteUtils.fromLittleEndian(supplier, 4) & 0x7fffffff;
private void nextBlock() throws IOException { maybeFinishCurrentBlock(); long len = ByteUtils.fromLittleEndian(supplier, 4); boolean uncompressed = (len & UNCOMPRESSED_FLAG_MASK) != 0; int realLen = (int) (len & (~UNCOMPRESSED_FLAG_MASK)); if (realLen == 0) { verifyContentChecksum(); if (!decompressConcatenated) { endReached = true; } else { init(false); } return; } InputStream capped = new BoundedInputStream(in, realLen); if (expectBlockChecksum) { capped = new ChecksumCalculatingInputStream(blockHash, capped); } if (uncompressed) { inUncompressed = true; currentBlock = capped; } else { inUncompressed = false; BlockLZ4CompressorInputStream s = new BlockLZ4CompressorInputStream(capped); if (expectBlockDependency) { s.prefill(blockDependencyBuffer); } currentBlock = s; } }
/** * Read 8-byte integer from buffer. * * @param buffer * @param offset * @return the 8-byte entry as a long */ public static final long convert64(final byte[] buffer, final int offset) { return ByteUtils.fromLittleEndian(buffer, offset, 8); }
private void verifyChecksum(XXHash32 hash, String kind) throws IOException { byte[] checksum = new byte[4]; int read = IOUtils.readFully(in, checksum); count(read); if (4 != read) { throw new IOException("Premature end of stream while reading " + kind + " checksum"); } long expectedHash = hash.getValue(); if (expectedHash != ByteUtils.fromLittleEndian(checksum)) { throw new IOException(kind + " checksum mismatch."); } }