1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.codehaus.plexus.archiver.tar;
18
19 import java.io.ByteArrayInputStream;
20 import java.io.ByteArrayOutputStream;
21 import java.io.IOException;
22
23 import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
24 import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
25 import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
26 import org.junit.jupiter.api.Test;
27
28 import static org.junit.jupiter.api.Assertions.assertEquals;
29 import static org.junit.jupiter.api.Assertions.assertNull;
30 import static org.junit.jupiter.api.Assertions.assertTrue;
31
32
33
34
35 class TarRoundTripTest {
36
37 private static final String LONG_NAME = "this/path/name/contains/more/than/one/hundred/characters/in/order/"
38 + "to/test/the/GNU/long/file/name/capability/round/tripped";
39
40
41
42
43 @Test
44 void testLongRoundTripping() throws IOException {
45 TarArchiveEntry original = new TarArchiveEntry(LONG_NAME);
46 assertTrue(LONG_NAME.length() > 100, "over 100 chars");
47 assertEquals(LONG_NAME, original.getName(), "original name");
48
49 ByteArrayOutputStream buff = new ByteArrayOutputStream();
50 TarArchiveOutputStream tos = new TarArchiveOutputStream(buff);
51 tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
52 tos.putArchiveEntry(original);
53 tos.closeArchiveEntry();
54 tos.close();
55
56 TarArchiveInputStream tis = new TarArchiveInputStream(new ByteArrayInputStream(buff.toByteArray()));
57 TarArchiveEntry tripped = tis.getNextTarEntry();
58 assertEquals(LONG_NAME, tripped.getName(), "round-tripped name");
59 assertNull(tis.getNextEntry(), "no more entries");
60 tis.close();
61 }
62 }