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);
}
}
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();
}
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;
}
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;
}
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);
}
Aggregations