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; }
n = inflater.inflate(buf, offset, len); if (n == 0) { if (inflater.finished()) { break; } else if (inflater.needsInput()) { throw new DataFormatException("Input is over while inflater still expecting data"); } else { throw new DataFormatException("Inflater is neither finished nor needing input.");
byte[] returnValues = null; Inflater inflater = new Inflater(); inflater.setInput while (inflater.needsInput() == false) { byte[] bytesDecompressedBuffer = new byte[bufferSizeInBytes]; dfe.printStackTrace();
private byte[] tryDecompress(byte[] in, final int len) throws IOException { if (len > 200000) { throw new IOException("OutOfMemory"); } // Decompress the bytes final byte[] tmp = new byte[len]; final Inflater decompresser = new Inflater(true); decompresser.setInput(in); try { final int resultLength = decompresser.inflate(tmp); if (decompresser.finished() == false) { return null; } decompresser.end(); final byte[] result = copyArray(tmp, resultLength); return result; } catch (DataFormatException e) { // e.printStackTrace(); throw new IOException(e.toString()); } }
@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(); }
Inflater inflater = acquireInflater(); try { inflater.setInput(gzippedDataBytes, headerSize, compressedDataSize); CRC32 crc = new CRC32(); int offset = 0; while (true) numDecompressedBytes = inflater.inflate(result, offset, result.length - offset); } catch (DataFormatException e) { String s = e.getMessage(); throw new ZipException(s != null ? s : "Invalid ZLIB data format"); crc.update(result, offset, numDecompressedBytes); offset += numDecompressedBytes; if ( inflater.finished() || inflater.needsDictionary() ) if ( checksum != (int) crc.getValue() || numUncompressedBytes != offset )
while ((count = _inflater.inflate(buf, offset, len)) == 0) { if (_inflater.finished() || _inflater.needsDictionary()) { _readTrailer(); _state = State.GZIP_COMPLETE; _crc.update(buf, offset, count); return count; } catch (DataFormatException e) { String s = e.getMessage(); throw new GZIPException(s != null ? s : "Invalid ZLIB data format");
Inflater inflater = new Inflater(false); inflater.setInput(data); while (inflater.getRemaining() > 0 && offset < uncomp.length) { offset += inflater.inflate(uncomp, offset, uncomp.length - offset); } catch (DataFormatException ex) { System.out.println("ERROR on inflation " + ex.getMessage()); ex.printStackTrace(); throw new IOException(ex.getMessage());
private int inflate(byte[] b, int off, int len) throws DataFormatException, ZipException { checkState(inflater != null, "inflater is null"); try { int inflaterTotalIn = inflater.getTotalIn(); int n = inflater.inflate(b, off, len); int bytesConsumedDelta = inflater.getTotalIn() - inflaterTotalIn; bytesConsumed += bytesConsumedDelta; deflatedBytesConsumed += bytesConsumedDelta; inflaterInputStart += bytesConsumedDelta; crc.update(b, off, n); if (inflater.finished()) { // Save bytes written to check against the trailer ISIZE expectedGzipTrailerIsize = (inflater.getBytesWritten() & 0xffffffffL); state = State.TRAILER; } else if (inflater.needsInput()) { state = State.INFLATER_NEEDS_INPUT; } return n; } catch (DataFormatException e) { // Wrap the exception so tests can check for a specific prefix throw new DataFormatException("Inflater data format exception: " + e.getMessage()); } }
try outputLength = inflater.inflate(outputBuffer); // throws throw new ZipException(e.toString()); crc.update(outputBuffer, 0, outputLength); return ByteBuffer.wrap(outputBuffer, 0, outputLength); this.array = null; if(inflater.finished()) int r = inflater.getRemaining(); ByteBuffer obb = ByteBuffer.wrap(array, off + len - r, r); trailer = ByteBuffer.wrap(GzipByteSource.trailer(crc.getValue(), inflater.getBytesWritten())); inflater.end(); inflater=null;
inflater = new Inflater(); inflater.reset(); inflater.setInput(compress_buffer, 0, data_length); int inflate_count; try { e.printStackTrace(); debug.writeException(e); throw new Error(e.getMessage());
inf.setInput(buf, off, read); } else { buf[off] = 0; inf.setInput(buf, off, 1); // provide dummy byte while ((inflated = inf.inflate(infBuf, 0, infBuf.length)) > 0) crc.update(infBuf, 0, inflated); } catch (DataFormatException dfe) { IOException ioe = new IOException(dfe.toString()); ioe.initCause(dfe); throw ioe;
public byte[] decompress(byte[] input) throws Exception { decompressor.reset(); decompressor.setInput(input); // Create an expandable byte array to hold the decompressed data ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length); // Decompress the data byte[] buf = new byte[1024]; while (!decompressor.finished()) { try { int count = decompressor.inflate(buf); bos.write(buf, 0, count); } catch (DataFormatException e) { Exception ex = new Exception("Couldn't decompress given data (wrong format): "+e.getMessage(), e); throw ex; } } return bos.toByteArray(); }
@Override public void onReceived(double timestamp_utc, Object payload) { try { // This will replace all the internal members of the tree! unpack((byte[]) payload); // After unpacking, we must ensure this notify handler is re-attached ConfigNode tree_bin = getNode("ADMIN:TREE"); tree_bin.addNotifyHandler(this); code_list = getShortCodeMap(); enumerate(); CRC32 crc = new CRC32(); crc.update((byte[]) payload); final int crcvalue = (int)crc.getValue(); Log.d(TAG, "CALC CRC: " + Integer.toHexString(crcvalue)); getNode("ADMIN:CRC32").value = crcvalue; Util.setPreference(crcToPrefKey(crcvalue),(byte[])payload); } catch (DataFormatException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } });
@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; } } }
_inflater.setInput(buffer.array(),buffer.getIndex(),buffer.length()); ByteArrayBuffer buf = new ByteArrayBuffer(length); try while(_inflater.getRemaining()>0) int inflated=_inflater.inflate(buf.array(),buf.putIndex(),buf.space()); if (inflated==0) throw new DataFormatException("insufficient data"); buf.setPutIndex(buf.putIndex()+inflated); getConnection().close(WebSocketConnectionRFC6455.CLOSE_BAD_PAYLOAD,e.toString());
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();
Inflater inflater = new Inflater(false); inflater.setInput(b, pos, GINI_HED_LEN); try { int resultLength = inflater.inflate(buf, 0, GINI_HED_LEN); if (resultLength != GINI_HED_LEN) log.warn("GINI: Zlib inflated image header size error"); } catch (DataFormatException ex) { log.error("ERROR on inflation " + ex.getMessage()); ex.printStackTrace(); throw new IOException(ex.getMessage());
@Override public synchronized int decompress(byte[] b, int off, int len) throws IOException { try { return super.inflate(b, off, len); } catch (DataFormatException dfe) { throw new IOException(dfe.getMessage()); } } }
/** * Read data from input stream and fill buffer with compressed data. * @param in input stream with uncompressed data * @param b compressed data buffer * @param off offset in compressed data buffer * @param len length of compressed data to read * @return number of compressed bytes read * @throws DataFormatException if an error occurs in deflater * @throws IOException if an I/O error occurs while compressing */ protected int readCompressed(InputStream in, byte[] b, int off, int len) throws DataFormatException, IOException { int deflated = 0; while ((deflated = def.deflate(b, off, len)) == 0) { if (def.finished()) { return -1; } else if (def.needsInput()) { int read = in.read(inputBytes, 0, inputBytes.length); if (read != -1) { def.setInput(inputBytes, 0, read); crc.update(inputBytes, 0, read); } else { def.finish(); } } else { throw new DataFormatException("Deflater malfunction!"); } } return deflated; }