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 ofArchiveEntryproduced.
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
ArArchiveInputStream,ArjArchiveInputStream,CpioArchiveInputStream,DumpArchiveInputStream,TarArchiveInputStream,ZipArchiveInputStream
public abstract class ArchiveInputStream<E extends ArchiveEntry> extends java.io.FilterInputStreamArchive input streams MUST override theFilterInputStream.read(byte[], int, int)- orread()- 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
ArchiveStreamFactoryto autodetect the archive type from the first few bytes of a stream.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classArchiveInputStream.ArchiveEntryIOIterator
-
Constructor Summary
Constructors Modifier Constructor Description ArchiveInputStream()Constructs a new instance.protectedArchiveInputStream(java.io.InputStream inputStream, java.lang.String charsetName)Constructs a new instance.privateArchiveInputStream(java.io.InputStream inputStream, java.nio.charset.Charset charset)Constructs a new instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancanReadEntryData(ArchiveEntry archiveEntry)Whether this stream is able to read the given entry.protected voidcount(int read)Increments the counter of already read bytes.protected voidcount(long read)Increments the counter of already read bytes.voidforEach(org.apache.commons.io.function.IOConsumer<? super E> action)Performs the given action for each element of the stream until all elements have been processed or the action throws an exception.longgetBytesRead()Gets the current number of bytes read from this stream.java.nio.charset.CharsetgetCharset()Gets the Charest.intgetCount()Deprecated.this method may yield wrong results for large archives, usegetBytesRead()instead.abstract EgetNextEntry()Gets the next Archive Entry in this Stream.org.apache.commons.io.function.IOIterator<E>iterator()voidmark(int readlimit)Does nothing.booleanmarkSupported()Always returns false.protected voidpushedBackBytes(long pushedBack)Decrements the counter of already read bytes.intread()Reads a byte of data.voidreset()Does nothing.
-
-
-
Field Detail
-
BYTE_MASK
private static final int BYTE_MASK
- See Also:
- Constant Field Values
-
single
private final byte[] single
-
bytesRead
private long bytesRead
The number of bytes read in this stream
-
charset
private java.nio.charset.Charset charset
-
-
Constructor Detail
-
ArchiveInputStream
public ArchiveInputStream()
Constructs a new instance.
-
ArchiveInputStream
private ArchiveInputStream(java.io.InputStream inputStream, java.nio.charset.Charset charset)Constructs a new instance.- Parameters:
inputStream- the underlying input stream, ornullif this instance is to be created without an underlying stream.charset- charset.- Since:
- 1.26.0
-
ArchiveInputStream
protected ArchiveInputStream(java.io.InputStream inputStream, java.lang.String charsetName)Constructs a new instance.- Parameters:
inputStream- the underlying input stream, ornullif this instance is to be created without an underlying stream.charsetName- charset name.- Since:
- 1.26.0
-
-
Method Detail
-
canReadEntryData
public boolean canReadEntryData(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- the entry to test- Returns:
- This implementation always returns true.
- Since:
- 1.1
-
count
protected void count(int read)
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
protected void count(long read)
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
-
forEach
public void forEach(org.apache.commons.io.function.IOConsumer<? super E> action) throws java.io.IOException
Performs the given action for each element of the stream until all elements have been processed or the action throws an exception. Actions are performed in the order of iteration. Exceptions thrown by the action are relayed to the caller.The behavior of this method is unspecified if the action performs side-effects that modify the underlying source of elements, unless an overriding class has specified a concurrent modification policy.
- Parameters:
action- The action to be performed for each element- Throws:
java.io.IOException- if an I/O error occurs.java.lang.NullPointerException- if the specified action is null- Since:
- 2.17.0
-
getBytesRead
public long getBytesRead()
Gets the current number of bytes read from this stream.- Returns:
- the number of read bytes
- Since:
- 1.1
-
getCharset
public java.nio.charset.Charset getCharset()
Gets the Charest.- Returns:
- the Charest.
-
getCount
@Deprecated public int 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
public abstract E getNextEntry() throws java.io.IOException
Gets the next Archive Entry in this Stream.- Returns:
- the next entry, or
nullif there are no more entries. - Throws:
java.io.IOException- if the next entry could not be read.
-
iterator
public org.apache.commons.io.function.IOIterator<E> iterator()
-
mark
public void mark(int readlimit)
Does nothing. TODO [COMPRESS-670] Support mark() and reset() in ArchiveInputStream.- Overrides:
markin classjava.io.FilterInputStream- Parameters:
readlimit- ignored.
-
markSupported
public boolean markSupported()
Always returns false. TODO [COMPRESS-670] Support mark() and reset() in ArchiveInputStream.- Overrides:
markSupportedin classjava.io.FilterInputStream- Returns:
- Always returns false.
-
pushedBackBytes
protected void pushedBackBytes(long pushedBack)
Decrements the counter of already read bytes.- Parameters:
pushedBack- the number of bytes pushed back.- Since:
- 1.1
-
read
public int read() throws java.io.IOExceptionReads 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:
readin classjava.io.FilterInputStream- Returns:
- the byte read, or -1 if end of input is reached
- Throws:
java.io.IOException- if an I/O error has occurred
-
reset
public void reset() throws java.io.IOExceptionDoes nothing. TODO [COMPRESS-670] Support mark() and reset() in ArchiveInputStream.- Overrides:
resetin classjava.io.FilterInputStream- Throws:
java.io.IOException- not thrown here but may be thrown from a subclass.
-
-