1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.compress.archivers;
20
21 import static org.junit.Assert.assertTrue;
22 import static org.junit.Assert.fail;
23
24 import java.io.BufferedInputStream;
25 import java.io.ByteArrayInputStream;
26 import java.io.FileInputStream;
27 import java.io.InputStream;
28
29 import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
30 import org.junit.Test;
31
32 public class ArchiveStreamFactoryTest {
33
34
35
36
37 @Test
38 public void shortTextFilesAreNoTARs() throws Exception {
39 try {
40 new ArchiveStreamFactory()
41 .createArchiveInputStream(new ByteArrayInputStream("This certainly is not a tar archive, really, no kidding".getBytes()));
42 fail("created an input stream for a non-archive");
43 } catch (ArchiveException ae) {
44 assertTrue(ae.getMessage().startsWith("No Archiver found"));
45 }
46 }
47
48
49
50
51 @Test
52 public void aiffFilesAreNoTARs() throws Exception {
53 InputStream is = null;
54 try {
55 is = new BufferedInputStream(new FileInputStream("src/test/resources/testAIFF.aif"));
56 new ArchiveStreamFactory().createArchiveInputStream(is);
57 fail("created an input stream for a non-archive");
58 } catch (ArchiveException ae) {
59 assertTrue(ae.getMessage().startsWith("No Archiver found"));
60 } finally {
61 if (is != null) {
62 is.close();
63 }
64 }
65 }
66
67 @Test
68 public void testCOMPRESS209() throws Exception {
69 InputStream is = null;
70 try {
71 is = new BufferedInputStream(new FileInputStream("src/test/resources/testCompress209.doc"));
72 new ArchiveStreamFactory().createArchiveInputStream(is);
73 fail("created an input stream for a non-archive");
74 } catch (ArchiveException ae) {
75 assertTrue(ae.getMessage().startsWith("No Archiver found"));
76 } finally {
77 if (is != null) {
78 is.close();
79 }
80 }
81 }
82
83
84
85
86
87
88 @Test
89 public void skipsPK00Prefix() throws Exception {
90 InputStream is = null;
91 try {
92 is = new BufferedInputStream(new FileInputStream("src/test/resources/COMPRESS-208.zip"));
93 ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(is);
94 assertTrue(ais instanceof ZipArchiveInputStream);
95 } finally {
96 if (is != null) {
97 is.close();
98 }
99 }
100 }
101 }