Search in sources :

Example 6 with CompressionInputStream

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

the class TestCompressionInputOutputStreams method testSimple.

@Test
public void testSimple() throws IOException {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final byte[] data = "Hello, World!".getBytes("UTF-8");
    final CompressionOutputStream cos = new CompressionOutputStream(baos);
    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)

Example 7 with CompressionInputStream

use of org.apache.nifi.remote.io.CompressionInputStream 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

CompressionInputStream (org.apache.nifi.remote.io.CompressionInputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 CompressionOutputStream (org.apache.nifi.remote.io.CompressionOutputStream)4 Test (org.junit.Test)4 InputStream (java.io.InputStream)3 CheckedInputStream (java.util.zip.CheckedInputStream)2 ProtocolException (org.apache.nifi.remote.exception.ProtocolException)2 StandardDataPacket (org.apache.nifi.remote.util.StandardDataPacket)2 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 CRC32 (java.util.zip.CRC32)1 FlowFile (org.apache.nifi.flowfile.FlowFile)1 StandardFlowFileCodec (org.apache.nifi.remote.codec.StandardFlowFileCodec)1 DataPacket (org.apache.nifi.remote.protocol.DataPacket)1 Response (org.apache.nifi.remote.protocol.Response)1 ByteArrayInputStream (org.apache.nifi.stream.io.ByteArrayInputStream)1 StopWatch (org.apache.nifi.util.StopWatch)1