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.cpio;
20
21 import java.io.File;
22 import java.io.FileInputStream;
23 import java.io.FileOutputStream;
24 import java.io.InputStream;
25
26 import org.apache.commons.compress.AbstractTestCase;
27 import org.apache.commons.compress.utils.IOUtils;
28
29 public class CpioArchiveOutputStreamTest extends AbstractTestCase {
30
31 public void testWriteOldBinary() throws Exception {
32 final File f = getFile("test1.xml");
33 final File output = new File(dir, "test.cpio");
34 final FileOutputStream out = new FileOutputStream(output);
35 InputStream in = null;
36 try {
37 final CpioArchiveOutputStream os =
38 new CpioArchiveOutputStream(out, CpioConstants
39 .FORMAT_OLD_BINARY);
40 os.putArchiveEntry(new CpioArchiveEntry(CpioConstants
41 .FORMAT_OLD_BINARY,
42 f, "test1.xml"));
43 IOUtils.copy(in = new FileInputStream(f), os);
44 in.close();
45 in = null;
46 os.closeArchiveEntry();
47 os.close();
48 } finally {
49 if (in != null) {
50 in.close();
51 }
52 out.close();
53 }
54
55 try {
56 in = new CpioArchiveInputStream(new FileInputStream(output));
57 CpioArchiveEntry e = ((CpioArchiveInputStream) in)
58 .getNextCPIOEntry();
59 assertEquals("test1.xml", e.getName());
60 assertNull(((CpioArchiveInputStream) in).getNextEntry());
61 } finally {
62 if (in != null) {
63 in.close();
64 }
65 }
66 }
67 }