com.jguild.jrpm.io.cpio

Class CPIOOutputStream

public final class CPIOOutputStream extends FilterOutputStream implements CPIOConstants

CPIOOutputStream is a stream for writting 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 CPIOEntry 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.

 CPIOOutputStream cpioOut = new CPIOOutputStream(new BufferedOutputStream(
         new FileOutputStream(new File("test.cpio"))));
 CPIOEntry cpioEntry = new CPIOEntry();
 cpioEntry.setName("testfile");
 String testContents = "12345";
 cpioEntry.setFileSize(testContents.length());
 cpioOut.putNextEntry(cpioEntry);
 cpioOut.write(testContents.getBytes());
 cpioOut.finish();
 cpioOut.close();
 

Note: This implementation should be compatible to cpio 2.5

Author: Michael Kuss

Constructor Summary
CPIOOutputStream(OutputStream out, short format)
Construct the cpio output stream with a specified format
CPIOOutputStream(OutputStream out)
Construct the cpio output stream.
Method Summary
voidclose()
Closes the CPIO output stream as well as the stream being filtered.
voidcloseEntry()
Closes the current CPIO entry and positions the stream for writing the next entry.
voidfinish()
Finishes writing the contents of the CPIO output stream without closing the underlying stream.
voidputNextEntry(CPIOEntry e)
Begins writing a new CPIO file entry and positions the stream to the start of the entry data.
voidsetFormat(short format)
Set a default header format.
voidwrite(byte[] b, int off, int len)
Writes an array of bytes to the current CPIO entry data.

Constructor Detail

CPIOOutputStream

public CPIOOutputStream(OutputStream out, short format)
Construct the cpio output stream with a specified format

Parameters: out The cpio stream format The format of the stream

CPIOOutputStream

public CPIOOutputStream(OutputStream out)
Construct the cpio output stream. The format for this CPIO stream is the "new" format

Parameters: out The cpio stream

Method Detail

close

public void close()
Closes the CPIO output stream as well as the stream being filtered.

Throws: IOException if an I/O error has occurred or if a CPIO file error has occurred

closeEntry

public void closeEntry()
Closes the current CPIO entry and positions the stream for writing the next entry.

Throws: IOException if an I/O error has occurred or if a CPIO file error has occurred

finish

public void finish()
Finishes writing the contents of the CPIO output stream without closing the underlying stream. Use this method when applying multiple filters in succession to the same output stream.

Throws: IOException if an I/O exception has occurred or if a CPIO file error has occurred

putNextEntry

public void putNextEntry(CPIOEntry e)
Begins writing a new CPIO file entry and positions the stream to the start of the entry data. Closes the current entry if still active. The current time will be used if the entry has no set modification time and the default header format will be used if no other format is specified in the entry.

Parameters: e the CPIO cpioEntry to be written

Throws: IOException if an I/O error has occurred or if a CPIO file error has occurred

setFormat

public void setFormat(short format)
Set a default header format. This will be used if no format is defined in the cpioEntry given to putNextEntry().

Parameters: format A CPIO format

write

public void write(byte[] b, int off, int len)
Writes an array of bytes to the current CPIO entry data. This method will block until all the bytes are written.

Parameters: b the data to be written off the start offset in the data len the number of bytes that are written

Throws: IOException if an I/O error has occurred or if a CPIO file error has occurred