java.util.zip

Class ZipFile

Implemented Interfaces:
java.util.zip.ZipConstants
Known Direct Subclasses:
JarFile

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

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

Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.

Field Summary

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.

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)
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
extends ZipEntry> 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, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

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.
Field Value:
4

OPEN_READ

public static final int OPEN_READ
Mode flag to open a zip file for reading.
Field Value:
1
Usages and Demos :

View More Examples of ZipFile.OPEN_READ
   1:             this.real_file = file;
   2:             zipfile = new ZipFile(file,ZipFile.OPEN_READ);
   3:             hash.put("",new HashMap());
   4:             Enumeration en = zipfile.entries();
   5:             parse(en);

View Full Code Here
   1:     public JarConfigurationSource(File jarFile) throws IOException {
   2:         archive = new ZipFile(jarFile, ZipFile.OPEN_READ);
   3:     }
   4: 
   5:     private final static String PREFIX = "etc/";

View Full Code Here
   1:         this.filter = filter;
   2:         zip = new ZipFile(f, ZipFile.OPEN_READ);
   3:         entries = zip.entries();
   4:         ...
   5:     {
   6:         ZipFile zf = new ZipFile(f, ZipFile.OPEN_READ);
   7:         ZipEntry ety = zf.getEntry(name);
   8:         return new BufferedInputStream(zf.getInputStream(ety));
   9:     }

View Full Code Here
   1:     {
   2:         ZipFile zf = new ZipFile(f, ZipFile.OPEN_READ);
   3:         ZipEntry ety = zf.getEntry(name);
   4:         return new BufferedInputStream(zf.getInputStream(ety));
   5:     }

