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;
20
21 import java.io.File;
22 import java.io.InputStream;
23 import java.io.OutputStream;
24 import java.nio.file.Files;
25
26 import org.apache.commons.compress.AbstractTest;
27 import org.apache.commons.compress.compressors.deflate.DeflateCompressorInputStream;
28 import org.apache.commons.compress.compressors.deflate.DeflateCompressorOutputStream;
29 import org.apache.commons.compress.compressors.deflate.DeflateParameters;
30 import org.junit.jupiter.api.Test;
31
32 public final class DeflateTest extends AbstractTest {
33
34
35
36
37
38
39 @Test
40 public void testDeflateCreation() throws Exception {
41 final File input = getFile("test1.xml");
42 final File output = newTempFile("test1.xml.deflatez");
43 try (OutputStream out = Files.newOutputStream(output.toPath())) {
44 try (CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream("deflate", out)) {
45 Files.copy(input.toPath(), cos);
46 }
47 }
48 }
49
50
51
52
53
54
55 @Test
56 public void testDeflateUnarchive() throws Exception {
57 final File input = getFile("bla.tar.deflatez");
58 final File output = newTempFile("bla.tar");
59 try (InputStream is = Files.newInputStream(input.toPath())) {
60
61 try (CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("deflate", is)) {
62 Files.copy(in, output.toPath());
63 }
64 }
65 }
66
67
68
69
70
71
72 @Test
73 public void testRawDeflateCreation() throws Exception {
74 final File input = getFile("test1.xml");
75 final File output = newTempFile("test1.xml.deflate");
76 try (OutputStream out = Files.newOutputStream(output.toPath())) {
77 final DeflateParameters params = new DeflateParameters();
78 params.setWithZlibHeader(false);
79 try (CompressorOutputStream cos = new DeflateCompressorOutputStream(out, params)) {
80 Files.copy(input.toPath(), cos);
81 }
82 }
83 }
84
85
86
87
88
89
90 @Test
91 public void testRawDeflateUnarchive() throws Exception {
92 final File input = getFile("bla.tar.deflate");
93 final File output = newTempFile("bla.tar");
94 try (InputStream is = Files.newInputStream(input.toPath())) {
95 final DeflateParameters params = new DeflateParameters();
96 params.setWithZlibHeader(false);
97 try (CompressorInputStream in = new DeflateCompressorInputStream(is, params)) {
98 Files.copy(in, output.toPath());
99 }
100 }
101 }
102 }