home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &… the Search for Life CD 3 / 0_CD-ROM.iso / install / jre1_3 / lib / rt.jar / java / util / zip / ZipFile.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  4.4 KB  |  225 lines

  1. package java.util.zip;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.security.AccessController;
  7. import java.util.Enumeration;
  8. import java.util.Vector;
  9. import sun.security.action.LoadLibraryAction;
  10.  
  11. public class ZipFile implements ZipConstants {
  12.    private long jzfile;
  13.    private String name;
  14.    private int total;
  15.    private static final int STORED = 0;
  16.    private static final int DEFLATED = 8;
  17.    public static final int OPEN_READ = 1;
  18.    public static final int OPEN_DELETE = 4;
  19.    private Vector inflaters;
  20.  
  21.    private static native void initIDs();
  22.  
  23.    public ZipFile(String var1) throws IOException {
  24.       this(new File(var1), 1);
  25.    }
  26.  
  27.    public ZipFile(File var1, int var2) throws IOException {
  28.       this.inflaters = new Vector();
  29.       if ((var2 & 1) != 0 && (var2 & -6) == 0) {
  30.          String var3 = var1.getPath();
  31.          SecurityManager var4 = System.getSecurityManager();
  32.          if (var4 != null) {
  33.             var4.checkRead(var3);
  34.          }
  35.  
  36.          this.jzfile = open(var3, var2);
  37.          this.name = var3;
  38.          this.total = getTotal(this.jzfile);
  39.       } else {
  40.          throw new IllegalArgumentException("Illegal mode: 0x" + Integer.toHexString(var2));
  41.       }
  42.    }
  43.  
  44.    private static native long open(String var0, int var1);
  45.  
  46.    private static native int getTotal(long var0);
  47.  
  48.    public ZipFile(File var1) throws ZipException, IOException {
  49.       this(var1, 1);
  50.    }
  51.  
  52.    public ZipEntry getEntry(String var1) {
  53.       if (var1 == null) {
  54.          throw new NullPointerException("name");
  55.       } else if (this.jzfile == 0L) {
  56.          throw new IllegalStateException("zip file closed");
  57.       } else {
  58.          long var2 = getEntry(this.jzfile, var1);
  59.          if (var2 == 0L && !var1.endsWith("/")) {
  60.             var2 = getEntry(this.jzfile, var1 + "/");
  61.          }
  62.  
  63.          if (var2 != 0L) {
  64.             ZipEntry var4 = new ZipEntry(var1, var2);
  65.             freeEntry(this.jzfile, var2);
  66.             return var4;
  67.          } else {
  68.             return null;
  69.          }
  70.       }
  71.    }
  72.  
  73.    private static native long getEntry(long var0, String var2);
  74.  
  75.    private static native void freeEntry(long var0, long var2);
  76.  
  77.    public InputStream getInputStream(ZipEntry var1) throws IOException {
  78.       return this.getInputStream(var1.name);
  79.    }
  80.  
  81.    private InputStream getInputStream(String var1) throws IOException {
  82.       if (var1 == null) {
  83.          throw new NullPointerException("name");
  84.       } else if (this.jzfile == 0L) {
  85.          throw new IllegalStateException("zip file closed");
  86.       } else {
  87.          long var2 = getEntry(this.jzfile, var1);
  88.          if (var2 == 0L) {
  89.             return null;
  90.          } else {
  91.             ZipFileInputStream var4 = new ZipFileInputStream(this.jzfile, var2);
  92.             switch (getMethod(var2)) {
  93.                case 0:
  94.                   return var4;
  95.                case 8:
  96.                   return new 1(this, var4, this.getInflater());
  97.                default:
  98.                   throw new ZipException("invalid compression method");
  99.             }
  100.          }
  101.       }
  102.    }
  103.  
  104.    private static native int getMethod(long var0);
  105.  
  106.    private Inflater getInflater() {
  107.       Vector var1 = this.inflaters;
  108.       synchronized(var1) {
  109.          int var2 = this.inflaters.size();
  110.          if (var2 > 0) {
  111.             Inflater var7 = (Inflater)this.inflaters.remove(var2 - 1);
  112.             var7.reset();
  113.             return var7;
  114.          } else {
  115.             Inflater var3 = new Inflater(true);
  116.             return var3;
  117.          }
  118.       }
  119.    }
  120.  
  121.    private void releaseInflater(Inflater var1) {
  122.       Vector var2 = this.inflaters;
  123.       synchronized(var2) {
  124.          this.inflaters.add(var1);
  125.       }
  126.    }
  127.  
  128.    public String getName() {
  129.       return this.name;
  130.    }
  131.  
  132.    public Enumeration entries() {
  133.       if (this.jzfile == 0L) {
  134.          throw new IllegalStateException("zip file closed");
  135.       } else {
  136.          return new 2(this);
  137.       }
  138.    }
  139.  
  140.    private static native long getNextEntry(long var0, int var2);
  141.  
  142.    public int size() {
  143.       if (this.jzfile == 0L) {
  144.          throw new IllegalStateException("zip file closed");
  145.       } else {
  146.          return this.total;
  147.       }
  148.    }
  149.  
  150.    public void close() throws IOException {
  151.       if (this.jzfile != 0L) {
  152.          long var1 = this.jzfile;
  153.          this.jzfile = 0L;
  154.          close(var1);
  155.          Vector var3 = this.inflaters;
  156.          synchronized(var3) {
  157.             int var4 = this.inflaters.size();
  158.  
  159.             for(int var5 = 0; var5 < var4; ++var5) {
  160.                Inflater var6 = (Inflater)this.inflaters.get(var5);
  161.                var6.end();
  162.             }
  163.          }
  164.       }
  165.  
  166.    }
  167.  
  168.    protected void finalize() throws IOException {
  169.       this.close();
  170.    }
  171.  
  172.    private static native void close(long var0);
  173.  
  174.    private static native int read(long var0, long var2, int var4, byte[] var5, int var6, int var7);
  175.  
  176.    private static native int getCSize(long var0);
  177.  
  178.    private static native int getSize(long var0);
  179.  
  180.    // $FF: synthetic method
  181.    static void access$000(ZipFile var0, Inflater var1) {
  182.       var0.releaseInflater(var1);
  183.    }
  184.  
  185.    // $FF: synthetic method
  186.    static int access$100(ZipFile var0) {
  187.       return var0.total;
  188.    }
  189.  
  190.    // $FF: synthetic method
  191.    static long access$200(ZipFile var0) {
  192.       return var0.jzfile;
  193.    }
  194.  
  195.    // $FF: synthetic method
  196.    static long access$300(long var0, int var2) {
  197.       return getNextEntry(var0, var2);
  198.    }
  199.  
  200.    // $FF: synthetic method
  201.    static void access$400(long var0, long var2) {
  202.       freeEntry(var0, var2);
  203.    }
  204.  
  205.    // $FF: synthetic method
  206.    static int access$500(long var0) {
  207.       return getCSize(var0);
  208.    }
  209.  
  210.    // $FF: synthetic method
  211.    static int access$600(long var0) {
  212.       return getSize(var0);
  213.    }
  214.  
  215.    // $FF: synthetic method
  216.    static int access$700(long var0, long var2, int var4, byte[] var5, int var6, int var7) {
  217.       return read(var0, var2, var4, var5, var6, var7);
  218.    }
  219.  
  220.    static {
  221.       AccessController.doPrivileged(new LoadLibraryAction("zip"));
  222.       initIDs();
  223.    }
  224. }
  225.