Search in sources :

Example 1 with InflaterOutputStream

use of java.util.zip.InflaterOutputStream in project jjwt by jwtk.

the class DeflateCompressionCodec method doDecompress.

@Override
public byte[] doDecompress(byte[] compressed) throws IOException {
    InflaterOutputStream inflaterOutputStream = null;
    ByteArrayOutputStream decompressedOutputStream = null;
    try {
        decompressedOutputStream = new ByteArrayOutputStream();
        inflaterOutputStream = new InflaterOutputStream(decompressedOutputStream);
        inflaterOutputStream.write(compressed);
        inflaterOutputStream.flush();
        return decompressedOutputStream.toByteArray();
    } finally {
        Objects.nullSafeClose(decompressedOutputStream, inflaterOutputStream);
    }
}
Also used : InflaterOutputStream(java.util.zip.InflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with InflaterOutputStream

use of java.util.zip.InflaterOutputStream in project voltdb by VoltDB.

the class CompressionService method gunzipBytes.

public static byte[] gunzipBytes(byte[] compressedBytes) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream((int) (compressedBytes.length * 1.5));
    InflaterOutputStream dos = new InflaterOutputStream(bos);
    dos.write(compressedBytes);
    dos.close();
    return bos.toByteArray();
}
Also used : InflaterOutputStream(java.util.zip.InflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with InflaterOutputStream

use of java.util.zip.InflaterOutputStream in project stetho by facebook.

the class RequestBodyHelper method createBodySink.

public OutputStream createBodySink(@Nullable String contentEncoding) throws IOException {
    OutputStream deflatingOutput;
    ByteArrayOutputStream deflatedOutput = new ByteArrayOutputStream();
    if (DecompressionHelper.GZIP_ENCODING.equals(contentEncoding)) {
        deflatingOutput = GunzippingOutputStream.create(deflatedOutput);
    } else if (DecompressionHelper.DEFLATE_ENCODING.equals(contentEncoding)) {
        deflatingOutput = new InflaterOutputStream(deflatedOutput);
    } else {
        deflatingOutput = deflatedOutput;
    }
    mDeflatingOutput = new CountingOutputStream(deflatingOutput);
    mDeflatedOutput = deflatedOutput;
    return mDeflatingOutput;
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InflaterOutputStream(java.util.zip.InflaterOutputStream) InflaterOutputStream(java.util.zip.InflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 4 with InflaterOutputStream

use of java.util.zip.InflaterOutputStream in project Much-Assembly-Required by simon987.

the class Memory method deserialize.

public static Memory deserialize(DBObject obj) {
    Memory memory = new Memory(0);
    String zipBytesStr = (String) obj.get("zipBytes");
    if (zipBytesStr != null) {
        byte[] compressedBytes = Base64.getDecoder().decode((String) obj.get("zipBytes"));
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            Inflater decompressor = new Inflater(true);
            InflaterOutputStream inflaterOutputStream = new InflaterOutputStream(baos, decompressor);
            inflaterOutputStream.write(compressedBytes);
            inflaterOutputStream.close();
            memory.setBytes(baos.toByteArray());
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        LogManager.LOGGER.severe("Memory was manually deleted");
        memory = new Memory(GameServer.INSTANCE.getConfig().getInt("memory_size"));
    }
    return memory;
}
Also used : Inflater(java.util.zip.Inflater) InflaterOutputStream(java.util.zip.InflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 5 with InflaterOutputStream

use of java.util.zip.InflaterOutputStream in project stetho by facebook.

the class DecompressionHelper method teeInputWithDecompression.

public static InputStream teeInputWithDecompression(NetworkPeerManager peerManager, String requestId, InputStream availableInputStream, OutputStream decompressedOutput, @Nullable String contentEncoding, ResponseHandler responseHandler) throws IOException {
    OutputStream output = decompressedOutput;
    CountingOutputStream decompressedCounter = null;
    if (contentEncoding != null) {
        boolean gzipEncoding = GZIP_ENCODING.equals(contentEncoding);
        boolean deflateEncoding = DEFLATE_ENCODING.equals(contentEncoding);
        if (gzipEncoding || deflateEncoding) {
            decompressedCounter = new CountingOutputStream(decompressedOutput);
            if (gzipEncoding) {
                output = GunzippingOutputStream.create(decompressedCounter);
            } else if (deflateEncoding) {
                output = new InflaterOutputStream(decompressedCounter);
            }
        } else {
            CLog.writeToConsole(peerManager, Console.MessageLevel.WARNING, Console.MessageSource.NETWORK, "Unsupported Content-Encoding in response for request #" + requestId + ": " + contentEncoding);
        }
    }
    return new ResponseHandlingInputStream(availableInputStream, requestId, output, decompressedCounter, peerManager, responseHandler);
}
Also used : OutputStream(java.io.OutputStream) InflaterOutputStream(java.util.zip.InflaterOutputStream) InflaterOutputStream(java.util.zip.InflaterOutputStream)

Aggregations

InflaterOutputStream (java.util.zip.InflaterOutputStream)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 OutputStream (java.io.OutputStream)2 IOException (java.io.IOException)1 Inflater (java.util.zip.Inflater)1