src/share/classes/java/util/zip/ZipFile.java

Print this page




  37 import java.util.HashSet;
  38 import java.util.NoSuchElementException;
  39 import java.security.AccessController;
  40 import sun.security.action.GetPropertyAction;
  41 import static java.util.zip.ZipConstants64.*;
  42 
  43 /**
  44  * This class is used to read entries from a zip file.
  45  *
  46  * <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
  47  * or method in this class will cause a {@link NullPointerException} to be
  48  * thrown.
  49  *
  50  * @author      David Connelly
  51  */
  52 public
  53 class ZipFile implements ZipConstants, Closeable {
  54     private long jzfile;  // address of jzfile data
  55     private String name;  // zip file name
  56     private int total;    // total number of entries
  57     private boolean closeRequested;
  58 
  59     private static final int STORED = ZipEntry.STORED;
  60     private static final int DEFLATED = ZipEntry.DEFLATED;
  61 
  62     /**
  63      * Mode flag to open a zip file for reading.
  64      */
  65     public static final int OPEN_READ = 0x1;
  66 
  67     /**
  68      * Mode flag to open a zip file and mark it for deletion.  The file will be
  69      * deleted some time between the moment that it is opened and the moment
  70      * that it is closed, but its contents will remain accessible via the
  71      * <tt>ZipFile</tt> object until either the close method is invoked or the
  72      * virtual machine exits.
  73      */
  74     public static final int OPEN_DELETE = 0x4;
  75 
  76     static {
  77         /* Zip library is loaded from System.initializeSystemClass */


 406     /*
 407      * Gets an inflater from the list of available inflaters or allocates
 408      * a new one.
 409      */
 410     private Inflater getInflater() {
 411         synchronized (inflaters) {
 412             int size = inflaters.size();
 413             if (size > 0) {
 414                 Inflater inf = (Inflater)inflaters.remove(size - 1);
 415                 return inf;
 416             } else {
 417                 return new Inflater(true);
 418             }
 419         }
 420     }
 421 
 422     /*
 423      * Releases the specified inflater to the list of available inflaters.
 424      */
 425     private void releaseInflater(Inflater inf) {




 426         synchronized (inflaters) {
 427             inf.reset();
 428             inflaters.add(inf);
 429         }
 430     }
 431 
 432     // List of available Inflater objects for decompression
 433     private Vector inflaters = new Vector();
 434 
 435     /**
 436      * Returns the path name of the ZIP file.
 437      * @return the path name of the ZIP file
 438      */
 439     public String getName() {
 440         return name;
 441     }
 442 
 443     /**
 444      * Returns an enumeration of the ZIP file entries.
 445      * @return an enumeration of the ZIP file entries




  37 import java.util.HashSet;
  38 import java.util.NoSuchElementException;
  39 import java.security.AccessController;
  40 import sun.security.action.GetPropertyAction;
  41 import static java.util.zip.ZipConstants64.*;
  42 
  43 /**
  44  * This class is used to read entries from a zip file.
  45  *
  46  * <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
  47  * or method in this class will cause a {@link NullPointerException} to be
  48  * thrown.
  49  *
  50  * @author      David Connelly
  51  */
  52 public
  53 class ZipFile implements ZipConstants, Closeable {
  54     private long jzfile;  // address of jzfile data
  55     private String name;  // zip file name
  56     private int total;    // total number of entries
  57     private volatile boolean closeRequested;
  58 
  59     private static final int STORED = ZipEntry.STORED;
  60     private static final int DEFLATED = ZipEntry.DEFLATED;
  61 
  62     /**
  63      * Mode flag to open a zip file for reading.
  64      */
  65     public static final int OPEN_READ = 0x1;
  66 
  67     /**
  68      * Mode flag to open a zip file and mark it for deletion.  The file will be
  69      * deleted some time between the moment that it is opened and the moment
  70      * that it is closed, but its contents will remain accessible via the
  71      * <tt>ZipFile</tt> object until either the close method is invoked or the
  72      * virtual machine exits.
  73      */
  74     public static final int OPEN_DELETE = 0x4;
  75 
  76     static {
  77         /* Zip library is loaded from System.initializeSystemClass */


 406     /*
 407      * Gets an inflater from the list of available inflaters or allocates
 408      * a new one.
 409      */
 410     private Inflater getInflater() {
 411         synchronized (inflaters) {
 412             int size = inflaters.size();
 413             if (size > 0) {
 414                 Inflater inf = (Inflater)inflaters.remove(size - 1);
 415                 return inf;
 416             } else {
 417                 return new Inflater(true);
 418             }
 419         }
 420     }
 421 
 422     /*
 423      * Releases the specified inflater to the list of available inflaters.
 424      */
 425     private void releaseInflater(Inflater inf) {
 426         if (closeRequested) {
 427            inf.end();
 428            return;
 429         }
 430         synchronized (inflaters) {
 431             inf.reset();
 432             inflaters.add(inf);
 433         }
 434     }
 435 
 436     // List of available Inflater objects for decompression
 437     private Vector inflaters = new Vector();
 438 
 439     /**
 440      * Returns the path name of the ZIP file.
 441      * @return the path name of the ZIP file
 442      */
 443     public String getName() {
 444         return name;
 445     }
 446 
 447     /**
 448      * Returns an enumeration of the ZIP file entries.
 449      * @return an enumeration of the ZIP file entries