public class TarArchiveInputStream extends ArchiveInputStream
Modifier and Type | Field and Description |
---|---|
private int |
blockSize
The size of a block
|
private TarArchiveEntry |
currEntry
The meta-data about the current entry
|
(package private) java.lang.String |
encoding |
private long |
entryOffset
How far into the entry the stream is at
|
private long |
entrySize
Size of the current entry
|
private java.util.Map<java.lang.String,java.lang.String> |
globalPaxHeaders |
private boolean |
hasHitEOF
True if file has hit EOF
|
private java.io.InputStream |
is
An input stream to read from
|
private int |
recordSize
The size the TAR header
|
private static int |
SMALL_BUFFER_SIZE |
private byte[] |
smallBuf |
private ZipEncoding |
zipEncoding
The encoding of the file
|
Constructor and Description |
---|
TarArchiveInputStream(java.io.InputStream is)
Constructor for TarInputStream.
|
TarArchiveInputStream(java.io.InputStream is,
int blockSize)
Constructor for TarInputStream.
|
TarArchiveInputStream(java.io.InputStream is,
int blockSize,
int recordSize)
Constructor for TarInputStream.
|
TarArchiveInputStream(java.io.InputStream is,
int blockSize,
int recordSize,
java.lang.String encoding)
Constructor for TarInputStream.
|
TarArchiveInputStream(java.io.InputStream is,
int blockSize,
java.lang.String encoding)
Constructor for TarInputStream.
|
TarArchiveInputStream(java.io.InputStream is,
java.lang.String encoding)
Constructor for TarInputStream.
|
Modifier and Type | Method and Description |
---|---|
private void |
applyPaxHeadersToCurrentEntry(java.util.Map<java.lang.String,java.lang.String> headers) |
int |
available()
Get the available data that can be read from the current
entry in the archive.
|
boolean |
canReadEntryData(ArchiveEntry ae)
Whether this class is able to read the given entry.
|
void |
close()
Closes this stream.
|
private void |
consumeRemainderOfLastBlock()
This method is invoked once the end of the archive is hit, it
tries to consume the remaining bytes under the assumption that
the tool creating this archive has padded the last block.
|
TarArchiveEntry |
getCurrentEntry()
Get the current TAR Archive Entry that this input stream is processing
|
protected byte[] |
getLongNameData()
Get the next entry in this tar archive as longname data.
|
ArchiveEntry |
getNextEntry()
Returns the next Archive Entry in this Stream.
|
TarArchiveEntry |
getNextTarEntry()
Get the next entry in this tar archive.
|
private byte[] |
getRecord()
Get the next record in this tar archive.
|
int |
getRecordSize()
Get the record size being used by this stream's buffer.
|
protected boolean |
isAtEOF() |
private boolean |
isDirectory() |
protected boolean |
isEOFRecord(byte[] record)
Determine if an archive record indicate End of Archive.
|
void |
mark(int markLimit)
Since we do not support marking just yet, we do nothing.
|
boolean |
markSupported()
Since we do not support marking just yet, we return false.
|
static boolean |
matches(byte[] signature,
int length)
Checks if the signature matches what is expected for a tar file.
|
(package private) java.util.Map<java.lang.String,java.lang.String> |
parsePaxHeaders(java.io.InputStream i) |
private void |
paxHeaders() |
int |
read(byte[] buf,
int offset,
int numToRead)
Reads bytes from the current tar archive entry.
|
private void |
readGlobalPaxHeaders() |
private void |
readOldGNUSparse()
Adds the sparse chunks from the current entry to the sparse chunks,
including any additional sparse entries following the current entry.
|
protected byte[] |
readRecord()
Read a record from the input stream and return the data.
|
void |
reset()
Since we do not support marking just yet, we do nothing.
|
protected void |
setAtEOF(boolean b) |
protected void |
setCurrentEntry(TarArchiveEntry e) |
long |
skip(long n)
Skips over and discards
n bytes of data from this input
stream. |
private void |
skipRecordPadding()
The last record block should be written at the full size, so skip any
additional space used to fill a record after an entry
|
private void |
tryToConsumeSecondEOFRecord()
Tries to read the next record rewinding the stream if it is not a EOF record.
|
count, count, getBytesRead, getCount, pushedBackBytes, read
private static final int SMALL_BUFFER_SIZE
private final byte[] smallBuf
private final int recordSize
private final int blockSize
private boolean hasHitEOF
private long entrySize
private long entryOffset
private final java.io.InputStream is
private TarArchiveEntry currEntry
private final ZipEncoding zipEncoding
final java.lang.String encoding
private java.util.Map<java.lang.String,java.lang.String> globalPaxHeaders
public TarArchiveInputStream(java.io.InputStream is)
is
- the input stream to usepublic TarArchiveInputStream(java.io.InputStream is, java.lang.String encoding)
is
- the input stream to useencoding
- name of the encoding to use for file namespublic TarArchiveInputStream(java.io.InputStream is, int blockSize)
is
- the input stream to useblockSize
- the block size to usepublic TarArchiveInputStream(java.io.InputStream is, int blockSize, java.lang.String encoding)
is
- the input stream to useblockSize
- the block size to useencoding
- name of the encoding to use for file namespublic TarArchiveInputStream(java.io.InputStream is, int blockSize, int recordSize)
is
- the input stream to useblockSize
- the block size to userecordSize
- the record size to usepublic TarArchiveInputStream(java.io.InputStream is, int blockSize, int recordSize, java.lang.String encoding)
is
- the input stream to useblockSize
- the block size to userecordSize
- the record size to useencoding
- name of the encoding to use for file namespublic void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
java.io.IOException
- on errorpublic int getRecordSize()
public int available() throws java.io.IOException
available
in class java.io.InputStream
java.io.IOException
- for signaturepublic long skip(long n) throws java.io.IOException
n
bytes of data from this input
stream. The skip
method may, for a variety of reasons, end
up skipping over some smaller number of bytes, possibly 0
.
This may result from any of a number of conditions; reaching end of file
or end of entry before n
bytes have been skipped; are only
two possibilities. The actual number of bytes skipped is returned. If
n
is negative, no bytes are skipped.skip
in class java.io.InputStream
n
- the number of bytes to be skipped.java.io.IOException
- if some other I/O error occurs.public boolean markSupported()
markSupported
in class java.io.InputStream
public void mark(int markLimit)
mark
in class java.io.InputStream
markLimit
- The limit to mark.public void reset()
reset
in class java.io.InputStream
public TarArchiveEntry getNextTarEntry() throws java.io.IOException
java.io.IOException
- on errorprivate void skipRecordPadding() throws java.io.IOException
java.io.IOException
protected byte[] getLongNameData() throws java.io.IOException
java.io.IOException
- on errorprivate byte[] getRecord() throws java.io.IOException
If there are no more entries in the archive, null will be
returned to indicate that the end of the archive has been
reached. At the same time the hasHitEOF
marker will be
set to true.
java.io.IOException
- on errorprotected boolean isEOFRecord(byte[] record)
record
- The record data to check.protected byte[] readRecord() throws java.io.IOException
java.io.IOException
- on errorprivate void readGlobalPaxHeaders() throws java.io.IOException
java.io.IOException
private void paxHeaders() throws java.io.IOException
java.io.IOException
java.util.Map<java.lang.String,java.lang.String> parsePaxHeaders(java.io.InputStream i) throws java.io.IOException
java.io.IOException
private void applyPaxHeadersToCurrentEntry(java.util.Map<java.lang.String,java.lang.String> headers)
private void readOldGNUSparse() throws java.io.IOException
java.io.IOException
- on errorprivate boolean isDirectory()
public ArchiveEntry getNextEntry() throws java.io.IOException
getNextEntry
in class ArchiveInputStream
null
if there are no more entriesjava.io.IOException
- if the next entry could not be readprivate void tryToConsumeSecondEOFRecord() throws java.io.IOException
This is meant to protect against cases where a tar implementation has written only one EOF record when two are expected. Actually this won't help since a non-conforming implementation likely won't fill full blocks consisting of - by default - ten records either so we probably have already read beyond the archive anyway.
java.io.IOException
public int read(byte[] buf, int offset, int numToRead) throws java.io.IOException
read
in class java.io.InputStream
buf
- The buffer into which to place bytes read.offset
- The offset at which to place bytes read.numToRead
- The number of bytes to read.java.io.IOException
- on errorpublic boolean canReadEntryData(ArchiveEntry ae)
May return false if the current entry is a sparse file.
canReadEntryData
in class ArchiveInputStream
ae
- the entry to testpublic TarArchiveEntry getCurrentEntry()
protected final void setCurrentEntry(TarArchiveEntry e)
protected final boolean isAtEOF()
protected final void setAtEOF(boolean b)
private void consumeRemainderOfLastBlock() throws java.io.IOException
java.io.IOException
public static boolean matches(byte[] signature, int length)
signature
- the bytes to checklength
- the number of bytes to check