Example usage for org.apache.commons.compress.compressors CompressorOutputStream write

List of usage examples for org.apache.commons.compress.compressors CompressorOutputStream write

Introduction

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

Prototype

public void write(byte b[], int off, int len) throws IOException 

Source Link

Document

Writes len bytes from the specified byte array starting at offset off to this output stream.

Usage

From source file:darks.codec.wrap.zip.CommonsCompress.java

/**
 * {@inheritDoc}// w  ww . j ava 2s.co  m
 */
@Override
public void compress(InputStream input, OutputStream out) throws Exception {
    CompressorOutputStream cos = null;
    try {
        cos = factory.createCompressorOutputStream(type, out);
        byte[] buf = new byte[1024];
        int len;
        while ((len = input.read(buf)) > 0) {
            cos.write(buf, 0, len);
        }
        cos.flush();
    } catch (CompressorException e) {
        throw new Exception("Fail to compress data by commons compress. Cause " + e.getMessage(), e);
    } finally {
        IoHelper.closeIO(cos);
    }
}