Example usage for org.apache.commons.compress.compressors.deflate DeflateCompressorOutputStream DeflateCompressorOutputStream

List of usage examples for org.apache.commons.compress.compressors.deflate DeflateCompressorOutputStream DeflateCompressorOutputStream

Introduction

In this page you can find the example usage for org.apache.commons.compress.compressors.deflate DeflateCompressorOutputStream DeflateCompressorOutputStream.

Prototype

public DeflateCompressorOutputStream(final OutputStream outputStream, final DeflateParameters parameters)
        throws IOException 

Source Link

Document

Creates a Deflate compressed output stream with the specified parameters.

Usage

From source file:com.chenshu.compress.CompressOldTest.java

@Benchmark
public int commonsDeflateCompress() {
    ByteArrayOutputStream bout = null;
    DeflateCompressorOutputStream dout = null;
    try {/*w ww. j av  a2 s . c om*/
        DeflateParameters p = new DeflateParameters();
        p.setCompressionLevel(level);
        bout = new ByteArrayOutputStream(data.length);
        dout = new DeflateCompressorOutputStream(bout, p);
        dout.write(data);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (dout != null) {
            try {
                dout.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (bout != null) {
            try {
                bout.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    byte[] bs = bout.toByteArray();
    return bs.length;
}