Search in sources :

Example 1 with BZip2CompressorOutputStream

use of org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream in project netty by netty.

the class Bzip2DecoderTest method compress.

@Override
protected byte[] compress(byte[] data) throws Exception {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    BZip2CompressorOutputStream bZip2Os = new BZip2CompressorOutputStream(os, MIN_BLOCK_SIZE);
    bZip2Os.write(data);
    bZip2Os.close();
    return os.toByteArray();
}
Also used : BZip2CompressorOutputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with BZip2CompressorOutputStream

use of org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream in project otter by alibaba.

the class BZip2Compressor method compressTo.

public void compressTo(InputStream in, OutputStream out) throws CompressException {
    BZip2CompressorOutputStream outputBZStream = null;
    try {
        outputBZStream = new BZip2CompressorOutputStream(out);
        NioUtils.copy(in, outputBZStream);
        outputBZStream.finish();
    } catch (Exception e) {
        throw new CompressException("bzip_compress_error", e);
    }
}
Also used : BZip2CompressorOutputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream) CompressException(com.alibaba.otter.node.etl.common.io.compress.exception.CompressException) CompressException(com.alibaba.otter.node.etl.common.io.compress.exception.CompressException)

Example 3 with BZip2CompressorOutputStream

use of org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream in project rest.li by linkedin.

the class TestStreamingCompression method testBzip2Compressor.

@Test
public void testBzip2Compressor() throws IOException, InterruptedException, CompressionException, ExecutionException {
    StreamingCompressor compressor = new Bzip2Compressor(_executor);
    final byte[] origin = new byte[BUF_SIZE];
    Arrays.fill(origin, (byte) 'c');
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    BZip2CompressorOutputStream bzip = new BZip2CompressorOutputStream(out);
    IOUtils.write(origin, bzip);
    bzip.close();
    byte[] compressed = out.toByteArray();
    testCompress(compressor, origin, compressed);
    testDecompress(compressor, origin, compressed);
    testCompressThenDecompress(compressor, origin);
}
Also used : BZip2CompressorOutputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream) Bzip2Compressor(com.linkedin.r2.filter.compression.streaming.Bzip2Compressor) StreamingCompressor(com.linkedin.r2.filter.compression.streaming.StreamingCompressor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test)

Example 4 with BZip2CompressorOutputStream

use of org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream in project rest.li by linkedin.

the class Bzip2Compressor method deflate.

@Override
public byte[] deflate(InputStream data) throws CompressionException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    BZip2CompressorOutputStream compressor = null;
    try {
        out = new ByteArrayOutputStream();
        compressor = new BZip2CompressorOutputStream(out);
        IOUtils.copy(data, compressor);
        compressor.finish();
    } catch (IOException e) {
        throw new CompressionException(CompressionConstants.DECODING_ERROR + getContentEncodingName(), e);
    } finally {
        if (compressor != null) {
            IOUtils.closeQuietly(compressor);
        }
    }
    return out.toByteArray();
}
Also used : BZip2CompressorOutputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 5 with BZip2CompressorOutputStream

use of org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream in project carbondata by apache.

the class CompressdFileTest method makeBzip2File.

private static void makeBzip2File(String path, String content) throws Exception {
    path = path + ".bz2";
    FileOutputStream output = new FileOutputStream(path);
    try {
        Writer writer = new OutputStreamWriter(new BZip2CompressorOutputStream(output), "UTF-8");
        try {
            writer.write(content);
        } finally {
            writer.close();
        }
    } finally {
        output.close();
    }
}
Also used : BZip2CompressorOutputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

BZip2CompressorOutputStream (org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileOutputStream (java.io.FileOutputStream)4 IOException (java.io.IOException)4 OutputStream (java.io.OutputStream)4 GZIPOutputStream (java.util.zip.GZIPOutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)3 Bzip2Compressor (com.linkedin.r2.filter.compression.streaming.Bzip2Compressor)2 StreamingCompressor (com.linkedin.r2.filter.compression.streaming.StreamingCompressor)2 BufferedWriter (java.io.BufferedWriter)2 File (java.io.File)2 ZipEntry (java.util.zip.ZipEntry)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 Test (org.testng.annotations.Test)2 CompressException (com.alibaba.otter.node.etl.common.io.compress.exception.CompressException)1 BufferedOutputStream (java.io.BufferedOutputStream)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1