Top Description Fields Constructors Methods
org.apache.commons.compress.archivers

public abstract Class ArchiveInputStream<E extends org.apache.commons.compress.archivers.ArchiveEntry>

extends FilterInputStream
Class Inheritance
Known Direct Subclasses
org.apache.commons.compress.archivers.ar.ArArchiveInputStream, org.apache.commons.compress.archivers.arj.ArjArchiveInputStream, org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream, org.apache.commons.compress.archivers.dump.DumpArchiveInputStream, org.apache.commons.compress.archivers.tar.TarArchiveInputStream, org.apache.commons.compress.archivers.zip.ZipArchiveInputStream
Type Parameters
<E>
The type of ArchiveEntry produced.
Imports
java.io.FilterInputStream, .IOException, .InputStream, java.nio.charset.Charset, org.apache.commons.io.Charsets, org.apache.commons.io.input.NullInputStream

Archive input streams MUST override the read(byte[], int, int) - or read() - method so that reading from the stream generates EOF for the end of data in each entry as well as at the end of the file proper.

The getNextEntry() method is used to reset the input stream ready for reading the data from the next entry.

The input stream classes must also implement a method with the signature:

public static boolean matches(byte[] signature, int length)

which is used by the ArchiveStreamFactory to autodetect the archive type from the first few bytes of a stream.

Field Summary

Modifier and TypeField and Description
private static final int
private long
bytesRead

The number of bytes read in this stream

private Charset
private final byte[]
Inherited from java.io.FilterInputStream:
in

Constructor Summary

AccessConstructor and Description
public
ArchiveInputStream()

Constructs a new instance.

private
ArchiveInputStream(final InputStream
the underlying input stream, or null if this instance is to be created without an underlying stream.
inputStream
,
final Charset
charset.
charset
)

Constructs a new instance.

protected
ArchiveInputStream(final InputStream
the underlying input stream, or null if this instance is to be created without an underlying stream.
inputStream
,
final String
charset name.
charsetName
)

Constructs a new instance.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

This implementation always returns true.
canReadEntryData
(final ArchiveEntry
the entry to test
archiveEntry
)

Whether this stream is able to read the given entry.

protected void
count(final int
the number of bytes read
read
)

Increments the counter of already read bytes.

protected void
count(final long
the number of bytes read
read
)

Increments the counter of already read bytes.

public long

Returns:

the number of read bytes
getBytesRead
()

Gets the current number of bytes read from this stream.

public Charset

Returns:

the Charest.
getCharset
()

Gets the Charest.

public int

Returns:

the number of read bytes
getCount
()

Deprecated this method may yield wrong results for large archives, use getBytesRead() instead.
Gets the current number of bytes read from this stream.
public abstract E

Returns:

the next entry, or null if there are no more entries
getNextEntry
()

Gets the next Archive Entry in this Stream.

protected void
pushedBackBytes(final long
the number of bytes pushed back.
pushedBack
)

Decrements the counter of already read bytes.

public int

Returns:

the byte read, or -1 if end of input is reached
read
()

Overrides java.io.FilterInputStream.read.

Reads a byte of data.
Inherited from java.io.FilterInputStream:
availableclosemarkmarkSupportedreadreadresetskip

Field Detail

BYTE_MASKback to summary
private static final int BYTE_MASK
bytesReadback to summary
private long bytesRead

The number of bytes read in this stream

charsetback to summary
private Charset charset
singleback to summary
private final byte[] single

Constructor Detail

ArchiveInputStreamback to summary
public ArchiveInputStream()

Constructs a new instance.

ArchiveInputStreamback to summary
private ArchiveInputStream(final InputStream inputStream, final Charset charset)

Constructs a new instance.

Parameters
inputStream:InputStream

the underlying input stream, or null if this instance is to be created without an underlying stream.

charset:Charset

charset.

Since
1.26.0
ArchiveInputStreamback to summary
protected ArchiveInputStream(final InputStream inputStream, final String charsetName)

Constructs a new instance.

Parameters
inputStream:InputStream

the underlying input stream, or null if this instance is to be created without an underlying stream.

charsetName:String

charset name.

Since
1.26.0

Method Detail

canReadEntryDataback to summary
public boolean canReadEntryData(final ArchiveEntry archiveEntry)

Whether this stream is able to read the given entry.

Some archive formats support variants or details that are not supported (yet).

Parameters
archiveEntry:ArchiveEntry

the entry to test

Returns:boolean

This implementation always returns true.

Since
1.1
countback to summary
protected void count(final int read)

Increments the counter of already read bytes. Doesn't increment if the EOF has been hit (read == -1)

Parameters
read:int

the number of bytes read

countback to summary
protected void count(final long read)

Increments the counter of already read bytes. Doesn't increment if the EOF has been hit (read == -1)

Parameters
read:long

the number of bytes read

Since
1.1
getBytesReadback to summary
public long getBytesRead()

Gets the current number of bytes read from this stream.

Returns:long

the number of read bytes

Since
1.1
getCharsetback to summary
public Charset getCharset()

Gets the Charest.

Returns:Charset

the Charest.

getCountback to summary
public int getCount()

Deprecated

this method may yield wrong results for large archives, use getBytesRead() instead.

Gets the current number of bytes read from this stream.

Returns:int

the number of read bytes

Annotations
@Deprecated
getNextEntryback to summary
public abstract E getNextEntry() throws IOException

Gets the next Archive Entry in this Stream.

Returns:E

the next entry, or null if there are no more entries

Exceptions
IOException:
if the next entry could not be read
pushedBackBytesback to summary
protected void pushedBackBytes(final long pushedBack)

Decrements the counter of already read bytes.

Parameters
pushedBack:long

the number of bytes pushed back.

Since
1.1
readback to summary
public int read() throws IOException

Overrides java.io.FilterInputStream.read.

Reads a byte of data. This method will block until enough input is available. Simply calls the read(byte[], int, int) method. MUST be overridden if the read(byte[], int, int) method is not overridden; may be overridden otherwise.

Returns:int

the byte read, or -1 if end of input is reached

Annotations
@Override
Exceptions
IOException:
if an I/O error has occurred