Build 1.0_r1(from source)

java.util.zip
Class ZipFile

java.lang.Object
  extended by java.util.zip.ZipFile
All Implemented Interfaces:
ZipConstants
Direct Known Subclasses:
JarFile

public class ZipFile
extends Object
implements ZipConstants

This class provides read-only random access to a Zip archive. The easy way to do this would be to use ZipInputStream to scan out the entries. This is less efficient than reading the central directory, because it requires performing small reads at points across the entire file, rather than reading one concentrated blob. Use ZipOutputStream if you want to create an archive.


Nested Class Summary
(package private) static class ZipFile.RAFStream
           
 
Field Summary
(package private)  String fileName
           
(package private)  File fileToDeleteOnClose
           
(package private)  ZipEntry.LittleEndianReader ler
           
static int OPEN_DELETE
          Delete zip file when closed.
static int OPEN_READ
          Open zip file for read.
 
Fields inherited from interface java.util.zip.ZipConstants
CENATT, CENATX, CENCOM, CENCRC, CENDSK, CENEXT, CENFLG, CENHDR, CENHOW, CENLEN, CENNAM, CENOFF, CENSIG, CENSIZ, CENTIM, CENVEM, CENVER, ENDCOM, ENDHDR, ENDOFF, ENDSIG, ENDSIZ, ENDSUB, ENDTOT, EXTCRC, EXTHDR, EXTLEN, EXTSIG, EXTSIZ, LOCCRC, LOCEXT, LOCFLG, LOCHDR, LOCHOW, LOCLEN, LOCNAM, LOCSIG, LOCSIZ, LOCTIM, LOCVER
 
Constructor Summary
ZipFile(File file)
          Constructs a new ZipFile opened on the specified File.
ZipFile(File file, int mode)
          Open a Zip file.
ZipFile(String name)
          Open a Zip file.
 
Method Summary
 void close()
          Close the Zip file.
 Enumeration<? extends ZipEntry> entries()
          Return an enumeration of the entries.
protected  void finalize()
          Called by the virtual machine when there are no longer any (non-weak) references to the receiver.
 ZipEntry getEntry(String entryName)
          Gets the zip entry with the specified name from this ZipFile.
 InputStream getInputStream(ZipEntry entry)
          Returns an input stream on the data of the specified ZipEntry.
 String getName()
          Gets the file name of this ZipFile.
 int size()
          Returns the number of ZipEntries in this ZipFile.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fileName

String fileName

fileToDeleteOnClose

File fileToDeleteOnClose

OPEN_READ

public static final int OPEN_READ
Open zip file for read.

See Also:
Constant Field Values

OPEN_DELETE

public static final int OPEN_DELETE
Delete zip file when closed.

See Also:
Constant Field Values

ler

ZipEntry.LittleEndianReader ler
Constructor Detail

ZipFile

public ZipFile(File file)
        throws ZipException,
               IOException
Constructs a new ZipFile opened on the specified File.

Parameters:
file - the File
Throws:
ZipException
IOException

ZipFile

public ZipFile(File file,
               int mode)
        throws IOException
Open a Zip file. "mode" must be OPEN_READ or OPEN_READ|OPEN_DELETE. The latter sets the "delete on exit" flag through a File object.

Throws:
IOException

ZipFile

public ZipFile(String name)
        throws IOException
Open a Zip file.

Throws:
IOException
Method Detail

finalize

protected void finalize()
                 throws IOException
Description copied from class: Object
Called by the virtual machine when there are no longer any (non-weak) references to the receiver. Subclasses can use this facility to guarantee that any associated resources are cleaned up before the receiver is garbage collected. Uncaught exceptions which are thrown during the running of the method cause it to terminate immediately, but are otherwise ignored.

Note: The virtual machine assumes that the implementation in class Object is empty.

Overrides:
finalize in class Object
Throws:
IOException

close

public void close()
           throws IOException
Close the Zip file. This could be called multiple times, e.g. once explicitly and again by the finalizer. The Java doc doesn't say anything about what operations like entries() or getName() are supposed to do after the file is closed.

Throws:
IOException

entries

public Enumeration<? extends ZipEntry> entries()
Return an enumeration of the entries. The entries are listed in the order in which they appear in the Zip archive.


getEntry

public ZipEntry getEntry(String entryName)
Gets the zip entry with the specified name from this ZipFile.

Parameters:
entryName - the name of the entry in the zip file
Returns:
a ZipEntry or null if the entry name does not exist in the zip file

getInputStream

public InputStream getInputStream(ZipEntry entry)
                           throws IOException
Returns an input stream on the data of the specified ZipEntry.

Parameters:
entry - the ZipEntry
Returns:
an input stream on the ZipEntry data
Throws:
IOException

getName

public String getName()
Gets the file name of this ZipFile.

Returns:
the file name of this ZipFile

size

public int size()
Returns the number of ZipEntries in this ZipFile.

Returns:
Number of entries in this file

Build 1.0_r1(from source)

Please submit a feedback, bug or feature