|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.schlichtherle.util.zip.BasicZipFile
de.schlichtherle.util.zip.ZipFile
public class ZipFile
Drop-in replacement for java.util.zip.ZipFile
.
Where the constructors of this class accept a charset
parameter, this is used to decode comments and entry names in the ZIP file.
However, if an entry has bit 11 set in its General Purpose Bit Flag,
then this parameter is ignored and "UTF-8" is used for this entry.
This is in accordance to Appendix D of PKWARE's ZIP File Format
Specification.
This class is able to skip a preamble like the one found in self extracting archives.
The entries returned by this class are instances of
de.schlichtherle.util.zip.ZipEntry
instead of
java.util.zip.ZipEntry
.
Note that there is no getName()
method because this method
would be meaningless when reading archive data from a ReadOnlyFile
.
This class is thread-safe.
ZipOutputStream
Field Summary |
---|
Fields inherited from class de.schlichtherle.util.zip.BasicZipFile |
---|
DEFAULT_CHARSET |
Constructor Summary | |
---|---|
ZipFile(File file)
Opens the given file for reading its ZIP contents, assuming UTF-8 charset for file names. |
|
ZipFile(File file,
String charset)
Opens the given file for reading its ZIP contents, assuming the specified charset for file names. |
|
ZipFile(File file,
String charset,
boolean preambled,
boolean postambled)
Opens the given file for reading its ZIP contents, assuming the specified charset for file names. |
|
ZipFile(ReadOnlyFile rof)
Opens the given read only file for reading its ZIP contents, assuming UTF-8 charset for file names. |
|
ZipFile(ReadOnlyFile rof,
String charset)
Opens the given read only file for reading its ZIP contents, assuming the specified charset for file names. |
|
ZipFile(ReadOnlyFile rof,
String charset,
boolean preambled,
boolean postambled)
Opens the given read only file for reading its ZIP contents, assuming the specified charset for file names. |
|
ZipFile(String name)
Opens the given file for reading its ZIP contents, assuming UTF-8 charset for file names. |
|
ZipFile(String name,
String charset)
Opens the given file for reading its ZIP contents, assuming the specified charset for file names. |
|
ZipFile(String name,
String charset,
boolean preambled,
boolean postambled)
Opens the given file for reading its ZIP contents, assuming the specified charset for file names. |
Method Summary | |
---|---|
boolean |
busy()
Returns true if and only if some input streams are open to
read from this ZIP compatible file. |
void |
close()
Closes the file. |
Enumeration |
entries()
Enumerates clones of all entries in this ZIP file. |
ZipEntry |
getEntry(String name)
Returns a clone of the ZipEntry for the given name or
null if no entry with that name exists. |
protected InputStream |
getInputStream(String name,
boolean check,
boolean inflate)
Returns an InputStream for reading the inflated or
deflated data of the given entry. |
InputStream |
getPostambleInputStream()
Returns an InputStream to read the postamble of this ZIP
compatible file. |
InputStream |
getPreambleInputStream()
Returns an InputStream to read the preamble of this ZIP
compatible file. |
Methods inherited from class de.schlichtherle.util.zip.BasicZipFile |
---|
createReadOnlyFile, createZipEntry, getCharset, getCheckedInputStream, getCheckedInputStream, getComment, getEncoding, getInputStream, getInputStream, getInputStream, getInputStream, getPostambleLength, getPreambleLength, length, offsetsConsiderPreamble, size |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ZipFile(String name) throws NullPointerException, FileNotFoundException, ZipException, IOException
name
- Name of the file.
NullPointerException
- If name
is null
.
FileNotFoundException
- If the file cannot get opened for reading.
ZipException
- If the file is not ZIP compatible.
IOException
- On any other I/O related issue.public ZipFile(String name, String charset) throws NullPointerException, UnsupportedEncodingException, FileNotFoundException, ZipException, IOException
name
- Name of the file.charset
- The charset to use for comments and entry names.
NullPointerException
- If name
or charset
is
null
.
UnsupportedEncodingException
- If charset is not supported by
this JVM.
FileNotFoundException
- If the file cannot get opened for reading.
ZipException
- If the file is not ZIP compatible.
IOException
- On any other I/O related issue.public ZipFile(String name, String charset, boolean preambled, boolean postambled) throws NullPointerException, UnsupportedEncodingException, FileNotFoundException, ZipException, IOException
name
- Name of the file.charset
- The charset to use for comments and entry names.preambled
- If this is true
, then the ZIP compatible
file may have a preamble.
Otherwise, the ZIP compatible file must start with either a
Local File Header (LFH) signature or an End Of Central Directory
(EOCD) Header, causing this constructor to fail fast if the file
is actually a false positive ZIP compatible file, i.e. not
compatible to the ZIP File Format Specification.
This may be used to read Self Extracting ZIP files (SFX), which
usually contain the application code required for extraction in
a preamble.
This parameter is true
by default.postambled
- If this is true
, then the ZIP compatible
file may have a postamble of arbitrary length.
Otherwise, the ZIP compatible file must not have a postamble
which exceeds 64KB size, including the End Of Central Directory
record (i.e. including the ZIP file comment), causing this
constructor to fail fast if the file is actually a false positive
ZIP compatible file, i.e. not compatible to the ZIP File Format
Specification.
This may be used to read Self Extracting ZIP files (SFX) with
large postambles.
This parameter is false
by default.
NullPointerException
- If name
or charset
is
null
.
UnsupportedEncodingException
- If charset is not supported by
this JVM.
FileNotFoundException
- If the file cannot get opened for reading.
ZipException
- If the file is not ZIP compatible.
IOException
- On any other I/O related issue.public ZipFile(File file) throws NullPointerException, FileNotFoundException, ZipException, IOException
file
- The file.
NullPointerException
- If file
is null
.
FileNotFoundException
- If the file cannot get opened for reading.
ZipException
- If the file is not ZIP compatible.
IOException
- On any other I/O related issue.public ZipFile(File file, String charset) throws NullPointerException, UnsupportedEncodingException, FileNotFoundException, ZipException, IOException
file
- The file.charset
- The charset to use for comments and entry names.
NullPointerException
- If file
or charset
is
null
.
UnsupportedEncodingException
- If charset is not supported by
this JVM.
FileNotFoundException
- If the file cannot get opened for reading.
ZipException
- If the file is not ZIP compatible.
IOException
- On any other I/O related issue.public ZipFile(File file, String charset, boolean preambled, boolean postambled) throws NullPointerException, UnsupportedEncodingException, FileNotFoundException, ZipException, IOException
file
- The file.charset
- The charset to use for comments and entry names.preambled
- If this is true
, then the ZIP compatible
file may have a preamble.
Otherwise, the ZIP compatible file must start with either a
Local File Header (LFH) signature or an End Of Central Directory
(EOCD) Header, causing this constructor to fail fast if the file
is actually a false positive ZIP compatible file, i.e. not
compatible to the ZIP File Format Specification.
This may be used to read Self Extracting ZIP files (SFX), which
usually contain the application code required for extraction in
a preamble.
This parameter is true
by default.postambled
- If this is true
, then the ZIP compatible
file may have a postamble of arbitrary length.
Otherwise, the ZIP compatible file must not have a postamble
which exceeds 64KB size, including the End Of Central Directory
record (i.e. including the ZIP file comment), causing this
constructor to fail fast if the file is actually a false positive
ZIP compatible file, i.e. not compatible to the ZIP File Format
Specification.
This may be used to read Self Extracting ZIP files (SFX) with
large postambles.
This parameter is false
by default.
NullPointerException
- If file
or charset
is
null
.
UnsupportedEncodingException
- If charset is not supported by
this JVM.
FileNotFoundException
- If the file cannot get opened for reading.
ZipException
- If the file is not ZIP compatible.
IOException
- On any other I/O related issue.public ZipFile(ReadOnlyFile rof) throws NullPointerException, FileNotFoundException, ZipException, IOException
rof
- The read only file.
Note that this constructor never closes this file.
NullPointerException
- If rof
is null
.
FileNotFoundException
- If the file cannot get opened for reading.
ZipException
- If the file is not ZIP compatible.
IOException
- On any other I/O related issue.public ZipFile(ReadOnlyFile rof, String charset) throws NullPointerException, UnsupportedEncodingException, FileNotFoundException, ZipException, IOException
rof
- The read only file.
Note that this constructor never closes this file.charset
- The charset to use for comments and entry names.
NullPointerException
- If rof
or charset
is null
.
UnsupportedEncodingException
- If charset is not supported by
this JVM.
FileNotFoundException
- If the file cannot get opened for reading.
ZipException
- If the file is not ZIP compatible.
IOException
- On any other I/O related issue.public ZipFile(ReadOnlyFile rof, String charset, boolean preambled, boolean postambled) throws NullPointerException, UnsupportedEncodingException, FileNotFoundException, ZipException, IOException
rof
- The read only file.
Note that this constructor never closes this file.charset
- The charset to use for comments and entry names.preambled
- If this is true
, then the ZIP compatible
file may have a preamble.
Otherwise, the ZIP compatible file must start with either a
Local File Header (LFH) signature or an End Of Central Directory
(EOCD) Header, causing this constructor to fail fast if the file
is actually a false positive ZIP compatible file, i.e. not
compatible to the ZIP File Format Specification.
This may be used to read Self Extracting ZIP files (SFX), which
usually contain the application code required for extraction in
a preamble.
This parameter is true
by default.postambled
- If this is true
, then the ZIP compatible
file may have a postamble of arbitrary length.
Otherwise, the ZIP compatible file must not have a postamble
which exceeds 64KB size, including the End Of Central Directory
record (i.e. including the ZIP file comment), causing this
constructor to fail fast if the file is actually a false positive
ZIP compatible file, i.e. not compatible to the ZIP File Format
Specification.
This may be used to read Self Extracting ZIP files (SFX) with
large postambles.
This parameter is false
by default.
NullPointerException
- If rof
or charset
is null
.
UnsupportedEncodingException
- If charset is not supported by
this JVM.
FileNotFoundException
- If the file cannot get opened for reading.
ZipException
- If the file is not ZIP compatible.
IOException
- On any other I/O related issue.Method Detail |
---|
public Enumeration entries()
entries
in class BasicZipFile
public ZipEntry getEntry(String name)
ZipEntry
for the given name or
null
if no entry with that name exists.
getEntry
in class BasicZipFile
name
- Name of the ZIP entry.public InputStream getPreambleInputStream() throws IOException
BasicZipFile
InputStream
to read the preamble of this ZIP
compatible file.
Note that the returned stream is a lightweight stream,
i.e. there is no external resource such as a ReadOnlyFile
allocated for it. Instead, all streams returned by this method share
the underlying ReadOnlyFile
of this ZipFile
.
This allows to close this object (and hence the underlying
ReadOnlyFile
) without cooperation of the returned
streams, which is important if the application wants to work on the
underlying file again (e.g. update or delete it).
getPreambleInputStream
in class BasicZipFile
ZipException
- If this ZIP file has been closed.
IOException
public InputStream getPostambleInputStream() throws IOException
BasicZipFile
InputStream
to read the postamble of this ZIP
compatible file.
Note that the returned stream is a lightweight stream,
i.e. there is no external resource such as a ReadOnlyFile
allocated for it. Instead, all streams returned by this method share
the underlying ReadOnlyFile
of this ZipFile
.
This allows to close this object (and hence the underlying
ReadOnlyFile
) without cooperation of the returned
streams, which is important if the application wants to work on the
underlying file again (e.g. update or delete it).
getPostambleInputStream
in class BasicZipFile
ZipException
- If this ZIP file has been closed.
IOException
public boolean busy()
BasicZipFile
true
if and only if some input streams are open to
read from this ZIP compatible file.
busy
in class BasicZipFile
protected InputStream getInputStream(String name, boolean check, boolean inflate) throws IOException
BasicZipFile
InputStream
for reading the inflated or
deflated data of the given entry.
If the BasicZipFile.close()
method is called on this instance, all input
streams returned by this method are closed, too.
getInputStream
in class BasicZipFile
name
- The name of the entry to get the stream for
- may not be null
!check
- Whether or not the entry's CRC-32 value is checked.
If and only if this parameter is true, two additional checks are
performed for the ZIP entry:
InputStream.close()
on the returned entry
stream, the CRC-32 value computed from the inflated entry
data is checked against the declared CRC-32 values.
This is independent from the inflate
parameter.
CRC32Exception
is thrown.
This parameter should be false
for most
applications, and is the default for the sibling of this class
in java.util.zip.ZipFile
.
inflate
- Whether or not the entry data should be inflated.
If false
, the entry data is not inflated,
even if the entry data is deflated.
This parameter should be true
for most applications.
null
if the
entry does not exist.
CRC32Exception
- If the declared CRC-32 values of the inflated
entry data are inconsistent across the entry headers.
ZipException
- If this file is not compatible to the ZIP File
Format Specification.
IOException
- If the entry cannot get read from this ZipFile.public void close() throws IOException
BasicZipFile
close
in class BasicZipFile
IOException
- if an error occurs closing the file.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |