Top Description Fields Constructors Methods
org.apache.tools.tar

public Class TarInputStream

extends FilterInputStream
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .FilterInputStream, .IOException, .InputStream, .OutputStream, java.nio.charset.StandardCharsets, java.util.HashMap, .Map, org.apache.tools.zip.ZipEncoding, .ZipEncodingHelper

The TarInputStream reads a UNIX tar archive as an InputStream. methods are provided to position at each successive entry in the archive, and the read each entry as a normal input stream using read().

Field Summary

Modifier and TypeField and Description
protected TarBuffer
private static final int
private static final int
protected TarEntry
protected boolean
private final ZipEncoding
protected long
protected long
protected boolean
private static final int
protected byte[]
oneBuf

This contents of this array is not used at all in this class, it is only here to avoid repeated object creation during calls to the no-arg read method.

protected byte[]
private final byte[]
private final byte[]
private static final int
Inherited from java.io.FilterInputStream:
in

Constructor Summary

AccessConstructor and Description
public
TarInputStream(InputStream
the input stream to use
is
)

Constructor for TarInputStream.

public
TarInputStream(InputStream
the input stream to use
is
,
String
name of the encoding to use for file names
encoding
)

Constructor for TarInputStream.

public
TarInputStream(InputStream
the input stream to use
is
,
int
the block size to use
blockSize
)

Constructor for TarInputStream.

public
TarInputStream(InputStream
the input stream to use
is
,
int
the block size to use
blockSize
,
String
name of the encoding to use for file names
encoding
)

Constructor for TarInputStream.

public
TarInputStream(InputStream
the input stream to use
is
,
int
the block size to use
blockSize
,
int
the record size to use
recordSize
)

Constructor for TarInputStream.

public
TarInputStream(InputStream
the input stream to use
is
,
int
the block size to use
blockSize
,
int
the record size to use
recordSize
,
String
name of the encoding to use for file names
encoding
)

Constructor for TarInputStream.

Method Summary

Modifier and TypeMethod and Description
private void
public int

Returns:

The number of available bytes for the current entry.
available
()

Overrides java.io.FilterInputStream.available.

Get the available data that can be read from the current entry in the archive.
public boolean

Returns:

boolean
canReadEntryData
(TarEntry
TarEntry
te
)

Whether this class is able to read the given entry.

public void
close()

Overrides java.io.FilterInputStream.close.

Implements java.io.Closeable.close.

Closes this stream.
public void
copyEntryContents(OutputStream
The OutputStream into which to write the entry's data.
out
)

Copies the contents of the current tar archive entry directly into an output stream.

protected byte[]

Returns:

The next entry in the archive as longname data, or null.
getLongNameData
()

Get the next entry in this tar archive as longname data.

public TarEntry

Returns:

The next TarEntry in the archive, or null.
getNextEntry
()

Get the next entry in this tar archive.

private byte[]

Returns:

The next header in the archive, or null.
getRecord
()

Get the next record in this tar archive.

public int

Returns:

The TarBuffer record size.
getRecordSize
()

Get the record size being used by this stream's TarBuffer.

private boolean
public void
mark(int
The limit to mark.
markLimit
)

Overrides java.io.FilterInputStream.mark.

Since we do not support marking just yet, we do nothing.
public boolean

Returns:

False.
markSupported
()

Overrides java.io.FilterInputStream.markSupported.

Since we do not support marking just yet, we return false.
pack-priv Map<String, String>
private void
public int

Returns:

The byte read, or -1 at EOF.
read
()

Overrides java.io.FilterInputStream.read.

Reads a byte from the current tar archive entry.
public int

Returns:

The number of bytes read, or -1 at EOF.
read
(byte[]
The buffer into which to place bytes read.
buf
,
int
The offset at which to place bytes read.
offset
,
int
The number of bytes to read.
numToRead
)

Overrides java.io.FilterInputStream.read.

Reads bytes from the current tar archive entry.
private void
readGNUSparse()

