|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.InputStream org.apache.commons.compress.archivers.ArchiveInputStream org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream
public class CpioArchiveInputStream
CPIOArchiveInputStream 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.
CPIOArchiveInputStream cpioIn = new CPIOArchiveInputStream(
new FileInputStream(new File("test.cpio")));
CPIOArchiveEntry 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
This class uses mutable fields and is not considered to be threadsafe.
Based on code from the jRPM project (jrpm.sourceforge.net)
Field Summary |
---|
Fields inherited from interface org.apache.commons.compress.archivers.cpio.CpioConstants |
---|
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 Summary | |
---|---|
CpioArchiveInputStream(InputStream in)
Construct the cpio input stream with a blocksize of BLOCK_SIZE . |
|
CpioArchiveInputStream(InputStream in,
int blockSize)
Construct the cpio input stream with a blocksize of BLOCK_SIZE . |
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. |
CpioArchiveEntry |
getNextCPIOEntry()
Reads the next CPIO file entry and positions stream at the beginning of the entry data. |
ArchiveEntry |
getNextEntry()
Returns the next Archive Entry in this Stream. |
static boolean |
matches(byte[] signature,
int length)
Checks if the signature matches one of the following magic values: Strings: "070701" - MAGIC_NEW "070702" - MAGIC_NEW_CRC "070707" - MAGIC_OLD_ASCII Octal Binary value: 070707 - MAGIC_OLD_BINARY (held as a short) = 0x71C7 or 0xC771 |
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 org.apache.commons.compress.archivers.ArchiveInputStream |
---|
canReadEntryData, count, count, getBytesRead, getCount, pushedBackBytes, read |
Methods inherited from class java.io.InputStream |
---|
mark, markSupported, read, reset |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CpioArchiveInputStream(InputStream in)
BLOCK_SIZE
.
in
- The cpio streampublic CpioArchiveInputStream(InputStream in, int blockSize)
BLOCK_SIZE
.
Construct the cpio input stream.
in
- The cpio streamblockSize
- The block size of the archive.Method Detail |
---|
public int available() throws IOException
available
in class InputStream
IOException
- if an I/O error has occurred or if a CPIO file error has
occurredpublic void close() throws IOException
close
in interface Closeable
close
in class InputStream
IOException
- if an I/O error has occurredpublic CpioArchiveEntry getNextCPIOEntry() throws IOException
IOException
- if an I/O error has occurred or if a CPIO file error has
occurredpublic int read(byte[] b, int off, int len) throws IOException
read
in class InputStream
b
- the buffer into which the data is readoff
- the start offset of the datalen
- the maximum number of bytes read
IOException
- if an I/O error has occurred or if a CPIO file error has
occurredpublic long skip(long n) throws IOException
skip
in class InputStream
n
- the number of bytes to skip
IOException
- if an I/O error has occurred
IllegalArgumentException
- if n < 0public ArchiveEntry getNextEntry() throws IOException
getNextEntry
in class ArchiveInputStream
null
if there are no more entries
IOException
- if the next entry could not be readpublic static boolean matches(byte[] signature, int length)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |