Class ZipFile
java.lang.Object
net.sf.jazzlib.ZipFile
- All Implemented Interfaces:
ZipConstants
This class represents a Zip archive. You can ask for the contained entries,
or get an input stream for a file entry. The entry is automatically
decompressed.
This class is thread safe: You can open input streams for arbitrary entries
in different threads.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate final byte[]private final Stringstatic final intMode flag to delete a zip file after reading.static final intMode flag to open a zip file for reading.private final RandomAccessFileFields inherited from interface ZipConstants
CENATT, CENATX, CENCOM, CENCRC, CENDSK, CENEXT, CENFLG, CENHDR, CENHOW, CENLEN, CENNAM, CENOFF, CENSIG, CENSIZ, CENTIM, CENVEM, CENVER, ENDCOM, ENDDCD, ENDHDR, ENDNRD, ENDOFF, ENDSIG, ENDSIZ, ENDSUB, ENDTOT, EXTCRC, EXTHDR, EXTLEN, EXTSIG, EXTSIZ, LOCCRC, LOCEXT, LOCFLG, LOCHDR, LOCHOW, LOCLEN, LOCNAM, LOCSIG, LOCSIZ, LOCTIM, LOCVER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate longcheckLocalHeader(ZipEntry entry) Checks, if the local header of the entry at index i matches the central directory, and returns the offset to the data.voidclose()Closes the ZipFile.entries()Returns an enumeration of all Zip entries in this Zip file.protected voidfinalize()Calls theclose()method when this ZipFile has not yet been explicitly closed.Checks that the ZipFile is still open and reads entries when necessary.Searches for a zip entry in this archive with the given name.getInputStream(ZipEntry entry) Creates an input stream reading the given zip entry as uncompressed data.getName()Returns the (path) name of this zip file.private voidRead the central directory of a zip file and fill the entries array.private final intreadLeInt(byte[] b, int off) Read an int in little endian byte order from the given byte buffer at the given offset.private final intRead an int in little endian byte order from the given DataInput stream using the given byte buffer.private final intreadLeShort(byte[] b, int off) Read an unsigned short in little endian byte order from the given byte buffer at the given offset.private final intreadLeShort(DataInput di, byte[] b) Read an unsigned short in little endian byte order from the given DataInput stream using the given byte buffer.intsize()Returns the number of entries in this zip file.
-
Field Details
-
OPEN_READ
public static final int OPEN_READMode flag to open a zip file for reading.- See Also:
-
OPEN_DELETE
public static final int OPEN_DELETEMode flag to delete a zip file after reading.- See Also:
-
name
-
raf
-
entries
-
closed
private boolean closed -
locBuf
private final byte[] locBuf
-
-
Constructor Details
-
ZipFile
Opens a Zip file with the given name for reading.- Throws:
IOException- if a i/o error occured.ZipException- if the file doesn't contain a valid zip archive.
-
ZipFile
Opens a Zip file reading the given File.- Throws:
IOException- if a i/o error occured.ZipException- if the file doesn't contain a valid zip archive.
-
ZipFile
Opens a Zip file reading the given File in the given mode. If the OPEN_DELETE mode is specified, the zip file will be deleted at some time moment after it is opened. It will be deleted before the zip file is closed or the Virtual Machine exits. The contents of the zip file will be accessible until it is closed. The OPEN_DELETE mode is currently unimplemented in this library- Parameters:
mode- Must be one of OPEN_READ or OPEN_READ | OPEN_DELETE- Throws:
IOException- if a i/o error occured.ZipException- if the file doesn't contain a valid zip archive.- Since:
- JDK1.3
-
-
Method Details
-
readLeShort
Read an unsigned short in little endian byte order from the given DataInput stream using the given byte buffer.- Parameters:
di- DataInput stream to read from.b- the byte buffer to read in (must be at least 2 bytes long).- Returns:
- The value read.
- Throws:
IOException- if a i/o error occured.EOFException- if the file ends prematurely
-
readLeInt
Read an int in little endian byte order from the given DataInput stream using the given byte buffer.- Parameters:
di- DataInput stream to read from.b- the byte buffer to read in (must be at least 4 bytes long).- Returns:
- The value read.
- Throws:
IOException- if a i/o error occured.EOFException- if the file ends prematurely
-
readLeShort
private final int readLeShort(byte[] b, int off) Read an unsigned short in little endian byte order from the given byte buffer at the given offset.- Parameters:
b- the byte array to read from.off- the offset to read from.- Returns:
- The value read.
-
readLeInt
private final int readLeInt(byte[] b, int off) Read an int in little endian byte order from the given byte buffer at the given offset.- Parameters:
b- the byte array to read from.off- the offset to read from.- Returns:
- The value read.
-
readEntries
Read the central directory of a zip file and fill the entries array. This is called exactly once when first needed. It is called while holding the lock onraf.- Throws:
IOException- if a i/o error occured.ZipException- if the central directory is malformed
-
close
Closes the ZipFile. This also closes all input streams given by this class. After this is called, no further method should be called.- Throws:
IOException- if a i/o error occured.
-
finalize
Calls theclose()method when this ZipFile has not yet been explicitly closed.- Overrides:
finalizein classObject- Throws:
IOException
-
entries
Returns an enumeration of all Zip entries in this Zip file. -
getEntries
Checks that the ZipFile is still open and reads entries when necessary. -
getEntry
-
checkLocalHeader
Checks, if the local header of the entry at index i matches the central directory, and returns the offset to the data.- Parameters:
entry- to check.- Returns:
- the start offset of the (compressed) data.
- Throws:
IOException- if a i/o error occured.ZipException- if the local header doesn't match the central directory header
-
getInputStream
Creates an input stream reading the given zip entry as uncompressed data. Normally zip entry should be an entry returned by getEntry() or entries().- Parameters:
entry- the entry to create an InputStream for.- Returns:
- the input stream.
- Throws:
IOException- if a i/o error occured.ZipException- if the Zip archive is malformed.
-
getName
Returns the (path) name of this zip file. -
size
public int size()Returns the number of entries in this zip file.
-