com.jguild.jrpm.io.cpio
Class CPIOOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended byjava.io.FilterOutputStream
          extended bycom.jguild.jrpm.io.cpio.CPIOOutputStream
All Implemented Interfaces:
CPIOConstants

public class CPIOOutputStream
extends java.io.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

Field Summary
 
Fields inherited from class java.io.FilterOutputStream
out
 
Fields inherited from interface com.jguild.jrpm.io.cpio.CPIOConstants
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, 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 Summary
CPIOOutputStream(java.io.OutputStream out)
          Construct the cpio output stream.
CPIOOutputStream(java.io.OutputStream out, short format)
          Construct the cpio output stream with a specified format
 
Method Summary
 void close()
          Closes the CPIO output stream as well as the stream being filtered.
 void closeEntry()
          Closes the current CPIO entry and positions the stream for writing the next entry.
 void finish()
          Finishes writing the contents of the CPIO output stream without closing the underlying stream.
 void putNextEntry(CPIOEntry e)
          Begins writing a new CPIO file entry and positions the stream to the start of the entry data.
 void setFormat(short format)
          Set a default header format.
 void write(byte[] b, int off, int len)
          Writes an array of bytes to the current CPIO entry data.
 
Methods inherited from class java.io.FilterOutputStream
flush, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CPIOOutputStream

public CPIOOutputStream(java.io.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(java.io.OutputStream out)
Construct the cpio output stream. The format for this CPIO stream is the "new" format

Parameters:
out - The cpio stream
Method Detail

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

putNextEntry

public void putNextEntry(CPIOEntry e)
                  throws java.io.IOException
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:
java.io.IOException - if an I/O error has occurred or if a CPIO file error has occurred

closeEntry

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

Throws:
java.io.IOException - if an I/O error has occurred or if a CPIO file error has occurred

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
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:
java.io.IOException - if an I/O error has occurred or if a CPIO file error has occurred

finish

public void finish()
            throws java.io.IOException
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:
java.io.IOException - if an I/O exception has occurred or if a CPIO file error has occurred

close

public void close()
           throws java.io.IOException
Closes the CPIO output stream as well as the stream being filtered.

Throws:
java.io.IOException - if an I/O error has occurred or if a CPIO file error has occurred


Copyright © 2002-2005 Sourceforge. All Rights Reserved.