Spec-Zone .ru
спецификации, руководства, описания, API
JavaTM 2 Platform
Std. Ed. v1.3.1

java.util.zip
Class ZipFile

java.lang.Object
  |
  +--java.util.zip.ZipFile
All Implemented Interfaces:
java.util.zip.ZipConstants
Direct Known Subclasses:
JarFile

public class ZipFile
extends Object
implements java.util.zip.ZipConstants

This class is used to read entries from a zip file.


Field Summary
static int CENATT
           
static int CENATX
           
static int CENCOM
           
static int CENCRC
           
static int CENDSK
           
static int CENEXT
           
static int CENFLG
           
static int CENHDR
           
static int CENHOW
           
static int CENLEN
           
static int CENNAM
           
static int CENOFF
           
static long CENSIG
           
static int CENSIZ
           
static int CENTIM
           
static int CENVEM
           
static int CENVER
           
static int ENDCOM
           
static int ENDHDR
           
static int ENDOFF
           
static long ENDSIG
           
static int ENDSIZ
           
static int ENDSUB
           
static int ENDTOT
           
static int EXTCRC
           
static int EXTHDR
           
static int EXTLEN
           
static long EXTSIG
           
static int EXTSIZ
           
static int LOCCRC
           
static int LOCEXT
           
static int LOCFLG
           
static int LOCHDR
           
static int LOCHOW
           
static int LOCLEN
           
static int LOCNAM
           
static long LOCSIG
           
static int LOCSIZ
           
static int LOCTIM
           
static int LOCVER
           
static int OPEN_DELETE
          Mode flag to open a zip file and mark it for deletion.
static int OPEN_READ
          Mode flag to open a zip file for reading.
 
Constructor Summary
ZipFile(File file)
          Opens a ZIP file for reading given the specified File object.
ZipFile(File file, int mode)
          Opens a new ZipFile to read from the specified File object in the specified mode.
ZipFile(String name)
          Opens a zip file for reading.
 
Method Summary
 void close()
          Closes the ZIP file.
 Enumeration entries()
          Returns an enumeration of the ZIP file entries.
protected  void finalize()
          Ensures that the close method of this ZIP file is called when there are no more references to it.
 ZipEntry getEntry(String name)
          Returns the zip file entry for the specified name, or null if not found.
 InputStream getInputStream(ZipEntry entry)
          Returns an input stream for reading the contents of the specified zip file entry.
 String getName()
          Returns the path name of the ZIP file.
 int size()
          Returns the number of entries in the ZIP file.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPEN_READ

public static final int OPEN_READ
Mode flag to open a zip file for reading.

OPEN_DELETE

public static final int OPEN_DELETE
Mode flag to open a zip file and mark it for deletion. The file will be deleted some time between the moment that it is opened and the moment that it is closed, but its contents will remain accessible via the ZipFile object until either the close method is invoked or the virtual machine exits.

LOCSIG

public static final long LOCSIG

EXTSIG

public static final long EXTSIG

CENSIG

public static final long CENSIG

ENDSIG

public static final long ENDSIG

LOCHDR

public static final int LOCHDR

EXTHDR

public static final int EXTHDR

CENHDR

public static final int CENHDR

ENDHDR

public static final int ENDHDR

LOCVER

public static final int LOCVER

LOCFLG

public static final int LOCFLG

LOCHOW

public static final int LOCHOW

LOCTIM

public static final int LOCTIM

LOCCRC

public static final int LOCCRC

LOCSIZ

public static final int LOCSIZ

LOCLEN

public static final int LOCLEN

LOCNAM

public static final int LOCNAM

LOCEXT

public static final int LOCEXT

EXTCRC

public static final int EXTCRC

EXTSIZ

public static final int EXTSIZ

EXTLEN

public static final int EXTLEN

CENVEM

public static final int CENVEM

CENVER

public static final int CENVER

CENFLG

public static final int CENFLG

CENHOW