Adds the sparse chunks from the current entry to the sparse chunks, including any additional sparse entries following the current entry.

public void
reset()

Overrides java.io.FilterInputStream.reset.

Since we do not support marking just yet, we do nothing.
public void
setDebug(boolean
True to turn on debugging.
debug
)

Sets the debugging flag.

public long

Returns:

the number actually skipped
skip
(long
The number of bytes to skip.
numToSkip
)

Overrides java.io.FilterInputStream.skip.

Skip bytes in the input buffer.
Inherited from java.io.FilterInputStream:
read

Field Detail

bufferback to summary
protected TarBuffer buffer
BUFFER_SIZEback to summary
private static final int BUFFER_SIZE
BYTE_MASKback to summary
private static final int BYTE_MASK
currEntryback to summary
protected TarEntry currEntry
debugback to summary
protected boolean debug
encodingback to summary
private final ZipEncoding encoding
entryOffsetback to summary
protected long entryOffset
entrySizeback to summary
protected long entrySize
hasHitEOFback to summary
protected boolean hasHitEOF
LARGE_BUFFER_SIZEback to summary
private static final int LARGE_BUFFER_SIZE
oneBufback to summary
protected byte[] oneBuf

This contents of this array is not used at all in this class, it is only here to avoid repeated object creation during calls to the no-arg read method.

readBufback to summary
protected byte[] readBuf
SKIP_BUFback to summary
private final byte[] SKIP_BUF
SMALL_BUFback to summary
private final byte[] SMALL_BUF
SMALL_BUFFER_SIZEback to summary
private static final int SMALL_BUFFER_SIZE

Constructor Detail

TarInputStreamback to summary
public TarInputStream(InputStream is)

Constructor for TarInputStream.

Parameters
is:InputStream

the input stream to use

TarInputStreamback to summary
public TarInputStream(InputStream is, String encoding)

Constructor for TarInputStream.

Parameters
is:InputStream

the input stream to use

encoding:String

name of the encoding to use for file names

TarInputStreamback to summary
public TarInputStream(InputStream is, int blockSize)

Constructor for TarInputStream.

Parameters
is:InputStream

the input stream to use

blockSize:int

the block size to use

TarInputStreamback to summary
public TarInputStream(InputStream is, int blockSize, String encoding)

Constructor for TarInputStream.

Parameters
is:InputStream

the input stream to use

blockSize:int

the block size to use

encoding:String

name of the encoding to use for file names

TarInputStreamback to summary
public TarInputStream(InputStream is, int blockSize, int recordSize)

Constructor for TarInputStream.

Parameters
is:InputStream

the input stream to use

blockSize:int

the block size to use

recordSize:int

the record size to use

TarInputStreamback to summary
public TarInputStream(InputStream is, int blockSize, int recordSize, String encoding)

Constructor for TarInputStream.

Parameters
is:InputStream

the input stream to use

blockSize:int

the block size to use

recordSize:int

the record size to use

encoding:String

name of the encoding to use for file names

Method Detail

applyPaxHeadersToCurrentEntryback to summary
private void applyPaxHeadersToCurrentEntry(Map<String, String> headers)
availableback to summary
public int available() throws IOException

Overrides java.io.FilterInputStream.available.

Get the available data that can be read from the current entry in the archive. This does not indicate how much data is left in the entire archive, only in the current entry. This value is determined from the entry's size header field and the amount of data already read from the current entry. Integer.MAX_VALUE is returned in case more than Integer.MAX_VALUE bytes are left in the current entry in the archive.

Returns:int

The number of available bytes for the current entry.

Annotations
@Override
Exceptions
IOException:
for signature
canReadEntryDataback to summary
public boolean canReadEntryData(TarEntry te)

Whether this class is able to read the given entry.

May return false if the current entry is a sparse file.

Parameters
te:TarEntry

TarEntry

Returns:boolean

boolean

closeback to summary
public void close() throws IOException

Overrides java.io.FilterInputStream.close.

Implements java.io.Closeable.close.

