public class CpioArchiveOutputStream extends ArchiveOutputStream<CpioArchiveEntry> implements CpioConstants
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)
BLOCK_SIZE, C_IRGRP, C_IROTH, C_IRUSR, C_ISBLK, C_ISCHR, C_ISDIR, C_ISFIFO, C_ISGID, C_ISLNK, C_ISNWK, C_ISREG, C_ISSOCK, C_ISUID, C_ISVTX, C_IWGRP, C_IWOTH, C_IWUSR, C_IXGRP, C_IXOTH, C_IXUSR, CPIO_TRAILER, FORMAT_NEW, FORMAT_NEW_CRC, FORMAT_NEW_MASK, FORMAT_OLD_ASCII, FORMAT_OLD_BINARY, FORMAT_OLD_MASK, MAGIC_NEW, MAGIC_NEW_CRC, MAGIC_OLD_ASCII, MAGIC_OLD_BINARY, S_IFMT| Constructor and Description |
|---|
CpioArchiveOutputStream(OutputStream out)
Constructs the cpio output stream.
|
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. |
CpioArchiveOutputStream(OutputStream out,
short format,
int blockSize)
Constructs the cpio output stream with a specified format using
ASCII as the file name encoding.
|
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.
|
CpioArchiveOutputStream(OutputStream out,
String encoding)
Constructs the cpio output stream.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the CPIO output stream as well as the stream being filtered.
|
void |
closeArchiveEntry()
Closes the archive entry, writing any trailer information that may
be required.
|
CpioArchiveEntry |
createArchiveEntry(File inputFile,
String entryName)
Creates a new CpioArchiveEntry.
|
CpioArchiveEntry |
createArchiveEntry(Path inputPath,
String entryName,
LinkOption... options)
Creates a new CpioArchiveEntry.
|
void |
finish()
Finishes writing the contents of the CPIO output stream without closing
the underlying stream.
|
void |
putArchiveEntry(CpioArchiveEntry entry)
Begins writing a new CPIO file entry and positions the stream to the
start of the entry data.
|
void |
write(byte[] b,
int off,
int len)
Writes an array of bytes to the current CPIO entry data.
|
canWriteEntryData, count, count, getBytesWritten, getCount, writeflush, writepublic CpioArchiveOutputStream(OutputStream out)
out - The cpio streampublic CpioArchiveOutputStream(OutputStream out, short format)
BLOCK_SIZE and
using ASCII as the file name encoding.out - The cpio streamformat - The format of the streampublic CpioArchiveOutputStream(OutputStream out, short format, int blockSize)
out - The cpio streamformat - The format of the streamblockSize - The block size of the archive.public CpioArchiveOutputStream(OutputStream out, short format, int blockSize, String encoding)
out - The cpio streamformat - The format of the streamblockSize - The block size of the archive.encoding - The encoding of file names to write - use null for
the platform's default.public CpioArchiveOutputStream(OutputStream out, String encoding)
out - The cpio streamencoding - The encoding of file names to write - use null for
the platform's default.public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamIOException - if an I/O error has occurred or if a CPIO file error has
occurredpublic void closeArchiveEntry()
throws IOException
ArchiveOutputStreamcloseArchiveEntry in class ArchiveOutputStream<CpioArchiveEntry>IOException - if an I/O error occurspublic CpioArchiveEntry createArchiveEntry(File inputFile, String entryName) throws IOException
createArchiveEntry in class ArchiveOutputStream<CpioArchiveEntry>inputFile - the file to create the entry fromentryName - name to use for the entryIOException - if an I/O error occursArchiveOutputStream.createArchiveEntry(java.io.File, String)public CpioArchiveEntry createArchiveEntry(Path inputPath, String entryName, LinkOption... options) throws IOException
createArchiveEntry in class ArchiveOutputStream<CpioArchiveEntry>inputPath - the file to create the entry fromentryName - name to use for the entryoptions - options indicating how symbolic links are handled.IOException - if an I/O error occursArchiveOutputStream.createArchiveEntry(java.io.File, String)public void finish()
throws IOException
finish in class ArchiveOutputStream<CpioArchiveEntry>IOException - if an I/O exception has occurred or if a CPIO file error has
occurredpublic void putArchiveEntry(CpioArchiveEntry entry) throws IOException
putArchiveEntry in class ArchiveOutputStream<CpioArchiveEntry>entry - the CPIO cpioEntry to be writtenIOException - if an I/O error has occurred or if a CPIO file error has
occurredClassCastException - if entry is not an instance of CpioArchiveEntrypublic void write(byte[] b,
int off,
int len)
throws IOException
write in class OutputStreamb - the data to be writtenoff - the start offset in the datalen - the number of bytes that are writtenIOException - if an I/O error has occurred or if a CPIO file error has
occurredCopyright © 2002–2025. All rights reserved.