public class CpioArchiveInputStream extends ArchiveInputStream<CpioArchiveEntry> implements CpioConstants
The stream can be read by extracting a cpio entry (containing all information about an entry) and afterwards reading from the stream the file specified by the entry.
CpioArchiveInputStream cpioIn = new CpioArchiveInputStream(Files.newInputStream(Paths.get("test.cpio")));
CpioArchiveEntry cpioEntry;
while ((cpioEntry = cpioIn.getNextEntry()) != null) {
System.out.println(cpioEntry.getName());
int tmp;
StringBuilder buf = new StringBuilder();
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)
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 |
|---|
CpioArchiveInputStream(java.io.InputStream in)
Constructs the cpio input stream with a blocksize of
BLOCK_SIZE and expecting ASCII file names. |
CpioArchiveInputStream(java.io.InputStream in,
int blockSize)
Constructs the cpio input stream with a blocksize of
BLOCK_SIZE expecting ASCII file names. |
CpioArchiveInputStream(java.io.InputStream in,
int blockSize,
java.lang.String encoding)
Constructs the cpio input stream with a blocksize of
BLOCK_SIZE. |
CpioArchiveInputStream(java.io.InputStream in,
java.lang.String encoding)
Constructs the cpio input stream with a blocksize of
BLOCK_SIZE. |
| Modifier and Type | Method and Description |
|---|---|
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()
Deprecated.
Use
getNextEntry(). |
CpioArchiveEntry |
getNextEntry()
Gets 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.
|
canReadEntryData, getBytesRead, getCharset, getCount, mark, markSupported, read, resetpublic CpioArchiveInputStream(java.io.InputStream in)
BLOCK_SIZE and expecting ASCII file names.in - The cpio streampublic CpioArchiveInputStream(java.io.InputStream in,
int blockSize)
BLOCK_SIZE expecting ASCII file names.in - The cpio streamblockSize - The block size of the archive.public CpioArchiveInputStream(java.io.InputStream in,
int blockSize,
java.lang.String encoding)
BLOCK_SIZE.in - The cpio streamblockSize - The block size of the archive.encoding - The encoding of file names to expect - use null for the platform's default.java.lang.IllegalArgumentException - if blockSize is not bigger than 0public CpioArchiveInputStream(java.io.InputStream in,
java.lang.String encoding)
BLOCK_SIZE.in - The cpio streamencoding - The encoding of file names to expect - use null for the platform's default.public static boolean matches(byte[] signature,
int length)
signature - data to matchlength - length of datapublic int available()
throws java.io.IOException
Programs should not count on this method to return the actual number of bytes that could be read without blocking.
available in class java.io.FilterInputStreamjava.io.IOException - if an I/O error has occurred or if a CPIO file error has occurredpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.FilterInputStreamjava.io.IOException - if an I/O error has occurred@Deprecated public CpioArchiveEntry getNextCPIOEntry() throws java.io.IOException
getNextEntry().java.io.IOException - if an I/O error has occurred or if a CPIO file error has occurredpublic CpioArchiveEntry getNextEntry() throws java.io.IOException
ArchiveInputStreamgetNextEntry in class ArchiveInputStream<CpioArchiveEntry>null if there are no more entriesjava.io.IOException - if the next entry could not be readpublic int read(byte[] b,
int off,
int len)
throws java.io.IOException
read in class java.io.FilterInputStreamb - the buffer into which the data is readoff - the start offset of the datalen - the maximum number of bytes readjava.io.IOException - if an I/O error has occurred or if a CPIO file error has occurredpublic long skip(long n)
throws java.io.IOException
skip in class java.io.FilterInputStreamn - the number of bytes to skipjava.io.IOException - if an I/O error has occurredjava.lang.IllegalArgumentException - if n < 0Copyright © 2010 - 2024 Adobe. All Rights Reserved