Refine search
/** * returns a {@link InflaterInputStream} which wraps the original entity's content stream * * @see HttpEntity#getContent() */ @Override public InputStream getContent() throws IOException, IllegalStateException { return new InflaterInputStream(wrappedEntity.getContent(), new Inflater(useNoWrapForInflateDecoding)); }
private DataInputStream getZlibInputStream(byte[] data) { return new DataInputStream(new BufferedInputStream(new InflaterInputStream( new ByteArrayInputStream(data), new Inflater(), 2048))); }
/** * Decompress ZLIB (RFC 1950) compressed data * * @param compressedData A byte array containing the ZLIB-compressed data. * @param maxBytes The maximum number of uncompressed bytes to read. * @return A string containing the decompressed data */ public static String decompressZlib(byte[] compressedData, long maxBytes) throws IOException { try (final ByteArrayInputStream dataStream = new ByteArrayInputStream(compressedData); final InflaterInputStream in = new InflaterInputStream(dataStream); final InputStream limited = ByteStreams.limit(in, maxBytes)) { return new String(ByteStreams.toByteArray(limited), StandardCharsets.UTF_8); } }
/** Must be called by all methods which access fields to ensure that the data * has been uncompressed. */ protected void ensureInflated() { if (compressed != null) { try { ByteArrayInputStream deflated = new ByteArrayInputStream(compressed); DataInput inflater = new DataInputStream(new InflaterInputStream(deflated)); readFieldsCompressed(inflater); compressed = null; } catch (IOException e) { throw new RuntimeException(e); } } }
@SuppressWarnings("resource") // caller must close the InputStream @Override InputStream decode(final String archiveName, final InputStream in, final long uncompressedLength, final Coder coder, final byte[] password) throws IOException { final Inflater inflater = new Inflater(true); // Inflater with nowrap=true has this odd contract for a zero padding // byte following the data stream; this used to be zlib's requirement // and has been fixed a long time ago, but the contract persists so // we comply. // https://docs.oracle.com/javase/7/docs/api/java/util/zip/Inflater.html#Inflater(boolean) final InflaterInputStream inflaterInputStream = new InflaterInputStream(new SequenceInputStream(in, new ByteArrayInputStream(ONE_ZERO_BYTE)), inflater); return new DeflateDecoderInputStream(inflaterInputStream, inflater); } @Override
in = new InflaterInputStream(conn.getInputStream()), new Inflater(true));
/** * @see <a href="https://github.com/logstash-plugins/logstash-input-beats/blob/master/PROTOCOL.md#compressed-frame-type">'compressed' frame type</a> */ private Collection<ByteBuf> processCompressedFrame(Channel channel, ByteBuf channelBuffer) throws Exception { final long payloadLength = channelBuffer.readUnsignedInt(); final byte[] data = new byte[(int) payloadLength]; channelBuffer.readBytes(data); try (final ByteArrayInputStream dataStream = new ByteArrayInputStream(data); final InputStream in = new InflaterInputStream(dataStream)) { final ByteBuf buffer = Unpooled.wrappedBuffer(ByteStreams.toByteArray(in)); return processCompressedDataFrames(channel, buffer); } }
try { if(type.equalsIgnoreCase(HttpHeaders.Values.GZIP)) { reader = new GZIPInputStream(new ByteArrayInputStream(fullMessage)); }else if(type.equalsIgnoreCase(HttpHeaders.Values.DEFLATE)) { reader = new InflaterInputStream(new ByteArrayInputStream(fullMessage), new Inflater(true));
protected InputStream detectStreamEncode(String encoding, InputStream ins) throws IOException { if (encoding != null && encoding.contains("gzip")) { return new GZIPInputStream(ins); } else if (encoding != null && encoding.contains("deflate")) { return new InflaterInputStream(ins, new Inflater(true)); } else { return ins; } }
private static byte[] inflate(byte[] input) throws IOException { InflaterInputStream gzis = new InflaterInputStream(new ByteArrayInputStream(input)); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; while(gzis.available() > 0) { int l = gzis.read(buffer); if(l > 0) out.write(buffer, 0, l); } return out.toByteArray(); }
public static byte[] inflate(byte[] input, int bufferSize) throws IOException { ByteArrayInputStream in = new ByteArrayInputStream(input); Inflater inf = new Inflater(); InflaterInputStream iis = new InflaterInputStream(in, inf, bufferSize); ByteArrayOutputStream out = new ByteArrayOutputStream(input.length * 5); for (int c = iis.read(); c != -1; c = iis.read()) { out.write(c); } in.close(); iis.close(); byte[] ret = out.toByteArray(); out.close(); return ret; }
@Override public InputStream decode(String contentEncoding, InputStream encodedStream) throws IOException { // correct impl. should wrap deflate in zlib, but some don't do it - have to identify, which one we got InputStream markSupportingStream = encodedStream.markSupported() ? encodedStream : new BufferedInputStream(encodedStream); markSupportingStream.mark(1); // read the first byte int firstByte = markSupportingStream.read(); markSupportingStream.reset(); // if using zlib, first 3 bits should be 0, 4th should be 1 // that should never be the case if no zlib wrapper if ((firstByte & 15) == 8) { // ok, zlib wrapped stream return new InflaterInputStream(markSupportingStream); } else { // no zlib wrapper return new InflaterInputStream(markSupportingStream, new Inflater(true)); } }
public byte[] decompress(byte[] in) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayInputStream bais = new ByteArrayInputStream(in); final InflaterInputStream gz = new InflaterInputStream(bais); int read; while ((read = gz.read()) != -1) { baos.write(read); } gz.close(); bais.close(); baos.close(); return baos.toByteArray(); }
/** * Decompresses the specified byte array according to the DEFLATE * specification (RFC 1951). * * @param bytes The byte array to decompress. Must not be {@code null}. * * @return The decompressed bytes. * * @throws java.io.IOException If decompression failed. */ public static byte[] decompress(final byte[] bytes) throws IOException { InflaterInputStream inf = new InflaterInputStream(new ByteArrayInputStream(bytes), new Inflater(NOWRAP)); ByteArrayOutputStream out = new ByteArrayOutputStream(); // Transfer bytes from the compressed array to the output byte[] buf = new byte[1024]; int len; while ((len = inf.read(buf)) > 0) { out.write(buf, 0, len); } inf.close(); out.close(); return out.toByteArray(); }
@Override public InputStream decode(String contentEncoding, InputStream encodedStream) throws IOException { // correct impl. should wrap deflate in zlib, but some don't do it - have to identify, which one we got InputStream markSupportingStream = encodedStream.markSupported() ? encodedStream : new BufferedInputStream(encodedStream); markSupportingStream.mark(1); // read the first byte int firstByte = markSupportingStream.read(); markSupportingStream.reset(); // if using zlib, first 3 bits should be 0, 4th should be 1 // that should never be the case if no zlib wrapper if ((firstByte & 15) == 8) { // ok, zlib wrapped stream return new InflaterInputStream(markSupportingStream); } else { // no zlib wrapper return new InflaterInputStream(markSupportingStream, new Inflater(true)); } }
/** * Deserialize this object, decompressing the partitions which can exceed the * allowed jobConf size. * @see <a href="https://issues.apache.org/jira/browse/HCATALOG-453">HCATALOG-453</a> */ @SuppressWarnings("unchecked") private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { ois.defaultReadObject(); //Next object in the stream will be a byte array of partition information which is compressed ObjectInputStream pis = new ObjectInputStream(new ByteArrayInputStream( (byte[])ois.readObject())); ObjectInputStream partInfoReader = new ObjectInputStream(new InflaterInputStream(pis)); partitions = (List<PartInfo>)partInfoReader.readObject(); if (partitions != null) { for (PartInfo partInfo : partitions) { if (partInfo.getTableInfo() == null) { partInfo.setTableInfo(this.tableInfo); } } } //Closing only the reader used for decompression byte stream partInfoReader.close(); } }
private byte[] decompress(byte[] data) throws SessionValueEncoderException { if (!doCompress()) { return data; } ByteArrayInputStream bais = new ByteArrayInputStream(data); Inflater inf = new Inflater(false); InflaterInputStream iis = new InflaterInputStream(bais, inf); try { return StreamUtil.readBytes(iis, true).toByteArray(); } catch (Exception e) { throw new SessionValueEncoderException(e); } finally { inf.end(); } }
private InputStream openStream(ZipEntry2 entry) throws IOException{ InputStream in = readData(entry.offset, entry.compSize); if (entry.deflate){ return new InflaterInputStream(in, new Inflater(true)); } return in; }
/** * Decompresses the provided data, returning the inflated result. * * @param data the deflated picture data. * @return the inflated picture data. */ private static byte[] inflatePictureData(byte[] data) { try { InflaterInputStream in = new InflaterInputStream(new ByteArrayInputStream(data)); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buf = new byte[4096]; int readBytes; while ((readBytes = in.read(buf)) > 0) { out.write(buf, 0, readBytes); } return out.toByteArray(); } catch (IOException e) { log.log(POILogger.INFO, "Possibly corrupt compression or non-compressed data", e); return data; } }
private byte[] decompress(byte[] data) throws SessionValueEncoderException { if (!doCompress()) { return data; } ByteArrayInputStream bais = new ByteArrayInputStream(data); Inflater inf = new Inflater(false); InflaterInputStream iis = new InflaterInputStream(bais, inf); try { return StreamUtil.readBytes(iis, true).toByteArray(); } catch (Exception e) { throw new SessionValueEncoderException(e); } finally { inf.end(); } }