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)

  • Constructor Details

    • CpioArchiveOutputStream

      Constructs the cpio output stream. The format for this CPIO stream is the "new" format using ASCII encoding for file names
      Parameters:
      out - The cpio stream
    • CpioArchiveOutputStream

      public CpioArchiveOutputStream(OutputStream out, short format)
      Constructs the cpio output stream with a specified format, a blocksize of BLOCK_SIZE and using ASCII as the file name encoding.
      Parameters:
      out - The cpio stream
      format - The format of the stream
    • CpioArchiveOutputStream

      public CpioArchiveOutputStream(OutputStream out, short format, int blockSize)
      Constructs the cpio output stream with a specified format using ASCII as the file name encoding.
      Parameters:
      out - The cpio stream
      format - The format of the stream
      blockSize - The block size of the archive.
      Since:
      1.1
    • CpioArchiveOutputStream

      public CpioArchiveOutputStream(OutputStream out, short format, int blockSize, String encoding)
      Constructs the cpio output stream with a specified format using ASCII as the file name encoding.
      Parameters:
      out - The cpio stream
      format - The format of the stream
      blockSize - The block size of the archive.
      encoding - The encoding of file names to write - use null for the platform's default.
      Since:
      1.6
    • CpioArchiveOutputStream

      Constructs the cpio output stream. The format for this CPIO stream is the "new" format.
      Parameters:
      out - The cpio stream
      encoding - The encoding of file names to write - use null for the platform's default.
      Since:
      1.6
  • Method Details