Search in sources :

Example 11 with BZip2CompressorOutputStream

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

the class Urify method urify.

private void urify(String resource) throws IOException {
    File source = new File(resource);
    if (source.isFile()) {
        String path = FilenameUtils.getFullPathNoEndSeparator(resource);
        String name = FilenameUtils.getName(resource);
        File target = new File(path, outputFilePrefix + name);
        int i = 0;
        while (target.exists()) {
            i++;
            target = new File(path, "uf" + i + "_" + name);
        }
        InputStream is = new FileInputStream(source);
        OutputStream os = new FileOutputStream(target);
        log.info("RDFTerm: {}", resource);
        log.info("Target  : {}", target);
        if ("gz".equalsIgnoreCase(FilenameUtils.getExtension(name))) {
            is = new GZIPInputStream(is);
            os = new GZIPOutputStream(os);
            name = FilenameUtils.removeExtension(name);
            log.debug("   - from GZIP Archive");
        } else if ("bz2".equalsIgnoreCase(FilenameUtils.getExtension(name))) {
            is = new BZip2CompressorInputStream(is);
            os = new BZip2CompressorOutputStream(os);
            name = FilenameUtils.removeExtension(name);
            log.debug("   - from BZip2 Archive");
        }
        // TODO: No Zip File support
        //else no complression
        BlockingQueue<String> queue = new ArrayBlockingQueue<String>(1000);
        ReaderDaemon reader = new ReaderDaemon(new BufferedReader(new InputStreamReader(is, charset)), queue);
        WriterDaemon writer = new WriterDaemon(new BufferedWriter(new OutputStreamWriter(os, charset)), queue);
        Thread readerDaemon = new Thread(reader, name + " reader");
        Thread writerDaemon = new Thread(writer, name + " writer");
        readerDaemon.setDaemon(true);
        writerDaemon.setDaemon(true);
        writerDaemon.start();
        readerDaemon.start();
        Object notifier = writer.getNotifier();
        synchronized (notifier) {
            //wait until processed
            if (!writer.completed()) {
                try {
                    notifier.wait();
                } catch (InterruptedException e) {
                /*ignore*/
                }
            }
        }
        if (reader.getError() != null) {
            throw new IOException("Error while reading source " + source, reader.getError());
        }
        if (writer.getError() != null) {
            throw new IOException("Error while writing resource " + target, writer.getError());
        }
        log.info(" ... completed resource {}", resource);
    } else {
        throw new FileNotFoundException("Parsed File " + resource + " does not exist or is not a File!");
    }
}
Also used : BZip2CompressorOutputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream) InputStreamReader(java.io.InputStreamReader) GZIPInputStream(java.util.zip.GZIPInputStream) BZip2CompressorInputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BZip2CompressorOutputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) BufferedWriter(java.io.BufferedWriter) GZIPInputStream(java.util.zip.GZIPInputStream) BZip2CompressorInputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File)

Example 12 with BZip2CompressorOutputStream

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

the class CompressUtil method _compressBZip2.

/**
 * compress a source file to a bzip2 file
 * @param source
 * @param target
 * @throws IOException
 */
private static void _compressBZip2(InputStream source, OutputStream target) throws IOException {
    InputStream is = IOUtil.toBufferedInputStream(source);
    OutputStream os = new BZip2CompressorOutputStream(IOUtil.toBufferedOutputStream(target));
    IOUtil.copy(is, os, true, true);
}
Also used : BZip2CompressorOutputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream) GZIPInputStream(java.util.zip.GZIPInputStream) ZipInputStream(java.util.zip.ZipInputStream) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BZip2CompressorOutputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream)

Aggregations

BZip2CompressorOutputStream (org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 FileOutputStream (java.io.FileOutputStream)5 OutputStream (java.io.OutputStream)5 GZIPOutputStream (java.util.zip.GZIPOutputStream)5 IOException (java.io.IOException)4 OutputStreamWriter (java.io.OutputStreamWriter)3 ZipOutputStream (java.util.zip.ZipOutputStream)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 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 GZIPInputStream (java.util.zip.GZIPInputStream)2 ZipEntry (java.util.zip.ZipEntry)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