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.ar;
20
21 import java.io.ByteArrayOutputStream;
22 import java.io.File;
23 import java.io.FileOutputStream;
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import org.apache.commons.compress.AbstractTestCase;
29
30 public class ArArchiveOutputStreamTest extends AbstractTestCase {
31
32 public void testLongFileNamesCauseExceptionByDefault() {
33 ArArchiveOutputStream os = null;
34 try {
35 os = new ArArchiveOutputStream(new ByteArrayOutputStream());
36 ArArchiveEntry ae = new ArArchiveEntry("this_is_a_long_name.txt",
37 0);
38 os.putArchiveEntry(ae);
39 fail("Expected an exception");
40 } catch (IOException ex) {
41 assertTrue(ex.getMessage().startsWith("filename too long"));
42 } finally {
43 closeQuietly(os);
44 }
45 }
46
47 public void testLongFileNamesWorkUsingBSDDialect() throws Exception {
48 FileOutputStream fos = null;
49 ArArchiveOutputStream os = null;
50 File[] df = createTempDirAndFile();
51 try {
52 fos = new FileOutputStream(df[1]);
53 os = new ArArchiveOutputStream(fos);
54 os.setLongFileMode(ArArchiveOutputStream.LONGFILE_BSD);
55 ArArchiveEntry ae = new ArArchiveEntry("this_is_a_long_name.txt",
56 14);
57 os.putArchiveEntry(ae);
58 os.write(new byte[] {
59 'H', 'e', 'l', 'l', 'o', ',', ' ',
60 'w', 'o', 'r', 'l', 'd', '!', '\n'
61 });
62 os.closeArchiveEntry();
63 os.close();
64 os = null;
65 fos = null;
66
67 List<String> expected = new ArrayList<String>();
68 expected.add("this_is_a_long_name.txt");
69 checkArchiveContent(df[1], expected);
70 } finally {
71 if (os != null) {
72 os.close();
73 }
74 if (fos != null) {
75 fos.close();
76 }
77 rmdir(df[0]);
78 }
79 }
80 }