Class ArchiveInputStream<E extends ArchiveEntry>
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.commons.compress.archivers.ArchiveInputStream<E>
- Type Parameters:
E
- The type ofArchiveEntry
produced.
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
ArArchiveInputStream
,ArjArchiveInputStream
,CpioArchiveInputStream
,DumpArchiveInputStream
,TarArchiveInputStream
,ZipArchiveInputStream
Archive input streams MUST override the
FilterInputStream.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
Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ModifierConstructorDescriptionConstructs a new instance.protected
ArchiveInputStream
(InputStream inputStream, String charsetName) Constructs a new instance. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canReadEntryData
(ArchiveEntry archiveEntry) Whether this stream is able to read the given entry.protected void
count
(int read) Increments the counter of already read bytes.protected void
count
(long read) Increments the counter of already read bytes.long
Gets the current number of bytes read from this stream.Gets the Charest.int
getCount()
Deprecated.abstract E
Gets the next Archive Entry in this Stream.void
mark
(int readlimit) Does nothing.boolean
Always returns false.protected void
pushedBackBytes
(long pushedBack) Decrements the counter of already read bytes.int
read()
Reads a byte of data.void
reset()
Does nothing.
-
Constructor Details
-
ArchiveInputStream
public ArchiveInputStream()Constructs a new instance. -
ArchiveInputStream
Constructs a new instance.- Parameters:
inputStream
- the underlying input stream, ornull
if this instance is to be created without an underlying stream.charsetName
- charset name.- Since:
- 1.26.0
-
-
Method Details
-
canReadEntryData
Whether this stream is able to read the given entry.Some archive formats support variants or details that are not supported (yet).
- Parameters:
archiveEntry
- the entry to test- Returns:
- This implementation always returns true.
- Since:
- 1.1
-
count
Increments the counter of already read bytes. Doesn't increment if the EOF has been hit (read == -1)- Parameters:
read
- the number of bytes read
-
count
Increments the counter of already read bytes. Doesn't increment if the EOF has been hit (read == -1)- Parameters:
read
- the number of bytes read- Since:
- 1.1
-
getBytesRead
Gets the current number of bytes read from this stream.- Returns:
- the number of read bytes
- Since:
- 1.1
-
getCharset
Gets the Charest.- Returns:
- the Charest.
-
getCount
Deprecated.this method may yield wrong results for large archives, usegetBytesRead()
instead.Gets the current number of bytes read from this stream.- Returns:
- the number of read bytes
-
getNextEntry
Gets the next Archive Entry in this Stream.- Returns:
- the next entry, or
null
if there are no more entries - Throws:
IOException
- if the next entry could not be read
-
mark
Does nothing. TODO [COMPRESS-670] Support mark() and reset() in ArchiveInputStream.- Overrides:
mark
in classFilterInputStream
- Parameters:
readlimit
- ignored.
-
markSupported
Always returns false. TODO [COMPRESS-670] Support mark() and reset() in ArchiveInputStream.- Overrides:
markSupported
in classFilterInputStream
- Returns:
- Always returns false.
-
pushedBackBytes
Decrements the counter of already read bytes.- Parameters:
pushedBack
- the number of bytes pushed back.- Since:
- 1.1
-
read
Reads a byte of data. This method will block until enough input is available. Simply calls theFilterInputStream.read(byte[], int, int)
method. MUST be overridden if theFilterInputStream.read(byte[], int, int)
method is not overridden; may be overridden otherwise.- Overrides:
read
in classFilterInputStream
- Returns:
- the byte read, or -1 if end of input is reached
- Throws:
IOException
- if an I/O error has occurred
-
reset
Does nothing. TODO [COMPRESS-670] Support mark() and reset() in ArchiveInputStream.- Overrides:
reset
in classFilterInputStream
- Throws:
IOException
- not thrown here but may be thrown from a subclass.
-
getBytesRead()
instead.