public static final int CENHOW

CENTIM

public static final int CENTIM

CENCRC

public static final int CENCRC

CENSIZ

public static final int CENSIZ

CENLEN

public static final int CENLEN

CENNAM

public static final int CENNAM

CENEXT

public static final int CENEXT

CENCOM

public static final int CENCOM

CENDSK

public static final int CENDSK

CENATT

public static final int CENATT

CENATX

public static final int CENATX

CENOFF

public static final int CENOFF

ENDSUB

public static final int ENDSUB

ENDTOT

public static final int ENDTOT

ENDSIZ

public static final int ENDSIZ

ENDOFF

public static final int ENDOFF

ENDCOM

public static final int ENDCOM
Constructor Detail

ZipFile

public ZipFile(String name)
        throws IOException
Opens a zip file for reading.

First, if there is a security manager, its checkRead method is called with the name argument as its argument to ensure the read is allowed.

Parameters:
name - the name of the zip file
Throws:
ZipException - if a ZIP format error has occurred
IOException - if an I/O error has occurred
SecurityException - if a security manager exists and its checkRead method doesn't allow read access to the file.
See Also:
SecurityManager.checkRead(java.lang.String)

ZipFile

public ZipFile(File file,
               int mode)
        throws IOException
Opens a new ZipFile to read from the specified File object in the specified mode. The mode argument must be either OPEN_READ or OPEN_READ | OPEN_DELETE.

First, if there is a security manager, its checkRead method is called with the name argument as its argument to ensure the read is allowed.

Parameters:
file - the ZIP file to be opened for reading
mode - the mode in which the file is to be opened
Throws:
ZipException - if a ZIP format error has occurred
IOException - if an I/O error has occurred
SecurityException - if a security manager exists and its checkRead method doesn't allow read access to the file.
IllegalArgumentException - If the mode argument is invalid
See Also:
SecurityManager.checkRead(java.lang.String)

ZipFile

public ZipFile(File file)
        throws ZipException,
               IOException
Opens a ZIP file for reading given the specified File object.
Parameters:
file - the ZIP file to be opened for reading
Throws:
ZipException - if a ZIP error has occurred
IOException - if an I/O error has occurred
Method Detail

getEntry

public ZipEntry getEntry(String name)
Returns the zip file entry for the specified name, or null if not found.
Parameters:
name - the name of the entry
Returns:
the zip file entry, or null if not found
Throws:
IllegalStateException - if the zip file has been closed

getInputStream

public InputStream getInputStream(ZipEntry entry)
                           throws IOException
Returns an input stream for reading the contents of the specified zip file entry.
Parameters:
entry - the zip file entry
Returns:
the input stream for reading the contents of the specified zip file entry.
Throws:
ZipException - if a ZIP format error has occurred
IOException - if an I/O error has occurred
IllegalStateException - if the zip file has been closed

getName

public String getName()
Returns the path name of the ZIP file.
Returns:
the path name of the ZIP file

entries

public Enumeration entries()
Returns an enumeration of the ZIP file entries.
Returns:
an enumeration of the ZIP file entries
Throws:
IllegalStateException - if the zip file has been closed

size

public int size()
Returns the number of entries in the ZIP file.
Returns:
the number of entries in the ZIP file
Throws:
IllegalStateException - if the zip file has been closed

close

public void close()
           throws IOException
Closes the ZIP file.
Throws:
IOException - if an I/O error has occured

finalize

protected void finalize()
                 throws IOException
Ensures that the close method of this ZIP file is called when there are no more references to it.

Since the time when GC would invoke this method is undetermined, it is strongly recommanded that applications invoke the close method as soon they have finished accessing this ZipFile. This will prevent holding up system resources for an undetermined length of time.

Overrides:
finalize in class Object
Throws:
IOException - if an I/O error occurs.
See Also:
close()

JavaTM 2 Platform
Std. Ed. v1.3.1

Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2001 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.

free hit counter