Search in sources :

Example 51 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project platform_frameworks_base by android.

the class BlobBackupHelper method deflate.

// Also versions the deflated blob internally in case we need to revise it
private byte[] deflate(byte[] data) {
    byte[] result = null;
    if (data != null) {
        try {
            ByteArrayOutputStream sink = new ByteArrayOutputStream();
            DataOutputStream headerOut = new DataOutputStream(sink);
            // write the header directly to the sink ahead of the deflated payload
            headerOut.writeInt(mCurrentBlobVersion);
            DeflaterOutputStream out = new DeflaterOutputStream(sink);
            out.write(data);
            // finishes and commits the compression run
            out.close();
            result = sink.toByteArray();
            if (DEBUG) {
                Log.v(TAG, "Deflated " + data.length + " bytes to " + result.length);
            }
        } catch (IOException e) {
            Log.w(TAG, "Unable to process payload: " + e.getMessage());
        }
    }
    return result;
}
Also used : DataOutputStream(java.io.DataOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 52 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project netty by netty.

the class ZlibTest method deflate.

private static byte[] deflate(byte[] bytes) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    OutputStream stream = new DeflaterOutputStream(out);
    stream.write(bytes);
    stream.close();
    return out.toByteArray();
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 53 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project hadoop by apache.

the class CompressedWritable method write.

@Override
public final void write(DataOutput out) throws IOException {
    if (compressed == null) {
        ByteArrayOutputStream deflated = new ByteArrayOutputStream();
        Deflater deflater = new Deflater(Deflater.BEST_SPEED);
        DataOutputStream dout = new DataOutputStream(new DeflaterOutputStream(deflated, deflater));
        writeCompressed(dout);
        dout.close();
        deflater.end();
        compressed = deflated.toByteArray();
    }
    out.writeInt(compressed.length);
    out.write(compressed);
}
Also used : Deflater(java.util.zip.Deflater) DataOutputStream(java.io.DataOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 54 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project intellij-community by JetBrains.

the class RefCountingStorage method zipAndWrite.

private void zipAndWrite(ByteSequence bytes, int record, boolean fixedSize) throws IOException {
    BufferExposingByteArrayOutputStream s = new BufferExposingByteArrayOutputStream();
    DeflaterOutputStream out = new DeflaterOutputStream(s);
    try {
        out.write(bytes.getBytes(), bytes.getOffset(), bytes.getLength());
    } finally {
        out.close();
    }
    synchronized (myLock) {
        doWrite(record, fixedSize, s);
        myPendingWriteRequestsSize -= bytes.getLength();
        myPendingWriteRequests.remove(record);
    }
}
Also used : BufferExposingByteArrayOutputStream(com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream)

Example 55 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project OpenAM by OpenRock.

the class IOUtilsTest method getObjectStreamBytes.

private byte[] getObjectStreamBytes(Object in, boolean compress) throws IOException {
    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    final ObjectOutputStream objectOutputStream = compress ? new ObjectOutputStream(new DeflaterOutputStream(byteArrayOutputStream)) : new ObjectOutputStream(byteArrayOutputStream);
    objectOutputStream.writeObject(in);
    objectOutputStream.close();
    return byteArrayOutputStream.toByteArray();
}
Also used : DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream)

Aggregations

DeflaterOutputStream (java.util.zip.DeflaterOutputStream)76 ByteArrayOutputStream (java.io.ByteArrayOutputStream)50 Deflater (java.util.zip.Deflater)25 IOException (java.io.IOException)24 OutputStream (java.io.OutputStream)13 InflaterInputStream (java.util.zip.InflaterInputStream)9 DataOutputStream (java.io.DataOutputStream)8 GZIPOutputStream (java.util.zip.GZIPOutputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 BufferedOutputStream (java.io.BufferedOutputStream)3 EOFException (java.io.EOFException)3 InputStream (java.io.InputStream)3 Test (org.junit.Test)3 ImageException (cbit.image.ImageException)2 DeflateCompressor (com.linkedin.r2.filter.compression.streaming.DeflateCompressor)2 StreamingCompressor (com.linkedin.r2.filter.compression.streaming.StreamingCompressor)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 PipedInputStream (java.io.PipedInputStream)2