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 static org.junit.jupiter.api.Assertions.assertEquals;
22 import static org.junit.jupiter.api.Assertions.assertNull;
23 import static org.junit.jupiter.api.Assertions.assertTrue;
24
25 import java.io.File;
26 import java.nio.file.Files;
27
28 import org.apache.commons.compress.AbstractTest;
29 import org.junit.jupiter.api.Test;
30
31 class CpioArchiveOutputStreamTest extends AbstractTest {
32
33 @Test
34 void testWriteOldBinary() throws Exception {
35 final File file = getFile("test1.xml");
36 final File output = newTempFile("test.cpio");
37 final CpioArchiveOutputStream ref;
38 try (CpioArchiveOutputStream outputStream = new CpioArchiveOutputStream(Files.newOutputStream(output.toPath()), CpioConstants.FORMAT_OLD_BINARY)) {
39 ref = outputStream;
40 outputStream.putArchiveEntry(new CpioArchiveEntry(CpioConstants.FORMAT_OLD_BINARY, file, "test1.xml"));
41 outputStream.write(file);
42 outputStream.closeArchiveEntry();
43 }
44 assertTrue(ref.isClosed());
45 try (CpioArchiveInputStream in = new CpioArchiveInputStream(Files.newInputStream(output.toPath()))) {
46 final CpioArchiveEntry e = in.getNextCPIOEntry();
47 assertEquals("test1.xml", e.getName());
48 assertNull(in.getNextEntry());
49 }
50 }
51 }