Closes this stream. Calls the TarBuffer's close() method.

Annotations
@Override
Exceptions
IOException:
on error
copyEntryContentsback to summary
public void copyEntryContents(OutputStream out) throws IOException

Copies the contents of the current tar archive entry directly into an output stream.

Parameters
out:OutputStream

The OutputStream into which to write the entry's data.

Exceptions
IOException:
on error
getLongNameDataback to summary
protected byte[] getLongNameData() throws IOException

Get the next entry in this tar archive as longname data.

Returns:byte[]

The next entry in the archive as longname data, or null.

Exceptions
IOException:
on error
getNextEntryback to summary
public TarEntry getNextEntry() throws IOException

Get the next entry in this tar archive. This will skip over any remaining data in the current entry, if there is one, and place the input stream at the header of the next entry, and read the header and instantiate a new TarEntry from the header bytes and return that entry. If there are no more entries in the archive, null will be returned to indicate that the end of the archive has been reached.

Returns:TarEntry

The next TarEntry in the archive, or null.

Exceptions
IOException:
on error
getRecordback to summary
private byte[] getRecord() throws IOException

Get the next record in this tar archive. This will skip over any remaining data in the current entry, if there is one, and place the input stream at the header of the next entry. If there are no more entries in the archive, null will be returned to indicate that the end of the archive has been reached.

Returns:byte[]

The next header in the archive, or null.

Exceptions
IOException:
on error
getRecordSizeback to summary
public int getRecordSize()

Get the record size being used by this stream's TarBuffer.

Returns:int

The TarBuffer record size.

isDirectoryback to summary
private boolean isDirectory()
markback to summary
public void mark(int markLimit)

Overrides java.io.FilterInputStream.mark.

Since we do not support marking just yet, we do nothing.

Parameters
markLimit:int

The limit to mark.

Annotations
@Override
markSupportedback to summary
public boolean markSupported()

Overrides java.io.FilterInputStream.markSupported.

Since we do not support marking just yet, we return false.

Returns:boolean

False.

Annotations
@Override
parsePaxHeadersback to summary
pack-priv Map<String, String> parsePaxHeaders(InputStream i) throws IOException
paxHeadersback to summary
private void paxHeaders() throws IOException
readback to summary
public int read() throws IOException

Overrides java.io.FilterInputStream.read.

Reads a byte from the current tar archive entry. This method simply calls read(byte[], int, int).

Returns:int

The byte read, or -1 at EOF.

Annotations
@Override
Exceptions
IOException:
on error
readback to summary
public int read(byte[] buf, int offset, int numToRead) throws IOException

Overrides java.io.FilterInputStream.read.

Reads bytes from the current tar archive entry. This method is aware of the boundaries of the current entry in the archive and will deal with them as if they were this stream's start and EOF.

Parameters
buf:byte[]

The buffer into which to place bytes read.

offset:int

The offset at which to place bytes read.

numToRead:int

The number of bytes to read.

Returns:int

The number of bytes read, or -1 at EOF.

Annotations
@Override
Exceptions
IOException:
on error
readGNUSparseback to summary
private void readGNUSparse() throws IOException

Adds the sparse chunks from the current entry to the sparse chunks, including any additional sparse entries following the current entry.

Exceptions
IOException:
on error
resetback to summary
public void reset()

Overrides java.io.FilterInputStream.reset.

Since we do not support marking just yet, we do nothing.

Annotations
@Override
setDebugback to summary
public void setDebug(boolean debug)

Sets the debugging flag.

Parameters
debug:boolean

True to turn on debugging.

skipback to summary
public long skip(long numToSkip) throws IOException

Overrides java.io.FilterInputStream.skip.

Skip bytes in the input buffer. This skips bytes in the current entry's data, not the entire archive, and will stop at the end of the current entry's data if the number to skip extends beyond that point.

Parameters
numToSkip:long

The number of bytes to skip.

Returns:long

the number actually skipped

Annotations
@Override
Exceptions
IOException:
on error