public class ZipArchiveInputStream extends ArchiveInputStream<ZipArchiveEntry> implements InputStreamStatistics
As of Apache Commons Compress it transparently supports Zip64 extensions and thus individual entries and archives larger than 4 GB or with more than 65,536 entries.
The ZipFile
class is preferred when reading from files as ZipArchiveInputStream
is limited by not being able to read the central directory
header before returning entries. In particular ZipArchiveInputStream
ZipFile
Modifier and Type | Field and Description |
---|---|
static int |
PREAMBLE_GARBAGE_MAX_SIZE |
Constructor and Description |
---|
ZipArchiveInputStream(java.io.InputStream inputStream)
Constructs an instance using UTF-8 encoding
|
ZipArchiveInputStream(java.io.InputStream inputStream,
java.lang.String encoding)
Constructs an instance using the specified encoding
|
ZipArchiveInputStream(java.io.InputStream inputStream,
java.lang.String encoding,
boolean useUnicodeExtraFields)
Constructs an instance using the specified encoding
|
ZipArchiveInputStream(java.io.InputStream inputStream,
java.lang.String encoding,
boolean useUnicodeExtraFields,
boolean allowStoredEntriesWithDataDescriptor)
Constructs an instance using the specified encoding
|
ZipArchiveInputStream(java.io.InputStream inputStream,
java.lang.String encoding,
boolean useUnicodeExtraFields,
boolean allowStoredEntriesWithDataDescriptor,
boolean skipSplitSig)
Constructs an instance using the specified encoding
|
Modifier and Type | Method and Description |
---|---|
boolean |
canReadEntryData(ArchiveEntry ae)
Whether this class is able to read the given entry.
|
void |
close() |
long |
getCompressedCount()
Gets the amount of raw or compressed bytes read by the stream.
|
ZipArchiveEntry |
getNextEntry()
Gets the next Archive Entry in this Stream.
|
ZipArchiveEntry |
getNextZipEntry()
Deprecated.
Use
getNextEntry() . |
long |
getUncompressedCount()
Gets the uncompressed count.
|
static boolean |
matches(byte[] signature,
int length)
Checks if the signature matches what is expected for a ZIP file.
|
int |
read(byte[] buffer,
int offset,
int length) |
ZipArchiveInputStream |
setExtraFieldSupport(java.util.function.Function<ZipShort,ZipExtraField> extraFieldSupport)
Enable custom extra fields factory.
|
long |
skip(long value)
Skips over and discards value bytes of data from this input stream.
|
getBytesRead, getCharset, getCount, mark, markSupported, read, reset
public static final int PREAMBLE_GARBAGE_MAX_SIZE
public ZipArchiveInputStream(java.io.InputStream inputStream)
inputStream
- the stream to wrappublic ZipArchiveInputStream(java.io.InputStream inputStream, java.lang.String encoding)
inputStream
- the stream to wrapencoding
- the encoding to use for file names, use null for the platform's default encodingpublic ZipArchiveInputStream(java.io.InputStream inputStream, java.lang.String encoding, boolean useUnicodeExtraFields)
inputStream
- the stream to wrapencoding
- the encoding to use for file names, use null for the platform's default encodinguseUnicodeExtraFields
- whether to use InfoZIP Unicode Extra Fields (if present) to set the file names.public ZipArchiveInputStream(java.io.InputStream inputStream, java.lang.String encoding, boolean useUnicodeExtraFields, boolean allowStoredEntriesWithDataDescriptor)
inputStream
- the stream to wrapencoding
- the encoding to use for file names, use null for the platform's default encodinguseUnicodeExtraFields
- whether to use InfoZIP Unicode Extra Fields (if present) to set the file names.allowStoredEntriesWithDataDescriptor
- whether the stream will try to read STORED entries that use a data descriptorpublic ZipArchiveInputStream(java.io.InputStream inputStream, java.lang.String encoding, boolean useUnicodeExtraFields, boolean allowStoredEntriesWithDataDescriptor, boolean skipSplitSig)
inputStream
- the stream to wrapencoding
- the encoding to use for file names, use null for the platform's default encodinguseUnicodeExtraFields
- whether to use InfoZIP Unicode Extra Fields (if present) to set the file names.allowStoredEntriesWithDataDescriptor
- whether the stream will try to read STORED entries that use a data descriptorskipSplitSig
- Whether the stream will try to skip the zip split signature(08074B50) at the beginning. You will need to set
this to true if you want to read a split archive.public static boolean matches(byte[] signature, int length)
signature
- the bytes to checklength
- the number of bytes to checkpublic boolean canReadEntryData(ArchiveEntry ae)
May return false if it is set up to use encryption or a compression method that hasn't been implemented yet.
canReadEntryData
in class ArchiveInputStream<ZipArchiveEntry>
ae
- the entry to testpublic void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.FilterInputStream
java.io.IOException
public long getCompressedCount()
InputStreamStatistics
getCompressedCount
in interface InputStreamStatistics
public ZipArchiveEntry getNextEntry() throws java.io.IOException
ArchiveInputStream
getNextEntry
in class ArchiveInputStream<ZipArchiveEntry>
null
if there are no more entriesjava.io.IOException
- if the next entry could not be read@Deprecated public ZipArchiveEntry getNextZipEntry() throws java.io.IOException
getNextEntry()
.java.io.IOException
- if an I/O error occurs.public long getUncompressedCount()
getUncompressedCount
in interface InputStreamStatistics
public int read(byte[] buffer, int offset, int length) throws java.io.IOException
read
in class java.io.FilterInputStream
java.io.IOException
public ZipArchiveInputStream setExtraFieldSupport(java.util.function.Function<ZipShort,ZipExtraField> extraFieldSupport)
extraFieldSupport
- the lookup function based on extra field header id.public long skip(long value) throws java.io.IOException
This implementation may end up skipping over some smaller number of bytes, possibly 0, if and only if it reaches the end of the underlying stream.
The actual number of bytes skipped is returned.
skip
in class java.io.FilterInputStream
value
- the number of bytes to be skipped.java.io.IOException
- - if an I/O error occurs.java.lang.IllegalArgumentException
- - if value is negative.Copyright © 2010 - 2024 Adobe. All Rights Reserved