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();
}
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);
}
}
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);
}
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();
}
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();
}
}
Aggregations