1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.compress.archivers.zip;
19
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21 import static org.junit.jupiter.api.Assertions.assertThrows;
22
23 import java.io.IOException;
24 import java.io.InputStream;
25
26 import org.apache.commons.compress.AbstractTest;
27 import org.apache.commons.compress.archivers.ArchiveEntry;
28 import org.junit.jupiter.api.Test;
29
30
31
32
33
34
35
36
37
38
39 public class Maven221MultiVolumeTest extends AbstractTest {
40
41 private static final String[] ENTRIES = {
42
43 "apache-maven-2.2.1/",
44 "apache-maven-2.2.1/LICENSE.txt",
45 "apache-maven-2.2.1/NOTICE.txt",
46 "apache-maven-2.2.1/README.txt",
47 "apache-maven-2.2.1/bin/",
48 "apache-maven-2.2.1/bin/m2.conf",
49 "apache-maven-2.2.1/bin/mvn",
50 "apache-maven-2.2.1/bin/mvn.bat",
51 "apache-maven-2.2.1/bin/mvnDebug",
52 "apache-maven-2.2.1/bin/mvnDebug.bat",
53 "apache-maven-2.2.1/boot/",
54 "apache-maven-2.2.1/boot/classworlds-1.1.jar",
55 "apache-maven-2.2.1/conf/",
56 "apache-maven-2.2.1/conf/settings.xml",
57 "apache-maven-2.2.1/lib/"
58
59 };
60
61 private static final String LAST_ENTRY_NAME = "apache-maven-2.2.1/lib/maven-2.2.1-uber.jar";
62
63 @Test
64 public void testRead7ZipMultiVolumeArchiveForFile() {
65 assertThrows(IOException.class, () -> ZipFile.builder().setFile(getFile("apache-maven-2.2.1.zip.001")).get());
66 }
67
68 @Test
69 public void testRead7ZipMultiVolumeArchiveForStream() throws IOException {
70
71 try (InputStream archive = newInputStream("apache-maven-2.2.1.zip.001");
72 ZipArchiveInputStream zi = new ZipArchiveInputStream(archive, null, false)) {
73
74
75
76 for (final String element : ENTRIES) {
77 assertEquals(element, zi.getNextEntry().getName());
78 }
79
80
81 final ArchiveEntry lastEntry = zi.getNextEntry();
82 assertEquals(LAST_ENTRY_NAME, lastEntry.getName());
83 final byte[] buffer = new byte[4096];
84
85
86
87
88
89 final IOException e1 = assertThrows(IOException.class, () -> {
90 while (zi.read(buffer) > 0) {
91
92 }
93 }, "shouldn't be able to read from truncated entry");
94 assertEquals("Truncated ZIP file", e1.getMessage());
95
96 final IOException e2 = assertThrows(IOException.class, () -> zi.read(buffer), "shouldn't be able to read from truncated entry after exception");
97 assertEquals("Truncated ZIP file", e2.getMessage());
98
99
100
101 assertThrows(IOException.class, zi::getNextEntry, "shouldn't be able to read another entry from truncated file");
102 }
103 }
104 }