public class ZipFileParser extends Object
ZipFile
uses a ZipFileParser
instance
to parse the contents of a Zip file. The parser objects has a few extension
points that (advanced) clients may use to teach the parser about new extra
field types, new compression methods or new kinds of external file
attributes.ZipFile
Modifier and Type | Field and Description |
---|---|
protected static long |
CENTRAL_FILE_HEADER |
protected static long |
LOCAL_FILE_HEADER |
Constructor and Description |
---|
ZipFileParser() |
Modifier and Type | Method and Description |
---|---|
protected void |
assertIsCentralFileHeader(UnsignedInteger i,
org.entityfs.RandomAccess ra)
This method throws a
ZipFileParseException if the supplied
integer's value is not the central directory header magic number. |
ZipEntryCompressionMethodRegistry |
getCompressionMethodRegistry()
Get the compression method registry used by this object.
|
ZipExternalFileAttributesParserRegistry |
getExternalFileAttributesParserRegistry()
Get the external file attributes parser registry used by this object.
|
ZipEntryExtraFieldParserRegistry |
getExtraFieldParserRegistry()
Get the extra field parser registry used by this object.
|
protected boolean |
isCentralFileHeader(UnsignedInteger i)
Does the integer contain the central directory header magic number?
|
protected boolean |
isLocalFileHeader(UnsignedInteger i)
Does the integer contain the local Zip entry header magic number?
|
ZipFileContents |
parse(ZipEntryCollaborator collaborator,
org.entityfs.RandomAccess ra,
Charset fileNameEncodingCs,
Charset textEncodingCs)
Parse the Zip file.
|
protected byte[] |
readByteArray(org.entityfs.RandomAccess ra,
int length)
Read a byte array from the random access.
|
protected String |
readString(org.entityfs.RandomAccess ra,
int length,
Charset cs,
boolean utf8Encoding)
Read a string from the random access.
|
void |
setCompressionMethodRegistry(ZipEntryCompressionMethodRegistry registry)
Set a custom compression method registry.
|
void |
setExternalFileAttributesParserRegistry(ZipExternalFileAttributesParserRegistry registry)
Set a custom external file attributes parser registry.
|
void |
setExtraFieldParserRegistry(ZipEntryExtraFieldParserRegistry registry)
Set a custom Zip entry extra field parser registry.
|
protected static final long LOCAL_FILE_HEADER
protected static final long CENTRAL_FILE_HEADER
public ZipEntryCompressionMethodRegistry getCompressionMethodRegistry()
The object returned is the actual registry used by this object. By changing its configuration, the behavior of this parser is changed.
setCompressionMethodRegistry(ZipEntryCompressionMethodRegistry)
public void setCompressionMethodRegistry(ZipEntryCompressionMethodRegistry registry)
If this is not set, a registry with the default configuration for
ZipEntryCompressionMethodRegistry
is used.
The getCompressionMethodRegistry()
method can be used to modify
the configuration of the current registry.
registry
- The new compression method registry.getCompressionMethodRegistry()
public ZipExternalFileAttributesParserRegistry getExternalFileAttributesParserRegistry()
The object returned is the actual registry used by this object. By changing its configuration, the behavior of this parser is changed.
setExternalFileAttributesParserRegistry(ZipExternalFileAttributesParserRegistry)
public void setExternalFileAttributesParserRegistry(ZipExternalFileAttributesParserRegistry registry)
If this is not set, a registry with the default configuration for
ZipExternalFileAttributesParserRegistry
is used.
The getExternalFileAttributesParserRegistry()
method can be used
to modify the configuration of the current registry.
registry
- The new registry.getExternalFileAttributesParserRegistry()
public ZipEntryExtraFieldParserRegistry getExtraFieldParserRegistry()
The object returned is the actual registry used by this object. By changing its configuration, the behavior of this object is changed.
setExtraFieldParserRegistry(ZipEntryExtraFieldParserRegistry)
public void setExtraFieldParserRegistry(ZipEntryExtraFieldParserRegistry registry)
If this is not set, the default configuration for
ZipEntryExtraFieldParserRegistry
is used.
The getExtraFieldParserRegistry()
method can be used to modify
the configuration of the current registry.
registry
- The new registry.getExtraFieldParserRegistry()
protected boolean isLocalFileHeader(UnsignedInteger i)
i
- The integer.true
if the integer contains the local Zip entry header
magic number.protected boolean isCentralFileHeader(UnsignedInteger i)
i
- The integer.true
if the integer contains the central directory header
magic number.protected void assertIsCentralFileHeader(UnsignedInteger i, org.entityfs.RandomAccess ra) throws ZipFileParseException
ZipFileParseException
if the supplied
integer's value is not the central directory header magic number.i
- The integer.ra
- The random access that the Zip file is read from.ZipFileParseException
- If the supplied integer is not the central
directory header magic number.protected String readString(org.entityfs.RandomAccess ra, int length, Charset cs, boolean utf8Encoding) throws org.entityfs.exception.UnexpectedEofException
ra
- The random access to read the string from.length
- The length of the string, in bytes.cs
- The charset to use for decoding the string, unless utf8Encoding
is set.utf8Encoding
- If this is set, the string is decoded using the UTF-8
charset no matter what the cs
argument is set to.org.entityfs.exception.UnexpectedEofException
- If the end of the file is reached before
the string data has been fully read.protected byte[] readByteArray(org.entityfs.RandomAccess ra, int length) throws org.entityfs.exception.UnexpectedEofException
ra
- The random access to read the byte array from.length
- The length of the byte array.org.entityfs.exception.UnexpectedEofException
- If the end of the file is reached before
the byte array has been fully read.public ZipFileContents parse(ZipEntryCollaborator collaborator, org.entityfs.RandomAccess ra, Charset fileNameEncodingCs, Charset textEncodingCs) throws ZipFileParseException, org.entityfs.support.exception.WrappedIOException
collaborator
- Collaborator object that is used to access the file
that the ZipFile
object is created from.ra
- A random access on the Zip file.fileNameEncodingCs
- The charset used to decode file names.textEncodingCs
- The charset used to decode other text entries, such
as Zip entry comments.ZipFile
object to initialize itself.ZipFileParseException
- If the Zip file cannot be parsed for some
reason other than an I/O error.org.entityfs.support.exception.WrappedIOException
- On I/O errors.