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.deflate;
20
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22 import static org.junit.jupiter.api.Assertions.assertTrue;
23
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.nio.file.Files;
27
28 import org.apache.commons.compress.AbstractTest;
29 import org.apache.commons.io.IOUtils;
30 import org.junit.jupiter.api.Test;
31
32 class DeflateCompressorInputStreamTest {
33
34 @Test
35 void testAvailableShouldReturnNonZero() throws IOException {
36 try (InputStream is = Files.newInputStream(AbstractTest.getPath("bla.tar.deflatez"));
37 DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
38 assertTrue(in.available() > 0);
39 }
40 }
41
42 @Test
43 void testMultiByteReadConsistentlyReturnsMinusOneAtEof() throws IOException {
44 final byte[] buf = new byte[2];
45 try (InputStream is = Files.newInputStream(AbstractTest.getPath("bla.tar.deflatez"));
46 DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
47 IOUtils.toByteArray(in);
48 assertEquals(-1, in.read(buf));
49 assertEquals(-1, in.read(buf));
50 }
51 }
52
53 @Test
54 void testShouldBeAbleToSkipAByte() throws IOException {
55 try (InputStream is = Files.newInputStream(AbstractTest.getPath("bla.tar.deflatez"));
56 DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
57 assertEquals(1, in.skip(1));
58 }
59 }
60
61 @Test
62 void testSingleByteReadConsistentlyReturnsMinusOneAtEof() throws IOException {
63 try (InputStream is = Files.newInputStream(AbstractTest.getPath("bla.tar.deflatez"));
64 DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
65 IOUtils.toByteArray(in);
66 assertEquals(-1, in.read());
67 assertEquals(-1, in.read());
68 }
69 }
70
71 @Test
72 void testSingleByteReadWorksAsExpected() throws IOException {
73 try (InputStream is = Files.newInputStream(AbstractTest.getPath("bla.tar.deflatez"));
74 DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
75
76 assertEquals('t', in.read());
77 }
78 }
79
80 }