Search in sources :

Example 6 with CompressionOutputStream

use of org.apache.nifi.remote.io.CompressionOutputStream in project nifi by apache.

the class TestCompressionInputOutputStreams method testDataLargerThanBuffer.

@Test
public void testDataLargerThanBuffer() throws IOException {
    final String str = "The quick brown fox jumps over the lazy dog\r\n\n\n\r";
    final StringBuilder sb = new StringBuilder();
    for (int i = 0; i < 100; i++) {
        sb.append(str);
    }
    final byte[] data = sb.toString().getBytes("UTF-8");
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final CompressionOutputStream cos = new CompressionOutputStream(baos, 8192);
    cos.write(data);
    cos.flush();
    cos.close();
    final byte[] compressedBytes = baos.toByteArray();
    final CompressionInputStream cis = new CompressionInputStream(new ByteArrayInputStream(compressedBytes));
    final byte[] decompressed = readFully(cis);
    assertTrue(Arrays.equals(data, decompressed));
}
Also used : CompressionOutputStream(org.apache.nifi.remote.io.CompressionOutputStream) CompressionInputStream(org.apache.nifi.remote.io.CompressionInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

CompressionOutputStream (org.apache.nifi.remote.io.CompressionOutputStream)6 CompressionInputStream (org.apache.nifi.remote.io.CompressionInputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Test (org.junit.Test)4 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 CheckedOutputStream (java.util.zip.CheckedOutputStream)2 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 CRC32 (java.util.zip.CRC32)1 CheckedInputStream (java.util.zip.CheckedInputStream)1 FlowFile (org.apache.nifi.flowfile.FlowFile)1 InputStreamCallback (org.apache.nifi.processor.io.InputStreamCallback)1 ProtocolException (org.apache.nifi.remote.exception.ProtocolException)1 StandardDataPacket (org.apache.nifi.remote.util.StandardDataPacket)1 StopWatch (org.apache.nifi.util.StopWatch)1