private int readOneByte() throws IOException { final int b = in.read(); if (b != -1) { count(1); return b & 0xFF; } return -1; }
private int readOnce(byte[] b, int off, int len) throws IOException { if (inUncompressed) { int cnt = currentBlock.read(b, off, len); count(cnt); return cnt; } BlockLZ4CompressorInputStream l = (BlockLZ4CompressorInputStream) currentBlock; long before = l.getBytesRead(); int cnt = currentBlock.read(b, off, len); count(l.getBytesRead() - before); return cnt; }
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."); } }
/** * 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; }
private boolean readSignature(boolean firstFrame) throws IOException { String garbageMessage = firstFrame ? "Not a LZ4 frame stream" : "LZ4 frame stream followed by garbage"; final byte[] b = new byte[4]; int read = IOUtils.readFully(in, b); count(read); if (0 == read && !firstFrame) { // good LZ4 frame and nothing after it endReached = true; return false; } if (4 != read) { throw new IOException(garbageMessage); } read = skipSkippableFrame(b); if (0 == read && !firstFrame) { // good LZ4 frame with only some skippable frames after it endReached = true; return false; } if (4 != read || !matches(b, 4)) { throw new IOException(garbageMessage); } return true; }
byte[] contentSize = new byte[8]; int skipped = IOUtils.readFully(in, contentSize); count(skipped); if (8 != skipped) { throw new IOException("Premature end of stream while reading content size");
private int readOneByte() throws IOException { final int b = in.read(); if (b != -1) { count(1); return b & 0xFF; } return -1; }
private int readOnce(byte[] b, int off, int len) throws IOException { if (inUncompressed) { int cnt = currentBlock.read(b, off, len); count(cnt); return cnt; } BlockLZ4CompressorInputStream l = (BlockLZ4CompressorInputStream) currentBlock; long before = l.getBytesRead(); int cnt = currentBlock.read(b, off, len); count(l.getBytesRead() - before); return cnt; }
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."); } }
/** * 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; }
private boolean readSignature(boolean firstFrame) throws IOException { String garbageMessage = firstFrame ? "Not a LZ4 frame stream" : "LZ4 frame stream followed by garbage"; final byte[] b = new byte[4]; int read = IOUtils.readFully(in, b); count(read); if (0 == read && !firstFrame) { // good LZ4 frame and nothing after it endReached = true; return false; } if (4 != read) { throw new IOException(garbageMessage); } read = skipSkippableFrame(b); if (0 == read && !firstFrame) { // good LZ4 frame with only some skippable frames after it endReached = true; return false; } if (4 != read || !matches(b, 4)) { throw new IOException(garbageMessage); } return true; }
byte[] contentSize = new byte[8]; int skipped = IOUtils.readFully(in, contentSize); count(skipped); if (8 != skipped) { throw new IOException("Premature end of stream while reading content size");