Search in sources :

Example 1 with CompressException

use of com.alibaba.otter.node.etl.common.io.compress.exception.CompressException in project otter by alibaba.

the class BZip2Compressor method decompressTo.

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

Example 2 with CompressException

use of com.alibaba.otter.node.etl.common.io.compress.exception.CompressException 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 CompressException

use of com.alibaba.otter.node.etl.common.io.compress.exception.CompressException in project otter by alibaba.

the class GzipCompressor method compressTo.

public void compressTo(InputStream in, OutputStream out) throws CompressException {
    GZIPOutputStream gzipOut = null;
    try {
        gzipOut = new GZIPOutputStream(out);
        NioUtils.copy(in, gzipOut);
        //需要使用finish
        gzipOut.finish();
    } catch (Exception e) {
        throw new CompressException("gzip_compress_error", e);
    }
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) CompressException(com.alibaba.otter.node.etl.common.io.compress.exception.CompressException) CompressException(com.alibaba.otter.node.etl.common.io.compress.exception.CompressException)

Example 4 with CompressException

use of com.alibaba.otter.node.etl.common.io.compress.exception.CompressException in project otter by alibaba.

the class GzipCompressor method decompressTo.

public void decompressTo(InputStream in, OutputStream out) throws CompressException {
    GZIPInputStream gzipin = null;
    try {
        gzipin = new GZIPInputStream(in);
        NioUtils.copy(gzipin, out);
        out.flush();
    } catch (Exception e) {
        throw new CompressException("gzip_decompress_error", e);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) CompressException(com.alibaba.otter.node.etl.common.io.compress.exception.CompressException) CompressException(com.alibaba.otter.node.etl.common.io.compress.exception.CompressException)

Example 5 with CompressException

use of com.alibaba.otter.node.etl.common.io.compress.exception.CompressException in project otter by alibaba.

the class AbstractCompressor method compress.

public InputStream compress(InputStream input) throws CompressException {
    FileOutputStream output = null;
    try {
        File temp = File.createTempFile("compress_", "jkt");
        output = new FileOutputStream(temp);
        //转化为流进行处理
        compressTo(input, output);
        return new FileInputStream(temp);
    } catch (IOException e) {
        throw new CompressException("An I/O Exception has occured", e);
    } finally {
        IOUtils.closeQuietly(output);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) CompressException(com.alibaba.otter.node.etl.common.io.compress.exception.CompressException)

Aggregations

CompressException (com.alibaba.otter.node.etl.common.io.compress.exception.CompressException)9 FileInputStream (java.io.FileInputStream)5 FileOutputStream (java.io.FileOutputStream)4 File (java.io.File)3 IOException (java.io.IOException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 GZIPInputStream (java.util.zip.GZIPInputStream)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 BZip2CompressorInputStream (org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream)1 BZip2CompressorOutputStream (org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream)1