View Full Code Here
   1:     private static void extractResourcePathFromJar(Class cl, File jarFile, String resourcePath, File dest) throws IOException {
   2:         ZipFile z = new ZipFile(jarFile, ZipFile.OPEN_READ);
   3:         String zipStyleResourcePath = resourcePath.substring(1) + "/"; 
   4:         ZipEntry ze = z.getEntry(zipStyleResourcePath);
   5:         System.out.println( "Extracting "+resourcePath+" to " + dest.getAbsolutePath() );

View Full Code Here

Constructor Details

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
Usages and Demos :

View More Examples of ZipFile(File file)
   1:   {
   2:     ZipFile zipfile = new ZipFile( "zippedfile.zip" );
   3: 
   4:     for ( Enumeration<? extends ZipEntry> e = zipfile.entries(); e.hasMoreElements(); )
   5:     {

View Full Code Here
   1:     vstup2.close();
   2:     ZipFile archivZip = new ZipFile("test.zip");
   3:     Enumeration vycet = archivZip.entries();
   4:     while(vycet.hasMoreElements()) {
   5:       ZipEntry polozkaArchivu2 = (ZipEntry)vycet.nextElement();

View Full Code Here
   1:       {
   2:         zip  =new ZipFile((File)getPathObject());
   3:         entry=zip.getEntry(_name);
   4:         if(entry!=null)
   5:             {

View Full Code Here
   1:             String baseDirectory = "c:/temp/unpack";
   2:             ZipFile zipFile = new ZipFile("c:\\temp\\test.zip");
   3:             Enumeration entries = zipFile.entries();
   4:             while (entries.hasMoreElements()) {
   5:                 ZipEntry entry = (ZipEntry)entries.nextElement();

View Full Code Here
   1:         cpi.out("KMInstallAnalJar "+masterJar.getPath()+"...");
   2:         ZipFile zf = new ZipFile(masterJar);
   3:         Enumeration e = zf.entries();
   4:         ...
   5:     updaters.add(updater);
   6:     ZipFile zf = new ZipFile(updater);
   7:     Enumeration e = zf.entries();
   8:         ...
   9:     for(i=0; i<zfchg.length; i++) zfchg[i] =
  10:         new ZipFile(updaters.get(i));
  11:     ZipFile zfmast = null;

View Full Code Here

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:
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, or its checkDelete method doesn't allow deleting the file when the OPEN_DELETE flag is set.
IllegalArgumentException - if the mode argument is invalid
Usages and Demos :

View More Examples of ZipFile(File file,int mode)
   1:             this.real_file = file;
   2:             zipfile = new ZipFile(file,ZipFile.OPEN_READ);
   3:             hash.put("",new HashMap());
   4:             Enumeration en = zipfile.entries();
   5:             parse(en);

View Full Code Here
   1:     public JarConfigurationSource(File jarFile) throws IOException {
   2:         archive = new ZipFile(jarFile, ZipFile.OPEN_READ);
   3:     }
   4: 
   5:     private final static String PREFIX = "etc/";

View Full Code Here
   1:         this.filter = filter;
   2:         zip = new ZipFile(f, ZipFile.OPEN_READ);
   3:         entries = zip.entries();
   4:         ...
   5:     {
   6:         ZipFile zf = new ZipFile(f, ZipFile.OPEN_READ);
   7:         ZipEntry ety = zf.getEntry(name);
   8:         return new BufferedInputStream(zf.getInputStream(ety));
   9:     }

View Full Code Here
   1:     {
   2:         ZipFile zf = new ZipFile(f, ZipFile.OPEN_READ);
   3:         ZipEntry ety = zf.getEntry(name);
   4:         return new BufferedInputStream(zf.getInputStream(ety));
   5:     }

View Full Code Here
   1:     private static void extractResourcePathFromJar(Class cl, File jarFile, String resourcePath, File dest) throws IOException {
   2:         ZipFile z = new ZipFile(jarFile, ZipFile.OPEN_READ);
   3:         String zipStyleResourcePath = resourcePath.substring(1) + "/"; 
   4:         ZipEntry ze = z.getEntry(zipStyleResourcePath);
   5:         System.out.println( "Extracting "+resourcePath+" to " + dest.getAbsolutePath() );

View Full Code Here

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:
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.
Usages and Demos :

View More Examples of ZipFile(String name)
   1:   {
   2:     ZipFile zipfile = new ZipFile( "zippedfile.zip" );
   3: 
   4:     for ( Enumeration<? extends ZipEntry> e = zipfile.entries(); e.hasMoreElements(); )
   5:     {

View Full Code Here
   1:     vstup2.close();
   2:     ZipFile archivZip = new ZipFile("test.zip");
   3:     Enumeration vycet = archivZip.entries();
   4:     while(vycet.hasMoreElements()) {
   5:       ZipEntry polozkaArchivu2 = (ZipEntry)vycet.nextElement();

View Full Code Here
   1:       {
   2:         zip  =new ZipFile((File)getPathObject());
   3:         entry=zip.getEntry(_name);
   4:         if(entry!=null)
   5:             {

View Full Code Here
   1:             String baseDirectory = "c:/temp/unpack";
   2:             ZipFile zipFile = new ZipFile("c:\\temp\\test.zip");
   3:             Enumeration entries = zipFile.entries();
   4:             while (entries.hasMoreElements()) {
   5:                 ZipEntry entry = (ZipEntry)entries.nextElement();

View Full Code Here
   1:         cpi.out("KMInstallAnalJar "+masterJar.getPath()+"...");
   2:         ZipFile zf = new ZipFile(masterJar);
   3:         Enumeration e = zf.entries();
   4:         ...
   5:     updaters.add(updater);
   6:     ZipFile zf = new ZipFile(updater);
   7:     Enumeration e = zf.entries();
   8:         ...
   9:     for(i=0; i<zfchg.length; i++) zfchg[i] =
  10:         new ZipFile(updaters.get(i));
  11:     ZipFile zfmast = null;

View Full Code Here

Method Details

close

public void close()
            throws IOException
Closes the ZIP file.

Closing this ZIP file will close all of the input streams previously returned by invocations of the getInputStream method.

Throws:
IOException - if an I/O error has occurred
Usages and Demos :

View More Examples of close()
   1:     private InputStream in;
   2:     private ZipFile     zip;
   3:     
   4:         ...
   5:     try {
   6:         in.close();
   7:     } finally {
   8:         ...
   9:         zip.close();
  10:     }
  11:         ...
  12: 
  13:     protected ZipInputStream(ZipFile zip, InputStream in) {

View Full Code Here
   1: import java.util.zip.ZipEntry;
   2: import java.util.zip.ZipFile;
   3: 
   4:         ...
   5:     {
   6:         ZipFile zf = new ZipFile(_filename);
   7:         Enumeration e = zf.entries();
   8:         ...
   9:                 } while(true);
  10:                 is.close();
  11:         ...
  12:                 baos.close();

View Full Code Here
   1: import java.util.zip.ZipEntry;
   2: import java.util.zip.ZipFile;
   3: import org.apache.tools.ant.BuildException;
   4:         ...
   5:             };
   6:             ZipFile zip = new ZipFile(source);
   7:             Enumeration e = zip.entries();
   8:         ...
   9:             
  10:             zip.close();
  11:         ...
  12:             writer.close();

View Full Code Here
   1:     final String imsFileName = "imsmanifest.xml";
   2:     ZipFile zip = null;
   3:     boolean status = true;
   4:         ...
   5:         try{
   6:             zip = new ZipFile(zipName);
   7:         }catch(IOException io){
   8:         ...
   9:             }while(len > 0);
  10:             out.close();
  11:         }else{
  12:         ...
  13:             try{
  14:                 zip.close();

View Full Code Here
   1: 
   2: import java.util.zip.ZipFile;
   3: import java.util.zip.ZipEntry;
   4:         ...
   5: {
   6:     ZipFile jar = null;
   7:     try {
   8:         ...
   9:         jar = new ZipFile(args[0]);
  10:     }
  11:         ...
  12:         }
  13:         jar.close();

View Full Code Here

extends ZipEntry> entries

public Enumerationextends ZipEntry> 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

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 recommended 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 interface Object
Throws:
IOException - if an I/O error has occurred
See Also:
close()

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
Usages and Demos :

View More Examples of getEntry(String name)
   1: import java.util.zip.ZipEntry;
   2: import java.util.zip.ZipFile;
   3: 
   4:         ...
   5:     Element resource;
   6:     ZipFile zip = null;
   7:         ...
   8:     public ContentResource(ZipFile z, Element elem) {
   9:         resource = elem;
  10:         ...
  11:     public void extractFile(String entry, String filename) throws Exception {
  12:         ZipEntry zentry = zip.getEntry(entry);

View Full Code Here
   1: import java.util.zip.ZipEntry;
   2: import java.util.zip.ZipFile;
   3: 
   4:         ...
   5:     Element resource;
   6:     ZipFile zip = null;
   7:         ...
   8:     public ContentResource(ZipFile zipFile, Element elem) {
   9:         resource = elem;
  10:         ...
  11:     public void extractFile(String entry, String filename) throws Exception {
  12:         ZipEntry zentry = zip.getEntry(entry);

View Full Code Here
   1: import java.util.zip.ZipEntry;
   2: import java.util.zip.ZipFile;
   3: 
   4:         ...
   5: 
   6:     private ZipFile zipFile;
   7: 
   8:         ...
   9:         SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
  10:         ZipEntry entry = zipFile.getEntry("index.xml");
  11:         InputStream stream = zipFile.getInputStream(entry);
  12:         ...
  13:             return null;
  14:         return zipFile.getInputStream(zipFile.getEntry(entry.getId()));

View Full Code Here
   1: import java.util.zip.ZipEntry;
   2: import java.util.zip.ZipFile;
   3: import java.util.HashMap;
   4:         ...
   5:     String dir, zname, fpermission, username;
   6:     ZipFile zip = null;
   7:     ArrayList identifiers = new ArrayList();
   8:         ...
   9:         try {
  10:             zip = new ZipFile(new File(zname));
  11:             deploy();
  12:         ...
  13:         boolean isFile = false;
  14:         String lomXml = getEntry(zip.getEntry(base + loc));

View Full Code Here
   1: import java.util.zip.ZipEntry;
   2: import java.util.zip.ZipFile;
   3: 
   4:         ...
   5:     public static boolean jarContainsResource(File file, String resource, boolean directory) {
   6:         ZipFile jarFile = null;
   7:         try {
   8:         ...
   9:             jarFile = new ZipFile(file, ZipFile.OPEN_READ);
  10:         ...
  11:             ZipEntry resourceEntry = jarFile.getEntry(resource); 

View Full Code Here

getInputStream

public InputStream getInputStream(ZipEntry entry)
            throws IOException
Returns an input stream for reading the contents of the specified zip file entry. Returns an input stream for reading the contents of the specified zip file entry.

Closing this ZIP file will, in turn, close all input streams that have been returned by invocations of this method.

Parameters:
entry - the zip file entry
Returns:
the input stream for reading the contents of the specified zip file entry.
Throws:
IOException - if an I/O error has occurred
IllegalStateException - if the zip file has been closed
Usages and Demos :

View More Examples of getInputStream(ZipEntry entry)
   1:     ZipFileProxy zip;
   2:     ZipFile zipfile;
   3:     String name, path;
   4:         ...
   5:     
   6:     public ZipEntryFileProxy(ZipFileProxy zip, ZipFile zipfile, String path, File parent) {
   7:         super("");
   8:         ...
   9:     public InputStream getInputStream() throws IOException {
  10:         return zipfile.getInputStream(entry);
  11:     }

View Full Code Here
   1:     private final static boolean DEBUG = false;
   2:     private ZipFile jar;
   3:     private URL csu;
   4:         ...
   5: 
   6:     private ZipFile getJarFile(URL url) throws IOException {
   7:         if ("file".equals(url.getProtocol())) {
   8:         ...
   9:             }
  10:             return new ZipFile(path);
  11:         }
  12:         ...
  13:                         public InputStream getInputStream() throws IOException {
  14:                             return jar.getInputStream(ze);

View Full Code Here
   1: import java.util.zip.ZipEntry;
   2: import java.util.zip.ZipFile;
   3: 
   4:         ...
   5:     
   6:     private ZipFile fZipFile;
   7:     private String fEntryName;
   8:         ...
   9: 
  10:     public JarEntryFile(ZipFile zipFile, String entryName) {
  11:         fZipFile = zipFile;
  12:         ...
  13:             ZipEntry zipEntry = fZipFile.getEntry(fEntryName);
  14:             return fZipFile.getInputStream(zipEntry);

View Full Code Here
   1: import java.util.Enumeration;
   2: import java.util.zip.ZipFile;
   3: import java.util.zip.ZipEntry;
   4:         ...
   5:     public static class JarVFS implements VFS {
   6:         private ZipFile zipfile;
   7:         
   8:         ...
   9:             try {
  10:                 return zipfile.getInputStream(ent);
  11:             } catch(IOException e) {

View Full Code Here
   1: 
   2:     ZipFile zdir;
   3: 
   4:         ...
   5: 
   6:         public Zipped(String name, ZipFile zdir, ZipEntry entry) {
   7:         this.name = name;
   8:         ...
   9:         public InputStream open() throws IOException {
  10:         return zdir.getInputStream(entry);
  11:     }

View Full Code Here

getName

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

View More Examples of getName()
   1: import java.util.zip.ZipEntry;
   2: import java.util.zip.ZipFile;
   3: 
   4:         ...
   5:     public InputStream getContents() throws CoreException {
   6:         ZipFile zipFile = null;
   7:         try {
   8:             zipFile = getZipFile();
   9:             if (JavaModelManager.ZIP_ACCESS_VERBOSE) {

View Full Code Here
   1: 
   2:     ZipFile zdir;
   3: 
   4:         ...
   5: 
   6:         public Zipped(String name, ZipFile zdir, ZipEntry entry) {
   7:         this.name = name;
   8:         ...
   9:         public String getPath() {
  10:         return zdir.getName() + "(" + entry + ")";
  11:     }

View Full Code Here
   1: import java.io.File;
   2: import java.util.zip.ZipFile;
   3: 
   4:         ...
   5:             ZipEntryStorage storage = (ZipEntryStorage)element;
   6:             ZipFile zipFile = storage.getArchive();
   7:         ...
   8:             IPath path = new Path(zipFile.getName());
   9:             IRuntimeClasspathEntry entry = JavaRuntime.newArchiveRuntimeClasspathEntry(path);
  10:         ...
  11:             if (res == null) {
  12:                 return zipFile.getName();

View Full Code Here
   1: import java.util.jar.JarFile;
   2: import java.util.zip.ZipFile;
   3: import java.util.zip.ZipEntry;
   4:         ...
   5:     private byte[] loadClassData(String name) throws ClassNotFoundException {
   6:         ZipFile jarFile = null;
   7: 
   8:         try {
   9:             jarFile = new JarFile(path);

View Full Code Here
   1: import java.io.IOException;
   2: import java.util.zip.ZipFile;
   3: 
   4:         ...
   5:         try {
   6:             new ZipFile(fileName);
   7:         } catch (IOException ioException) {
   8:         ...
   9:     public static ZipLeveledStructureProvider getZipStructureProvider(
  10:             ZipFile targetZip, Shell shell) {
  11:         if (zipProviderCache == null) {
  12:         ...
  13:             zipProviderCache = new ZipLeveledStructureProvider(targetZip);
  14:         } else if (!zipProviderCache.getZipFile().getName().equals(

View Full Code Here

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