public class

ZipFailSafeReader

extends Object
implements AutoCloseable
java.lang.Object
   ↳ com.pnfsoftware.jeb.util.encoding.zip.fsr.ZipFailSafeReader

Class Overview

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

Summary

Public Constructors
ZipFailSafeReader(File file)
Construct with all optional settings set to false.
ZipFailSafeReader(SeekableByteChannel channel)
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, boolean treatUnsupportedCompressionAsDeflate, boolean ignoreEncryption, boolean recoveryMode, boolean doNotParseEntries)
Construct a zip parser.
Public Methods
void close()
Iterable<ZipEntry> enumerateEntries()
Get the iterable to parse and enumerate over the zip entries.
List<ZipEntry> getEntries()
Retrieve a read-only list of the current entries.
ZipEntry getEntry(String filename)
Retrieve an entry by name.
int getNumberOfEntries()
int getOffsetAppendedData()
int getOffsetFirstEntry()
boolean hasAppendedData()
boolean hasEntry(String filename)
Determine whether an entry exists.
boolean hasPrependedData()
boolean isClosed()
boolean isTruncated()
ZipData readData(String filename)
Read an entry's data and provide the decompressed bytes.
ZipData readData(ZipEntry e)
Read an entry's data and provide the decompressed bytes.
String toString()
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.AutoCloseable

Public Constructors

public ZipFailSafeReader (File file)

Construct with all optional settings set to false.

Parameters
file input zip
Throws
IOException

public ZipFailSafeReader (SeekableByteChannel channel)

Construct with all optional settings set to false.

Parameters
channel input zip
Throws
IOException

public ZipFailSafeReader (File file, boolean treatUnsupportedCompressionAsDeflate, boolean ignoreEncryption, boolean recoveryMode, boolean doNotParseEntries)

Construct a zip parser.

Parameters
file input zip
treatUnsupportedCompressionAsDeflate optional
ignoreEncryption optional
recoveryMode optional; if true, the reader will attempt to recover zip entries of truncated files, including those with incomplete Central Directory
doNotParseEntries 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, via enumerateEntries() (this will result in faster opening of large archives)
Throws
IOException

public ZipFailSafeReader (SeekableByteChannel channel, boolean treatUnsupportedCompressionAsDeflate, boolean ignoreEncryption, boolean recoveryMode, boolean doNotParseEntries)

Construct a zip parser.

Parameters
channel input
recoveryMode optional; if true, the reader will attempt to recover zip entries of truncated files, including those with incomplete Central Directory
doNotParseEntries 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, via enumerateEntries() (this will result in faster opening of large archives)
Throws
IOException

Public Methods

public void close ()

Throws
IOException

public Iterable<ZipEntry> 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 with doNotParseEntries=true. Any IOException raised will be wrapped in a RuntimeException.

Returns
  • the iterable that will iterate and parse the zip entries

public List<ZipEntry> 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.

public ZipEntry getEntry (String filename)

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.

public int getNumberOfEntries ()

public int getOffsetAppendedData ()

public int getOffsetFirstEntry ()

public boolean hasAppendedData ()

public boolean hasEntry (String filename)

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.

public boolean hasPrependedData ()

public boolean isClosed ()

public boolean isTruncated ()

public ZipData readData (String filename)

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.@return

Throws
IOException

public ZipData readData (ZipEntry e)

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.@return

Throws
IOException

public String toString ()