Class CpioArchiveOutputStream

All Implemented Interfaces:
Closeable, Flushable, AutoCloseable, CpioConstants

CpioArchiveOutputStream is a stream for writing CPIO streams. All formats of CPIO are supported (old ASCII, old binary, new portable format and the new portable format with CRC).

An entry can be written by creating an instance of CpioArchiveEntry and fill it with the necessary values and put it into the CPIO stream. Afterwards write the contents of the file into the CPIO stream. Either close the stream by calling finish() or put a next entry into the cpio stream.

 CpioArchiveOutputStream out = new CpioArchiveOutputStream(
         new FileOutputStream(new File("test.cpio")));
 CpioArchiveEntry entry = new CpioArchiveEntry();
 entry.setName("testfile");
 String contents = "12345";
 entry.setFileSize(contents.length());
 entry.setMode(CpioConstants.C_ISREG); // regular file
 ... set other attributes, e.g. time, number of links
 out.putArchiveEntry(entry);
 out.write(testContents.getBytes());
 out.close();
 

Note: This implementation should be compatible to cpio 2.5

This class uses mutable fields and is not considered threadsafe.

based on code from the jRPM project (jrpm.sourceforge.net)