@Override public synchronized boolean needsInput() { if (state == GzipStateLabel.DEFLATE_STREAM) { // most common case return inflater.needsInput(); } // see userBufLen comment at top of decompress(); currently no need to // verify userBufLen <= 0 return (state != GzipStateLabel.FINISHED); }
public void awaitReadable(final long time, final TimeUnit timeUnit) throws IOException { if (! inflater.needsInput()) { return; } next.awaitReadable(time, timeUnit); } }
public void awaitReadable() throws IOException { if (! inflater.needsInput()) { return; } next.awaitReadable(); }
public static DeflaterInflaterData uncompressBytes(byte[] output, int compressedDataLength) throws DataFormatException { Inflater decompresser = new Inflater(); decompresser.setInput(output, 0, compressedDataLength); byte[] buffer = new byte[512]; byte[] result = new byte[0]; int bytesRead; while (!decompresser.needsInput()) { bytesRead = decompresser.inflate(buffer); byte[] newResult = new byte[result.length + bytesRead]; System.arraycopy(result, 0, newResult, 0, result.length); System.arraycopy(buffer, 0, newResult, result.length, bytesRead); result = newResult; } decompresser.end(); return new DeflaterInflaterData(result.length, result); }
/** * Provide a more InputStream compatible version. A return value of 1 means that it is likely to read one * byte without blocking, 0 means that the system is known to block for more input. * * @return 0 if no data is available, 1 otherwise * @throws IOException */ @Override public int available() throws IOException { /* * aSmack related remark (where KXmlParser is used): * This is one of the funny code blocks. InflaterInputStream.available violates the contract of * InputStream.available, which breaks kXML2. * * I'm not sure who's to blame, oracle/sun for a broken api or the google guys for mixing a sun bug with * a xml reader that can't handle it.... * * Anyway, this simple if breaks suns distorted reality, but helps to use the api as intended. */ if (inf.needsInput()) { return 0; } return super.available(); } };
while (inflater.needsInput() == false) { byte[] bytesDecompressedBuffer = new byte[bufferSizeInBytes];
/** * 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; }
if (inflater.finished()) { break; } else if (inflater.needsInput()) {
private PooledByteBuffer decompress(WebSocketChannel channel, PooledByteBuffer pooled) throws IOException { ByteBuffer buffer = pooled.getBuffer(); while (!decompress.needsInput() && !decompress.finished()) { if (!buffer.hasRemaining()) { pooled = largerBuffer(pooled, channel, buffer.capacity() * 2); buffer = pooled.getBuffer(); } int n; try { n = decompress.inflate(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); } catch (DataFormatException e) { WebSocketLogger.EXTENSION_LOGGER.debug(e.getMessage(), e); throw WebSocketMessages.MESSAGES.badCompressedPayload(e); } buffer.position(buffer.position() + n); } return pooled; }
/** * Potentially reads more bytes to fill the inflater's buffer and * reads from it. */ private int readFromInflater(final byte[] buffer, final int offset, final int length) throws IOException { int read = 0; do { if (inf.needsInput()) { final int l = fill(); if (l > 0) { current.bytesReadFromStream += buf.limit(); } else if (l == -1) { return -1; } else { break; } } try { read = inf.inflate(buffer, offset, length); } catch (final DataFormatException e) { throw (IOException) new ZipException(e.getMessage()).initCause(e); } } while (read == 0 && inf.needsInput()); return read; }
if (!zlib.needsInput())
return true; if (inflater.needsDictionary() || inflater.needsInput()) { return false;
if (inf.needsInput()) { fill();
try { boolean readFooter = false; while (!inflater.needsInput()) { byte[] outArray = decompressed.array(); int writerIndex = decompressed.writerIndex();
return toRead; if (inf.needsInput()) { fill(); if (len > 0) {
/** * Uses streaming decompression to inflate {@code deflated}. The input must * either be finished or have a trailing sync flush. */ private Buffer inflate(Buffer deflated) throws IOException { InputStream deflatedIn = deflated.inputStream(); Inflater inflater = new Inflater(); InputStream inflatedIn = new InflaterInputStream(deflatedIn, inflater); Buffer result = new Buffer(); byte[] buffer = new byte[8192]; while (!inflater.needsInput() || deflated.size() > 0 || deflatedIn.available() > 0) { int count = inflatedIn.read(buffer, 0, buffer.length); if (count != -1) { result.write(buffer, 0, count); } } return result; } }
try { boolean readFooter = false; while (!inflater.needsInput()) { byte[] outArray = decompressed.array(); int writerIndex = decompressed.writerIndex();
throw new CorruptIndexException("Invalid decoder state: needsInput=" + decompressor.needsInput() + ", needsDict=" + decompressor.needsDictionary(), in);
/** * Inflates up to {@code byteCount} bytes from the current input and stores them in * {@code buf} starting at {@code offset}. * * @throws DataFormatException * if the underlying stream is corrupted or was not compressed * using a {@code Deflater}. * @return the number of bytes inflated. */ public synchronized int inflate(byte[] buf, int offset, int byteCount) throws DataFormatException { Arrays.checkOffsetAndCount(buf.length, offset, byteCount); checkOpen(); if (needsInput()) { return 0; } boolean neededDict = needsDictionary; needsDictionary = false; int result = inflateImpl(buf, offset, byteCount, streamHandle); if (needsDictionary && neededDict) { throw new DataFormatException("Needs dictionary"); } return result; }
if (nextDone && inflater.needsInput() && !inflater.finished()) { throw UndertowLogger.ROOT_LOGGER.unexpectedEndOfCompressedInput(); } else if (nextDone && inflater.finished()) { uncompressed.getBuffer().limit(read); dataDeflated(uncompressed.getBuffer().array(), uncompressed.getBuffer().arrayOffset(), read); if (inflater.needsInput()) { compressed.close(); compressed = null;