Example usage for org.apache.commons.compress.compressors CompressorOutputStream write

List of usage examples for org.apache.commons.compress.compressors CompressorOutputStream write

Introduction

In this page you can find the example usage for org.apache.commons.compress.compressors CompressorOutputStream write.

Prototype

public abstract void write(int b) throws IOException;

Source Link

Document

Writes the specified byte to this output stream.

Usage

From source file:com.streamsets.pipeline.stage.origin.spooldir.TestSpoolDirWithCompression.java

@BeforeClass
public static void setUpClass()
        throws IOException, InterruptedException, URISyntaxException, CompressorException {
    testDir = new File("target", UUID.randomUUID().toString()).getAbsoluteFile();
    Assert.assertTrue(testDir.mkdirs());
    Files.copy(Paths.get(Resources.getResource("logArchive.zip").toURI()),
            Paths.get(testDir.getAbsolutePath(), "logArchive1.zip"));
    Files.copy(Paths.get(Resources.getResource("logArchive.zip").toURI()),
            Paths.get(testDir.getAbsolutePath(), "logArchive2.zip"));
    Files.copy(Paths.get(Resources.getResource("logArchive.tar.gz").toURI()),
            Paths.get(testDir.getAbsolutePath(), "logArchive1.tar.gz"));
    Files.copy(Paths.get(Resources.getResource("logArchive.tar.gz").toURI()),
            Paths.get(testDir.getAbsolutePath(), "logArchive2.tar.gz"));
    Files.copy(Paths.get(Resources.getResource("testAvro.tar.gz").toURI()),
            Paths.get(testDir.getAbsolutePath(), "testAvro1.tar.gz"));
    Files.copy(Paths.get(Resources.getResource("testAvro.tar.gz").toURI()),
            Paths.get(testDir.getAbsolutePath(), "testAvro2.tar.gz"));

    File bz2File = new File(testDir, "testFile1.bz2");
    CompressorOutputStream bzip2 = new CompressorStreamFactory().createCompressorOutputStream("bzip2",
            new FileOutputStream(bz2File));
    bzip2.write(IOUtils.toByteArray(Resources.getResource("testLogFile.txt").openStream()));
    bzip2.close();// ww w .j av  a  2s. c om

    bz2File = new File(testDir, "testFile2.bz2");
    bzip2 = new CompressorStreamFactory().createCompressorOutputStream("bzip2", new FileOutputStream(bz2File));
    bzip2.write(IOUtils.toByteArray(Resources.getResource("testLogFile.txt").openStream()));
    bzip2.close();
}

From source file:com.streamsets.pipeline.lib.parser.TestCompressionInputBuilder.java

private void testCompressedFile(String compressionType) throws Exception {

    //write data into the stream using the specified compression
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    CompressorOutputStream cOut = new CompressorStreamFactory().createCompressorOutputStream(compressionType,
            bOut);/*from   ww w  .ja va  2  s  .c  o m*/
    cOut.write("StreamSets".getBytes());
    cOut.close();

    //create compression input
    CompressionDataParser.CompressionInputBuilder compressionInputBuilder = new CompressionDataParser.CompressionInputBuilder(
            Compression.COMPRESSED_FILE, null, new ByteArrayInputStream(bOut.toByteArray()), "0");
    CompressionDataParser.CompressionInput input = compressionInputBuilder.build();

    //verify
    Assert.assertNotNull(input);
    Assert.assertEquals("myFile::4567", input.wrapOffset("myFile::4567"));
    Assert.assertEquals("myFile::4567", input.wrapRecordId("myFile::4567"));
    InputStream myFile = input.getNextInputStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(myFile));
    Assert.assertEquals("StreamSets", reader.readLine());
}

From source file:com.streamsets.pipeline.lib.parser.TestCompressionInputBuilder.java

private void testConcatenatedCompressedFile(String compressionType) throws Exception {
    ByteArrayOutputStream bytes1 = new ByteArrayOutputStream();
    ByteArrayOutputStream bytes2 = new ByteArrayOutputStream();
    CompressorOutputStream compressed1 = new CompressorStreamFactory()
            .createCompressorOutputStream(compressionType, bytes1);

    CompressorOutputStream compressed2 = new CompressorStreamFactory()
            .createCompressorOutputStream(compressionType, bytes2);

    compressed1.write("line1\n".getBytes());
    compressed1.close();// ww w  . j  a v a  2 s.  c o m

    compressed2.write("line2".getBytes());
    compressed2.close();

    CompressionDataParser.CompressionInputBuilder compressionInputBuilder = new CompressionDataParser.CompressionInputBuilder(
            Compression.COMPRESSED_FILE, null,
            new SequenceInputStream(new ByteArrayInputStream(bytes1.toByteArray()),
                    new ByteArrayInputStream(bytes2.toByteArray())),
            "0");
    CompressionDataParser.CompressionInput input = compressionInputBuilder.build();

    //verify
    Assert.assertNotNull(input);
    Assert.assertEquals("myFile::4567", input.wrapOffset("myFile::4567"));
    Assert.assertEquals("myFile::4567", input.wrapRecordId("myFile::4567"));
    InputStream myFile = input.getNextInputStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(myFile));
    Assert.assertEquals("line1", reader.readLine());
    Assert.assertEquals("line2", reader.readLine());
}

From source file:no.finntech.shootout.streams.CompressedStreams.java

@Override
protected void writeTo(OutputStream out) throws IOException, CompressorException {
    String json = JsonUtil.objectToJson(getObject());
    CompressorOutputStream outputStream = FACTORY.createCompressorOutputStream(getCompressor(), out);
    outputStream.write(json.getBytes());
    outputStream.flush();//ww w .ja v  a  2 s .  c  o m
    outputStream.close();
}