| Constructor: |
public ZipFile(String name) throws IOException {
/* Zip library is loaded from System.initializeSystemClass */
initIDs();
this(new File(name), OPEN_READ);
}
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:
ZipException - if a ZIP format error has occurred
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.
Also see:
- SecurityManager#checkRead(java.lang.String)
|
public ZipFile(File file) throws IOException, ZipException {
this(file, OPEN_READ);
}
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
|
public ZipFile(File file,
int mode) throws IOException {
if (((mode & OPEN_READ) == 0) ||
((mode & ~(OPEN_READ | OPEN_DELETE)) != 0)) {
throw new IllegalArgumentException("Illegal mode: 0x"+
Integer.toHexString(mode));
}
String name = file.getPath();
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkRead(name);
if ((mode & OPEN_DELETE) != 0) {
sm.checkDelete(name);
}
}
jzfile = open(name, mode, file.lastModified());
this.name = name;
this.total = getTotal(jzfile);
}
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:
ZipException - if a ZIP format error has occurred
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
Also see:
- SecurityManager#checkRead(java.lang.String)
- since:
1.3 -
|
| Method from java.util.zip.ZipFile Detail: |
public void close() throws IOException {
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();
}
}
}
}
}
Closes the ZIP file.
Closing this ZIP file will close all of the input streams
previously returned by invocations of the
getInputStream method. |
public Enumeration 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;
}
}
};
}
Returns an enumeration of the ZIP file entries. |
protected void finalize() throws IOException {
close();
}
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. |
public ZipEntry getEntry(String name) {
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;
}
Returns the zip file entry for the specified name, or null
if not found. |
public InputStream getInputStream(ZipEntry entry) throws IOException {
return getInputStream(entry.name);
}
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. |
public String getName() {
return name;
}
Returns the path name of the ZIP file. |
public int size() {
ensureOpen();
return total;
}
Returns the number of entries in the ZIP file. |