/** When the inflater has processed compressed data, remove it from the buffer. */ private void releaseInflatedBytes() throws IOException { if (bufferBytesHeldByInflater == 0) return; int toRelease = bufferBytesHeldByInflater - inflater.getRemaining(); bufferBytesHeldByInflater -= toRelease; source.skip(toRelease); }
@Override protected void fill() throws IOException { super.fill(); compressedCount += inf.getRemaining(); }
@Override void decode(ByteBufAllocator alloc, ByteBuf headerBlock, SpdyHeadersFrame frame) throws Exception { int len = setInput(headerBlock); int numBytes; do { numBytes = decompress(alloc, frame); } while (numBytes > 0); // z_stream has an internal 64-bit hold buffer // it is always capable of consuming the entire input if (decompressor.getRemaining() != 0) { // we reached the end of the deflate stream throw INVALID_HEADER_BLOCK; } headerBlock.skipBytes(len); }
/** * Refills the inflater with compressed data if it needs input. (And only if * it needs input). Returns true if the inflater required input but the source * was exhausted. */ public boolean refill() throws IOException { if (!inflater.needsInput()) return false; releaseInflatedBytes(); if (inflater.getRemaining() != 0) throw new IllegalStateException("?"); // TODO: possible? // If there are compressed bytes in the source, assign them to the inflater. if (source.exhausted()) return true; // Assign buffer bytes to the inflater. Segment head = source.buffer().head; bufferBytesHeldByInflater = head.limit - head.pos; inflater.setInput(head.data, head.pos, bufferBytesHeldByInflater); return false; }
private void verifyCrc() throws IOException { // Get non-compressed bytes read by fill int size = inf.getRemaining(); final int trailerSize = 8; // crc (4 bytes) + total out (4 bytes) byte[] b = new byte[trailerSize]; int copySize = (size > trailerSize) ? trailerSize : size; System.arraycopy(buf, len - size, b, 0, copySize); readFully(b, copySize, trailerSize - copySize); if (Memory.peekInt(b, 0, ByteOrder.LITTLE_ENDIAN) != (int) crc.getValue()) { throw new IOException("CRC mismatch"); } if (Memory.peekInt(b, 4, ByteOrder.LITTLE_ENDIAN) != inf.getTotalOut()) { throw new IOException("Size mismatch"); } }
ByteBuf decompressed = ctx.alloc().heapBuffer(inflater.getRemaining() << 1); try { boolean readFooter = false; decompressed.ensureWritable(inflater.getRemaining() << 1); in.skipBytes(readableBytes - inflater.getRemaining());
@Override void decode(ChannelBuffer headerBlock, SpdyHeadersFrame frame) throws Exception { if (headerBlock == null) { throw new NullPointerException("headerBlock"); } if (frame == null) { throw new NullPointerException("frame"); } int len = setInput(headerBlock); int numBytes; do { numBytes = decompress(frame); } while (numBytes > 0); // z_stream has an internal 64-bit hold buffer // it is always capable of consuming the entire input if (decompressor.getRemaining() != 0) { // we reached the end of the deflate stream throw INVALID_HEADER_BLOCK; } headerBlock.skipBytes(len); }
int bytesRemaining = inflater.getRemaining(); assert (bytesRemaining >= 0) : "logic error: Inflater finished; byte-count is inconsistent";
ByteBuf decompressed = ctx.alloc().heapBuffer(inflater.getRemaining() << 1); try { boolean readFooter = false; decompressed.ensureWritable(inflater.getRemaining() << 1); in.skipBytes(readableBytes - inflater.getRemaining());
final int skipAmount = bufUsed - inf.getRemaining(); if (IOUtils.skip(in, skipAmount) != skipAmount) { throw new IOException();
ByteBuf decompressed = ctx.alloc().heapBuffer(inflater.getRemaining() << 1); try { boolean readFooter = false; decompressed.ensureWritable(inflater.getRemaining() << 1); in.skipBytes(readableBytes - inflater.getRemaining());
return -1; } else if (inflater.finished()) { int rem = inflater.getRemaining(); ByteBuffer buf = compressed.getBuffer(); buf.position(buf.limit() - rem);
/** * Inflater statistic */ public long getRemaining() { try { return inf.getRemaining(); } catch (RuntimeException e) { // possible NPE in some implementations return 0; } }
/** * Moved from i2ptunnel HTTPResponseOutputStream.InternalGZIPInputStream * @since 0.8.9 */ public long getRemaining() { try { return inf.getRemaining(); } catch (RuntimeException e) { // possible NPE in some implementations return 0; } }
if ( inflater.getRemaining() != 0 )
@Override public void close() throws IOException { // We need to read here to enter the loop above and pump the // trailing checksum into the Inflater. It should return -1 as the // caller was supposed to consume all content. // if (read(skipBuffer) != -1 || actualSize != expectedSize) { throw new CorruptObjectException(MessageFormat.format(JGitText .get().packfileCorruptionDetected, JGitText.get().wrongDecompressedLength)); } int used = bAvail - inf.getRemaining(); if (0 < used) { onObjectData(src, buf, p, used); use(used); } inf.reset(); } }
static void checkValidEndOfStream(InputStream in, Inflater inf, AnyObjectId id, final byte[] buf) throws IOException, CorruptObjectException { for (;;) { int r; try { r = inf.inflate(buf); } catch (DataFormatException e) { throw new CorruptObjectException(id, JGitText.get().corruptObjectBadStream); } if (r != 0) throw new CorruptObjectException(id, JGitText.get().corruptObjectIncorrectLength); if (inf.finished()) { if (inf.getRemaining() != 0 || in.read() != -1) throw new CorruptObjectException(id, JGitText.get().corruptObjectBadStream); break; } if (!inf.needsInput()) throw new CorruptObjectException(id, JGitText.get().corruptObjectBadStream); r = in.read(buf); if (r <= 0) throw new CorruptObjectException(id, JGitText.get().corruptObjectBadStream); inf.setInput(buf, 0, r); } }
@Override public boolean isDone() { return (inflater.getRemaining() <= 0) || inflater.finished(); }
@Override public boolean isDone() { return (inflater.getRemaining() <= 0) || inflater.finished(); }
private void pushBackUnconsumedBytes() { int remaining = inf.getRemaining(); BufferObjectDataInput bufferedInput = (BufferObjectDataInput) in; int position = bufferedInput.position(); int rewindBack = max(0, remaining - ExtendedGZipInputStream.GZIP_TRAILER_SIZE); int newPosition = position - rewindBack; bufferedInput.position(newPosition); }