⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zipfile.java

📁 java源代码 请看看啊 提点宝贵的意见
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    private static native int getMethod(long jzentry);    /*     * Gets an inflater from the list of available inflaters or allocates     * a new one.     */    private Inflater getInflater() {	synchronized (inflaters) {	    int size = inflaters.size();	    if (size > 0) {		Inflater inf = (Inflater)inflaters.remove(size - 1);		inf.reset();		return inf;	    } else {		return new Inflater(true);	    }	}    }    /*     * Releases the specified inflater to the list of available inflaters.     */    private void releaseInflater(Inflater inf) {	synchronized (inflaters) {	    inflaters.add(inf);	}    }    // List of available Inflater objects for decompression    private Vector inflaters = new Vector();    /**     * Returns the path name of the ZIP file.     * @return the path name of the ZIP file     */    public String getName() {        return name;    }    /**     * Returns an enumeration of the ZIP file entries.     * @return an enumeration of the ZIP file entries     * @exception IllegalStateException if the zip file has been closed     */    public Enumeration entries() {        ensureOpen(jzfile);        return new Enumeration() {                private int i = 0;                public boolean hasMoreElements() {                    synchronized (ZipFile.this) {                        if (ZipFile.this.jzfile == 0) {                            throw new IllegalStateException("zip file closed");                        }                        ensureOpen(ZipFile.this.jzfile);                    }                    return i < total;                }                public Object nextElement() throws NoSuchElementException {                    synchronized (ZipFile.this) {                        ensureOpen(ZipFile.this.jzfile);                        if (i >= total) {                            throw new NoSuchElementException();                        }                        long jzentry = getNextEntry(jzfile, i++);                        if (jzentry == 0) {                            String message;                            if (ZipFile.this.jzfile == 0) {                                message = "ZipFile concurrently closed";                            } else {                                message = getZipMessage(ZipFile.this.jzfile);                            }                            throw new InternalError("jzentry == 0" +                                                    ",\n jzfile = " + ZipFile.this.jzfile +                                                    ",\n total = " + ZipFile.this.total +                                                    ",\n name = " + ZipFile.this.name +                                                    ",\n i = " + i +                                                    ",\n message = " + message                                );                        }                        ZipEntry ze = new ZipEntry(jzentry);                        freeEntry(jzfile, jzentry);                        return ze;                    }                }            };    }    private static native long getNextEntry(long jzfile, int i);    /**     * Returns the number of entries in the ZIP file.     * @return the number of entries in the ZIP file     * @exception IllegalStateException if the zip file has been closed     */    public int size() {        ensureOpen(jzfile);	return total;    }    /**     * Closes the ZIP file.     * <p> Closing this ZIP file will close all of the input streams     * previously returned by invocations of the {@link #getInputStream     * getInputStream} method.     *     * @throws IOException if an I/O error has occured     */    public void close() throws IOException {        synchronized (this) {            if (jzfile != 0) {                // Close the zip file                long zf = this.jzfile;                jzfile = 0;                close(zf);                // Release inflaters                synchronized (inflaters) {                    int size = inflaters.size();                    for (int i = 0; i < size; i++) {                        Inflater inf = (Inflater)inflaters.get(i);                        inf.end();                    }                }            }        }    }    /**     * Ensures that the <code>close</code> method of this ZIP file is     * called when there are no more references to it.     *     * <p>     * Since the time when GC would invoke this method is undetermined,      * it is strongly recommanded that applications invoke the <code>close</code>      * method as soon they have finished accessing this <code>ZipFile</code>.     * This will prevent holding up system resources for an undetermined      * length of time.     *      * @exception  IOException  if an I/O error occurs.     * @see        java.util.zip.ZipFile#close()     */    protected void finalize() throws IOException {        close();    }    private static native void close(long jzfile);    private void ensureOpen(long fd) {	if (fd == 0) {	    throw new IllegalStateException("zip file closed");	}    }	    /*     * Inner class implementing the input stream used to read a      * (possible compressed) zip file entry.     */    private class ZipFileInputStream extends InputStream {	private long jzentry;	// address of jzentry data	private int pos;	// current position within entry data	private int rem;	// number of remaining bytes within entry        private int size;       // uncompressed size of this entry        private ZipFile handle; // this would prevent the zip file from being GCed       	ZipFileInputStream(long jzentry, ZipFile zf) {	    pos = 0;	    rem = getCSize(jzentry);            size = getSize(jzentry);	    this.handle = zf;	    this.jzentry = jzentry;	}	public int read(byte b[], int off, int len) throws IOException {	    if (rem == 0) {		return -1;	    }	    if (len <= 0) {		return 0;	    }	    if (len > rem) {		len = rem;	    }            synchronized (ZipFile.this) {                if (ZipFile.this.jzfile == 0)                    throw new ZipException("ZipFile closed.");                len = ZipFile.read(ZipFile.this.jzfile, jzentry, pos, b,                                   off, len);            }	    if (len > 0) {		pos += len;		rem -= len;	    }	    if (rem == 0) {		close();	    }	    return len;	}	public int read() throws IOException {	    byte[] b = new byte[1];	    if (read(b, 0, 1) == 1) {		return b[0] & 0xff;	    } else {		return -1;	    }	}	public long skip(long n) {	    int len = n > rem ? rem : (int)n;	    pos += len;	    rem -= len;	    if (rem == 0) {		close();	    }	    return len;	}	public int available() {	    return rem;	}	public int size() {	    return size;	}       public void close() {           rem = 0;           synchronized (ZipFile.this) {               if (jzentry != 0 && ZipFile.this.jzfile != 0) {                   freeEntry(ZipFile.this.jzfile, jzentry);                   jzentry = 0;               }           }       }    }    private static native int read(long jzfile, long jzentry,				   int pos, byte[] b, int off, int len);    private static native int getCSize(long jzentry);    private static native int getSize(long jzentry);        // Temporary add on for bug troubleshooting    private static native String getZipMessage(long jzfile);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -