Search in sources :

Example 96 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 97 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 98 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 99 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)

Example 100 with DeflaterOutputStream

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

the class SAML2Utils method encodeForRedirect.

/**
     * Returns the encoded request message.
     * The SAML Request message must be
     * encoded before being transmitted.
     * The Request message is encoded as follows:
     * 1. URL Encoded using the DEFLATE compression method.
     * 2. Then the message is base-64 encoded according to
     * the rules specified in RFC2045.
     *
     * @param str String to be encoded.
     * @return String the encoded String value or null on error.
     */
public static String encodeForRedirect(final String str) {
    String classMethod = "SAML2Utils.encodeForRedirect: ";
    byte[] input;
    try {
        input = str.getBytes("UTF-8");
    } catch (UnsupportedEncodingException uee) {
        debug.error(classMethod + "cannot get byte array: ", uee);
        return null;
    }
    Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(out, deflater);
    try {
        deflaterOutputStream.write(input);
    } catch (IOException e) {
        debug.error(classMethod + "There was a problem compressing the input", e);
        return null;
    } finally {
        IOUtils.closeIfNotNull(deflaterOutputStream);
    }
    String encoded = URLEncDec.encode(Base64.encode(out.toByteArray()));
    if (debug.messageEnabled()) {
        debug.message(classMethod + "out string length : " + encoded.length());
        debug.message(classMethod + "out string is ===>" + encoded + "<===");
    }
    return encoded;
}
Also used : Deflater(java.util.zip.Deflater) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

DeflaterOutputStream (java.util.zip.DeflaterOutputStream)162 ByteArrayOutputStream (java.io.ByteArrayOutputStream)101 Deflater (java.util.zip.Deflater)63 IOException (java.io.IOException)52 OutputStream (java.io.OutputStream)39 DataOutputStream (java.io.DataOutputStream)21 InflaterInputStream (java.util.zip.InflaterInputStream)16 GZIPOutputStream (java.util.zip.GZIPOutputStream)12 File (java.io.File)9 FileOutputStream (java.io.FileOutputStream)8 InputStream (java.io.InputStream)7 ObjectOutputStream (java.io.ObjectOutputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 FileInputStream (java.io.FileInputStream)6 BufferedOutputStream (java.io.BufferedOutputStream)5 ByteArrayOutputStream (org.fusesource.hawtbuf.ByteArrayOutputStream)5 Saml2Exception (org.springframework.security.saml2.Saml2Exception)5 ByteBuffer (java.nio.ByteBuffer)4 EOFException (java.io.EOFException)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3