Class ZipFailSafeReader
java.lang.Object
com.pnfsoftware.jeb.util.encoding.zip.fsr.ZipFailSafeReader
- All Implemented Interfaces:
AutoCloseable
PNF Software's Zip Fail Safe Reader (PZFSR). This parser attempts to handle corner-cases that
fail Oracle's and Apache Common's parsers.
Limitations:
- limited to 2Gb archives at most
- zip64 is not supported
- uncommon flags are not supported
- non-standard attributes are disregarded
- the only compression scheme supported is DEFLATE
-
Constructor Summary
ConstructorDescriptionZipFailSafeReader
(File file) Construct with all optional settings set to false.ZipFailSafeReader
(File file, boolean treatUnsupportedCompressionAsDeflate, boolean ignoreEncryption, boolean recoveryMode, boolean doNotParseEntries) Construct a zip parser.ZipFailSafeReader
(SeekableByteChannel channel) Construct with all optional settings set to false.ZipFailSafeReader
(SeekableByteChannel channel, boolean treatUnsupportedCompressionAsDeflate, boolean ignoreEncryption, boolean recoveryMode, boolean doNotParseEntries) Construct a zip parser. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Get the iterable to parse and enumerate over the zip entries.Retrieve a read-only list of the current entries.Retrieve an entry by name.int
int
int
boolean
boolean
Determine whether an entry exists.boolean
boolean
isClosed()
boolean
Read an entry's data and provide the decompressed bytes.Read an entry's data and provide the decompressed bytes.toString()
-
Constructor Details
-
ZipFailSafeReader
Construct with all optional settings set to false.- Parameters:
file
- input zip- Throws:
IOException
-
ZipFailSafeReader
Construct with all optional settings set to false.- Parameters:
channel
- input zip- Throws:
IOException
-
ZipFailSafeReader
public ZipFailSafeReader(File file, boolean treatUnsupportedCompressionAsDeflate, boolean ignoreEncryption, boolean recoveryMode, boolean doNotParseEntries) throws IOException Construct a zip parser.- Parameters:
file
- input ziptreatUnsupportedCompressionAsDeflate
- optionalignoreEncryption
- optionalrecoveryMode
- optional; if true, the reader will attempt to recover zip entries of truncated files, including those with incomplete Central DirectorydoNotParseEntries
- optional; if true, the zip entries will not be pre-emptively parsed, and it will be up to the user to trigger parsing through enumeration, viaenumerateEntries()
(this will result in faster opening of large archives)- Throws:
IOException
-
ZipFailSafeReader
public ZipFailSafeReader(SeekableByteChannel channel, boolean treatUnsupportedCompressionAsDeflate, boolean ignoreEncryption, boolean recoveryMode, boolean doNotParseEntries) throws IOException Construct a zip parser.- Parameters:
channel
- inputtreatUnsupportedCompressionAsDeflate
-ignoreEncryption
-recoveryMode
- optional; if true, the reader will attempt to recover zip entries of truncated files, including those with incomplete Central DirectorydoNotParseEntries
- optional; if true, the zip entries will not be pre-emptively parsed, and it will be up to the user to trigger parsing through enumeration, viaenumerateEntries()
(this will result in faster opening of large archives)- Throws:
IOException
-
-
Method Details
-
enumerateEntries
Get the iterable to parse and enumerate over the zip entries. This method should be called once, and once only, if the object was constructed withdoNotParseEntries=true
. AnyIOException
raised will be wrapped in aRuntimeException
.- Returns:
- the iterable that will iterate and parse the zip entries
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
-
isClosed
public boolean isClosed() -
getOffsetFirstEntry
public int getOffsetFirstEntry() -
hasPrependedData
public boolean hasPrependedData() -
getOffsetAppendedData
public int getOffsetAppendedData() -
hasAppendedData
public boolean hasAppendedData() -
isTruncated
public boolean isTruncated() -
getNumberOfEntries
public int getNumberOfEntries() -
getEntries
Retrieve a read-only list of the current entries.This method may be called even if not all entries were enumerated (incomplete parsing). if so, it will return an incomplete list.
- Returns:
-
getEntry
Retrieve an entry by name.This method may be called even if not all entries were enumerated (incomplete parsing). It will fail if the entry has not been parsed yet.
- Parameters:
filename
-- Returns:
-
hasEntry
Determine whether an entry exists. parsed yet.This method may be called even if not all entries were enumerated (incomplete parsing). It will fail if the entry has not been parsed yet.
- Parameters:
filename
-- Returns:
-
readData
Read an entry's data and provide the decompressed bytes.This method may be called even if not all entries were enumerated (incomplete parsing). It will fail if the entry has not been parsed yet.
- Parameters:
filename
-- Returns:
- Throws:
IOException
-
readData
Read an entry's data and provide the decompressed bytes.This method may be called even if not all entries were enumerated (incomplete parsing). It will fail if the entry has not been parsed yet.
- Parameters:
e
-- Returns:
- Throws:
IOException
-
toString
-