Methods Summary |
---|
public void | close()Closes the ZIP file.
Closing this ZIP file will close all of the input streams
previously returned by invocations of the {@link #getInputStream
getInputStream} method.
synchronized (this) {
closeRequested = true;
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();
}
}
}
}
|
private static native void | close(long jzfile)
|
private void | ensureOpen()
if (closeRequested) {
throw new IllegalStateException("zip file closed");
}
if (jzfile == 0) {
throw new IllegalStateException("The object is not initialized.");
}
|
private void | ensureOpenOrZipException()
if (closeRequested) {
throw new ZipException("ZipFile closed");
}
|
public java.util.Enumeration | entries()Returns an enumeration of the ZIP file entries.
ensureOpen();
return new Enumeration<ZipEntry>() {
private int i = 0;
public boolean hasMoreElements() {
synchronized (ZipFile.this) {
ensureOpen();
return i < total;
}
}
public ZipEntry nextElement() throws NoSuchElementException {
synchronized (ZipFile.this) {
ensureOpen();
if (i >= total) {
throw new NoSuchElementException();
}
long jzentry = getNextEntry(jzfile, i++);
if (jzentry == 0) {
String message;
if (closeRequested) {
message = "ZipFile concurrently closed";
} else {
message = getZipMessage(ZipFile.this.jzfile);
}
throw new ZipError("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;
}
}
};
|
protected void | finalize()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.
close();
|
private static native void | freeEntry(long jzfile, long jzentry)
|
private static native long | getCSize(long jzentry)
|
public java.util.zip.ZipEntry | getEntry(java.lang.String name)Returns the zip file entry for the specified name, or null
if not found.
if (name == null) {
throw new NullPointerException("name");
}
long jzentry = 0;
synchronized (this) {
ensureOpen();
jzentry = getEntry(jzfile, name, true);
if (jzentry != 0) {
ZipEntry ze = new ZipEntry(name, jzentry);
freeEntry(jzfile, jzentry);
return ze;
}
}
return null;
|
private static native long | getEntry(long jzfile, java.lang.String name, boolean addSlash)
|
private java.util.zip.Inflater | getInflater()
synchronized (inflaters) {
int size = inflaters.size();
if (size > 0) {
Inflater inf = (Inflater)inflaters.remove(size - 1);
return inf;
} else {
return new Inflater(true);
}
}
|
public java.io.InputStream | getInputStream(java.util.zip.ZipEntry 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.
return getInputStream(entry.name);
|
private java.io.InputStream | getInputStream(java.lang.String name)Returns an input stream for reading the contents of the specified
entry, or null if the entry was not found.
if (name == null) {
throw new NullPointerException("name");
}
long jzentry = 0;
ZipFileInputStream in = null;
synchronized (this) {
ensureOpen();
jzentry = getEntry(jzfile, name, false);
if (jzentry == 0) {
return null;
}
in = new ZipFileInputStream(jzentry);
}
final ZipFileInputStream zfin = in;
switch (getMethod(jzentry)) {
case STORED:
return zfin;
case DEFLATED:
// MORE: Compute good size for inflater stream:
long size = getSize(jzentry) + 2; // Inflater likes a bit of slack
if (size > 65536) size = 8192;
if (size <= 0) size = 4096;
return new InflaterInputStream(zfin, getInflater(), (int)size) {
private boolean isClosed = false;
public void close() throws IOException {
if (!isClosed) {
releaseInflater(inf);
this.in.close();
isClosed = true;
}
}
// Override fill() method to provide an extra "dummy" byte
// at the end of the input stream. This is required when
// using the "nowrap" Inflater option.
protected void fill() throws IOException {
if (eof) {
throw new EOFException(
"Unexpected end of ZLIB input stream");
}
len = this.in.read(buf, 0, buf.length);
if (len == -1) {
buf[0] = 0;
len = 1;
eof = true;
}
inf.setInput(buf, 0, len);
}
private boolean eof;
public int available() throws IOException {
if (isClosed)
return 0;
long avail = zfin.size() - inf.getBytesWritten();
return avail > (long) Integer.MAX_VALUE ?
Integer.MAX_VALUE : (int) avail;
}
};
default:
throw new ZipException("invalid compression method");
}
|
private static native int | getMethod(long jzentry)
|
public java.lang.String | getName()Returns the path name of the ZIP file.
return name;
|
private static native long | getNextEntry(long jzfile, int i)
|
private static native long | getSize(long jzentry)
|
private static native int | getTotal(long jzfile)
|
private static native java.lang.String | getZipMessage(long jzfile)
|
private static native void | initIDs()
|
private static native long | open(java.lang.String name, int mode, long lastModified)
|
private static native int | read(long jzfile, long jzentry, long pos, byte[] b, int off, int len)
|
private void | releaseInflater(java.util.zip.Inflater inf)
synchronized (inflaters) {
inf.reset();
inflaters.add(inf);
}
|
public int | size()Returns the number of entries in the ZIP file.
ensureOpen();
return total;
|