1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.compress.compressors.lz4;
20
21 import static org.junit.jupiter.api.Assertions.assertTrue;
22
23 import java.io.ByteArrayOutputStream;
24 import java.io.IOException;
25 import java.util.Arrays;
26
27 import org.junit.jupiter.api.Test;
28
29 public class FramedLZ4CompressorOutputStreamTest {
30
31 @Test
32 public void testFinishWithNoWrite() throws IOException {
33 final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
34 try (FramedLZ4CompressorOutputStream compressor = new FramedLZ4CompressorOutputStream(buffer,
35 new FramedLZ4CompressorOutputStream.Parameters(FramedLZ4CompressorOutputStream.BlockSize.K64, true, false, false))) {
36
37 }
38 assertTrue(buffer.size() == 15, "Only the trailer gets written.");
39 }
40
41 @Test
42 public void testWriteByteArrayVsWriteByte() throws IOException {
43 ByteArrayOutputStream buffer = new ByteArrayOutputStream();
44 final byte[] bytes = "abcdefghijklmnop".getBytes();
45 try (FramedLZ4CompressorOutputStream compressor = new FramedLZ4CompressorOutputStream(buffer,
46 new FramedLZ4CompressorOutputStream.Parameters(FramedLZ4CompressorOutputStream.BlockSize.K64, true, false, false))) {
47 compressor.write(bytes);
48 compressor.finish();
49 }
50 final byte[] bulkOutput = buffer.toByteArray();
51 buffer = new ByteArrayOutputStream();
52 try (FramedLZ4CompressorOutputStream compressor = new FramedLZ4CompressorOutputStream(buffer,
53 new FramedLZ4CompressorOutputStream.Parameters(FramedLZ4CompressorOutputStream.BlockSize.K64, true, false, false))) {
54 for (final byte element : bytes) {
55 compressor.write(element);
56 }
57 compressor.finish();
58 }
59 assertTrue(Arrays.equals(bulkOutput, buffer.toByteArray()));
60 }
61
62 }