com.jguild.jrpm.io.cpio
Class CPIOInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended bycom.jguild.jrpm.io.cpio.CPIOInputStream
All Implemented Interfaces:
CPIOConstants

public class CPIOInputStream
extends java.io.FilterInputStream
implements CPIOConstants

CPIOInputStream is a stream for reading cpio streams. All formats of cpio are supported (old ascii, old binary, new portable format and the new portable format with crc).

The stream can be read by extracting a cpio entry (containing all informations about a entry) and afterwards reading from the stream the file specified by the entry.

 CPIOInputStream cpioIn = new CPIOInputStream(new BufferedInputStream(new FileInputStream(new File("test.cpio"))));
 CPIOEntry cpioEntry;

 while ((cpioEntry = cpioIn.getNextEntry()) != null) {
     System.out.println(cpioEntry.getName());
     int tmp;
     StringBuffer buf = new StringBuffer();
     while ((tmp = cpIn.read()) != -1) {
        buf.append((char) tmp);
     }
     System.out.println(buf.toString());
 }
 cpioIn.close();
 
Note: This implementation should be compatible to cpio 2.5

Author:
Michael Kuss

Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
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
CPIOInputStream(java.io.InputStream in)
          Construct the cpio input stream
 
Method Summary
 int available()
          Returns 0 after EOF has reached for the current entry data, otherwise always return 1.
 void close()
          Closes the CPIO input stream.
 void closeEntry()
          Closes the current CPIO entry and positions the stream for reading the next entry.
 CPIOEntry getNextEntry()
          Reads the next CPIO file entry and positions stream at the beginning of the entry data.
 int read()
          Reads a byte of data.
 int read(byte[] b, int off, int len)
          Reads from the current CPIO entry into an array of bytes.
 long skip(long n)
          Skips specified number of bytes in the current CPIO entry.
 
Methods inherited from class java.io.FilterInputStream
mark, markSupported, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CPIOInputStream

public CPIOInputStream(java.io.InputStream in)
Construct the cpio input stream

Parameters:
in - The cpio stream
Method Detail

available

public int available()
              throws java.io.IOException
Returns 0 after EOF has reached for the current entry data, otherwise always return 1.

Programs should not count on this method to return the actual number of bytes that could be read without blocking.

Returns:
1 before EOF and 0 after EOF has reached for current entry.
Throws:
java.io.IOException - if an I/O error has occurred or if a CPIO file error has occurred

close

public void close()
           throws java.io.IOException
Closes the CPIO input stream.

Throws:
java.io.IOException - if an I/O error has occurred

closeEntry

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

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

getNextEntry

public CPIOEntry getNextEntry()
                       throws java.io.IOException
Reads the next CPIO file entry and positions stream at the beginning of the entry data.

Returns:
the CPIOEntry just read
Throws:
java.io.IOException - if an I/O error has occurred or if a CPIO file error has occurred

read

public int read()
         throws java.io.IOException
Reads a byte of data. This method will block until enough input is available.

Returns:
the byte read, or -1 if end of input is reached
Throws:
java.io.IOException - if an I/O error has occurred or if a CPIO file error has occurred

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads from the current CPIO entry into an array of bytes. Blocks until some input is available.

Parameters:
b - the buffer into which the data is read
off - the start offset of the data
len - the maximum number of bytes read
Returns:
the actual number of bytes read, or -1 if the end of the entry is reached
Throws:
java.io.IOException - if an I/O error has occurred or if a CPIO file error has occurred

skip

public long skip(long n)
          throws java.io.IOException
Skips specified number of bytes in the current CPIO entry.

Parameters:
n - the number of bytes to skip
Returns:
the actual number of bytes skipped
Throws:
java.io.IOException - if an I/O error has occurred
java.lang.IllegalArgumentException - if n < 0


Copyright © 2002-2005 Sourceforge. All Rights Reserved.