Search in sources :

Example 1 with DeflateCompressorOutputStream

use of org.apache.commons.compress.compressors.deflate.DeflateCompressorOutputStream in project beam by apache.

the class TextIOTest method writeToFile.

private static File writeToFile(String[] lines, String filename, CompressionType compression) throws IOException {
    File file = tempFolder.resolve(filename).toFile();
    OutputStream output = new FileOutputStream(file);
    switch(compression) {
        case UNCOMPRESSED:
            break;
        case GZIP:
            output = new GZIPOutputStream(output);
            break;
        case BZIP2:
            output = new BZip2CompressorOutputStream(output);
            break;
        case ZIP:
            ZipOutputStream zipOutput = new ZipOutputStream(output);
            zipOutput.putNextEntry(new ZipEntry("entry"));
            output = zipOutput;
            break;
        case DEFLATE:
            output = new DeflateCompressorOutputStream(output);
            break;
        default:
            throw new UnsupportedOperationException(compression.toString());
    }
    writeToStreamAndClose(lines, output);
    return file;
}
Also used : DeflateCompressorOutputStream(org.apache.commons.compress.compressors.deflate.DeflateCompressorOutputStream) BZip2CompressorOutputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) BZip2CompressorOutputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream) DeflateCompressorOutputStream(org.apache.commons.compress.compressors.deflate.DeflateCompressorOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) File(java.io.File)

Aggregations

File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 BZip2CompressorOutputStream (org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream)1 DeflateCompressorOutputStream (org.apache.commons.compress.compressors.deflate.DeflateCompressorOutputStream)1