Refine search
public static byte[] decompress(byte[] value) throws DataFormatException { ByteArrayOutputStream bos = new ByteArrayOutputStream(value.length); Inflater decompressor = new Inflater(); try { decompressor.setInput(value); final byte[] buf = new byte[1024]; while (!decompressor.finished()) { int count = decompressor.inflate(buf); bos.write(buf, 0, count); } } finally { decompressor.end(); } return bos.toByteArray(); }
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; }
public static byte[] decompress(byte[] data) throws IOException, DataFormatException { long startTime = System.currentTimeMillis(); Inflater inflater = new Inflater(); inflater.setInput(data); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); byte[] buffer = new byte[1024]; while (!inflater.finished()) { int count = inflater.inflate(buffer); outputStream.write(buffer, 0, count); } outputStream.close(); byte[] output = outputStream.toByteArray(); logger.debug("Original: " + data.length + " bytes. " + "Decompressed: " + output.length + " bytes. Time: " + (System.currentTimeMillis() - startTime)); return output; } }
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); }
@Override public void close() throws IOException { if (writePointer > 0) { inflater.setInput(writeBuffer, 0, writePointer); try { int n = inflater.inflate(outputBuffer); while (n > 0) { output.write(outputBuffer, 0, n); n = inflater.inflate(outputBuffer); } output.close(); } catch (DataFormatException e) { IOException io = new IOException(e.getMessage()); io.initCause(e); throw io; } } }
/** * Decompress the byte array previously returned by compress */ public static byte[] decompress(byte[] value) throws DataFormatException { // Create an expandable byte array to hold the decompressed data ByteArrayOutputStream bos = new ByteArrayOutputStream(value.length); Inflater decompressor = new Inflater(); try { decompressor.setInput(value); final byte[] buf = new byte[1024]; while (!decompressor.finished()) { int count = decompressor.inflate(buf); bos.write(buf, 0, count); } } finally { decompressor.end(); } return bos.toByteArray(); }
inflater.setInput(userBuf, userBufOff, userBufLen); userBufOff += userBufLen; userBufLen = 0; numAvailBytes = inflater.inflate(b, off, len); } catch (DataFormatException dfe) { throw new IOException(dfe.getMessage()); if (inflater.finished()) { state = GzipStateLabel.TRAILER_CRC; int bytesRemaining = inflater.getRemaining();
protected void bufferAndDecompress() throws IOException { if (allDataRead) { eos = true; return; } readChunkHeader(); fillBuffer(compressedBuffer); inflater.setInput(compressedBuffer); try { inflater.inflate(buffer); } catch (final DataFormatException e) { throw new IOException(e); } inflater.reset(); bufferIndex = 0; final int moreDataByte = in.read(); if (moreDataByte < 1) { allDataRead = true; } else if (moreDataByte > 1) { throw new IOException("Expected indicator of whether or not more data was to come (-1, 0, or 1) but got " + moreDataByte); } }
@Override public void expand(byte[] in, int inPos, int inLen, byte[] out, int outPos, int outLen) { Inflater decompresser = new Inflater(); decompresser.setInput(in, inPos, inLen); decompresser.finished(); try { int len = decompresser.inflate(out, outPos, outLen); if (len != outLen) { throw new DataFormatException(len + " " + outLen); } } catch (DataFormatException e) { throw DbException.get(ErrorCode.COMPRESSION_ERROR, e); } decompresser.end(); }
final Inflater decompressor = new Inflater(); decompressor.setInput(buffer.array(), initialTargetPosition + 8, lengthOfCompressedContents); } else { byte[] compressedContents = new byte[lengthOfCompressedContents]; buffer.get(compressedContents); decompressor.setInput(compressedContents); decompressor.inflate(headerBuffer.array()); T histogram = decodeFromByteBuffer( headerBuffer, histogramClass, minBarForHighestTrackableValue, decompressor);
headerDone = readHeader(buf); inflater.setInput(buf.array(), buf.arrayOffset() + buf.position(), buf.remaining()); if (nextDone && inflater.needsInput() && !inflater.finished()) { throw UndertowLogger.ROOT_LOGGER.unexpectedEndOfCompressedInput(); } else if (nextDone && inflater.finished()) { done(); return -1; } else if (inflater.finished()) { int rem = inflater.getRemaining(); ByteBuffer buf = compressed.getBuffer(); int read = inflater.inflate(uncompressed.getBuffer().array(), uncompressed.getBuffer().arrayOffset(), uncompressed.getBuffer().limit()); uncompressed.getBuffer().limit(read); dataDeflated(uncompressed.getBuffer().array(), uncompressed.getBuffer().arrayOffset(), read);