Search in sources :

Example 16 with DeflaterOutputStream

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

the class SourceCodeCompressor method compress.

public static synchronized byte[] compress(byte[] source, int off, int len) {
    try {
        DEFLATER.reset();
        DEFLATER.setDictionary(PRESET_BUF);
        try {
            DeflaterOutputStream output = null;
            try {
                output = new DeflaterOutputStream(OUTPUT, DEFLATER);
                output.write(source, off, len);
            } finally {
                if (output != null) {
                    output.close();
                }
            }
        } catch (IOException e) {
            return source;
        }
        return OUTPUT.toByteArray();
    } finally {
        OUTPUT.reset();
    }
}
Also used : DeflaterOutputStream(java.util.zip.DeflaterOutputStream) IOException(java.io.IOException)

Example 17 with DeflaterOutputStream

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

the class ConnectionStreams method setGzipped.

// Actions ================================================================
// Actions ================================================================
public void setGzipped() throws IOException {
    loggedWriter.flush();
    loggedOutputStream.flush();
    deflaterOutputStream = new DeflaterOutputStream(connection.getOutputStream(), new Deflater(6));
    setOutputStream(deflaterOutputStream);
    setInputStream(new InflaterInputStream(connection.getInputStream()));
}
Also used : Deflater(java.util.zip.Deflater) InflaterInputStream(java.util.zip.InflaterInputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream)

Example 18 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project gerrit by GerritCodeReview.

the class PatchList method writeObject.

private void writeObject(final ObjectOutputStream output) throws IOException {
    final ByteArrayOutputStream buf = new ByteArrayOutputStream();
    try (DeflaterOutputStream out = new DeflaterOutputStream(buf)) {
        writeCanBeNull(out, oldId);
        writeNotNull(out, newId);
        writeVarInt32(out, isMerge ? 1 : 0);
        comparisonType.writeTo(out);
        writeVarInt32(out, insertions);
        writeVarInt32(out, deletions);
        writeVarInt32(out, patches.length);
        for (PatchListEntry p : patches) {
            p.writeTo(out);
        }
    }
    writeBytes(output, buf.toByteArray());
}
Also used : DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 19 with DeflaterOutputStream

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

the class Metafile method compress.

protected static byte[] compress(byte[] bytes, int offset, int length) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    DeflaterOutputStream deflater = new DeflaterOutputStream(out);
    deflater.write(bytes, offset, length);
    deflater.close();
    return out.toByteArray();
}
Also used : DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 20 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project teaTime by ancfdy.

the class AppZLibMgr method compress.

/**
     * 压缩
     *
     * @param data
     *            待压
     *缩数据
     * @param os
     *            输出流
     */
public static void compress(byte[] data, OutputStream os) {
    DeflaterOutputStream dos = new DeflaterOutputStream(os);
    try {
        dos.write(data, 0, data.length);
        dos.finish();
        dos.flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : DeflaterOutputStream(java.util.zip.DeflaterOutputStream) IOException(java.io.IOException)

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