/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* This class is used to read entries from a zip file.
*
* <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
* or method in this class will cause a {@link NullPointerException} to be
* thrown.
*
* @author David Connelly
*/
public
private volatile boolean closeRequested = false;
/**
* Mode flag to open a zip file for reading.
*/
/**
* Mode flag to open a zip file and mark it for deletion. The file will be
* deleted some time between the moment that it is opened and the moment
* that it is closed, but its contents will remain accessible via the
* <tt>ZipFile</tt> object until either the close method is invoked or the
* virtual machine exits.
*/
static {
/* Zip library is loaded from System.initializeSystemClass */
initIDs();
}
private static native void initIDs();
private static final boolean usemmap;
static {
// A system prpperty to disable mmap use to avoid vm crash when
// in-use zip file is accidently overwritten by others.
}
/**
* Opens a zip file for reading.
*
* <p>First, if there is a security manager, its <code>checkRead</code>
* method is called with the <code>name</code> argument as its argument
* to ensure the read is allowed.
*
* <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
* decode the entry names and comments.
*
* @param name the name of the zip file
* @throws ZipException if a ZIP format error has occurred
* @throws IOException if an I/O error has occurred
* @throws SecurityException if a security manager exists and its
* <code>checkRead</code> method doesn't allow read access to the file.
*
* @see SecurityManager#checkRead(java.lang.String)
*/
}
/**
* Opens a new <code>ZipFile</code> to read from the specified
* <code>File</code> object in the specified mode. The mode argument
* must be either <tt>OPEN_READ</tt> or <tt>OPEN_READ | OPEN_DELETE</tt>.
*
* <p>First, if there is a security manager, its <code>checkRead</code>
* method is called with the <code>name</code> argument as its argument to
* ensure the read is allowed.
*
* <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
* decode the entry names and comments
*
* @param file the ZIP file to be opened for reading
* @param mode the mode in which the file is to be opened
* @throws ZipException if a ZIP format error has occurred
* @throws IOException if an I/O error has occurred
* @throws SecurityException if a security manager exists and
* its <code>checkRead</code> method
* doesn't allow read access to the file,
* or its <code>checkDelete</code> method doesn't allow deleting
* the file when the <tt>OPEN_DELETE</tt> flag is set.
* @throws IllegalArgumentException if the <tt>mode</tt> argument is invalid
* @see SecurityManager#checkRead(java.lang.String)
* @since 1.3
*/
}
/**
* Opens a ZIP file for reading given the specified File object.
*
* <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
* decode the entry names and comments.
*
* @param file the ZIP file to be opened for reading
* @throws ZipException if a ZIP format error has occurred
* @throws IOException if an I/O error has occurred
*/
}
/**
* Opens a new <code>ZipFile</code> to read from the specified
* <code>File</code> object in the specified mode. The mode argument
* must be either <tt>OPEN_READ</tt> or <tt>OPEN_READ | OPEN_DELETE</tt>.
*
* <p>First, if there is a security manager, its <code>checkRead</code>
* method is called with the <code>name</code> argument as its argument to
* ensure the read is allowed.
*
* @param file the ZIP file to be opened for reading
* @param mode the mode in which the file is to be opened
* @param charset
* the {@linkplain java.nio.charset.Charset charset} to
* be used to decode the ZIP entry name and comment that are not
* encoded by using UTF-8 encoding (indicated by entry's general
* purpose flag).
*
* @throws ZipException if a ZIP format error has occurred
* @throws IOException if an I/O error has occurred
*
* @throws SecurityException
* if a security manager exists and its <code>checkRead</code>
* method doesn't allow read access to the file,or its
* <code>checkDelete</code> method doesn't allow deleting the
* file when the <tt>OPEN_DELETE</tt> flag is set
*
* @throws IllegalArgumentException if the <tt>mode</tt> argument is invalid
*
* @see SecurityManager#checkRead(java.lang.String)
*
* @since 1.7
*/
{
throw new IllegalArgumentException("Illegal mode: 0x"+
}
}
}
throw new NullPointerException("charset is null");
}
/**
* Opens a zip file for reading.
*
* <p>First, if there is a security manager, its <code>checkRead</code>
* method is called with the <code>name</code> argument as its argument
* to ensure the read is allowed.
*
* @param name the name of the zip file
* @param charset
* the {@linkplain java.nio.charset.Charset charset} to
* be used to decode the ZIP entry name and comment that are not
* encoded by using UTF-8 encoding (indicated by entry's general
* purpose flag).
*
* @throws ZipException if a ZIP format error has occurred
* @throws IOException if an I/O error has occurred
* @throws SecurityException
* if a security manager exists and its <code>checkRead</code>
* method doesn't allow read access to the file
*
* @see SecurityManager#checkRead(java.lang.String)
*
* @since 1.7
*/
{
}
/**
* Opens a ZIP file for reading given the specified File object.
* @param file the ZIP file to be opened for reading
* @param charset
* The {@linkplain java.nio.charset.Charset charset} to be
* used to decode the ZIP entry name and comment (ignored if
* the <a href="package-summary.html#lang_encoding"> language
* encoding bit</a> of the ZIP entry's general purpose bit
* flag is set).
*
* @throws ZipException if a ZIP format error has occurred
* @throws IOException if an I/O error has occurred
*
* @since 1.7
*/
{
}
/**
* Returns the zip file comment, or null if none.
*
* @return the comment string for the zip file, or null if none
*
* @throws IllegalStateException if the zip file has been closed
*
* Since 1.7
*/
synchronized (this) {
ensureOpen();
return null;
}
}
/**
* Returns the zip file entry for the specified name, or null
* if not found.
*
* @param name the name of the entry
* @return the zip file entry, or null if not found
* @throws IllegalStateException if the zip file has been closed
*/
throw new NullPointerException("name");
}
long jzentry = 0;
synchronized (this) {
ensureOpen();
if (jzentry != 0) {
return ze;
}
}
return null;
}
boolean addSlash);
// freeEntry releases the C jzentry struct.
// the outstanding inputstreams that need to be closed,
// mapped to the inflater objects they use.
/**
* Returns an input stream for reading the contents of the specified
* zip file entry.
*
* <p> Closing this ZIP file will, in turn, close all input
* streams that have been returned by invocations of this method.
*
* @param entry the zip file entry
* @return the input stream for reading the contents of the specified
* zip file entry.
* @throws ZipException if a ZIP format error has occurred
* @throws IOException if an I/O error has occurred
* @throws IllegalStateException if the zip file has been closed
*/
throw new NullPointerException("entry");
}
long jzentry = 0;
synchronized (this) {
ensureOpen();
} else {
}
if (jzentry == 0) {
return null;
}
switch (getEntryMethod(jzentry)) {
case STORED:
synchronized (streams) {
}
return in;
case DEFLATED:
// MORE: Compute good size for inflater stream:
synchronized (streams) {
}
return is;
default:
throw new ZipException("invalid compression method");
}
}
}
private volatile boolean closeRequested = false;
private boolean eof = false;
int size) {
}
if (closeRequested)
return;
closeRequested = true;
super.close();
synchronized (streams) {
}
}
}
// 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.
if (eof) {
throw new EOFException("Unexpected end of ZLIB input stream");
}
if (len == -1) {
len = 1;
eof = true;
}
}
if (closeRequested)
return 0;
}
close();
}
}
/*
* Gets an inflater from the list of available inflaters or allocates
* a new one.
*/
synchronized (inflaterCache) {
return inf;
}
}
}
return new Inflater(true);
}
/*
* Releases the specified inflater to the list of available inflaters.
*/
synchronized (inflaterCache) {
}
}
}
// List of available Inflater objects for decompression
/**
* Returns the path name of the ZIP file.
* @return the path name of the ZIP file
*/
return name;
}
/**
* Returns an enumeration of the ZIP file entries.
* @return an enumeration of the ZIP file entries
* @throws IllegalStateException if the zip file has been closed
*/
ensureOpen();
return new Enumeration<ZipEntry>() {
private int i = 0;
public boolean hasMoreElements() {
synchronized (ZipFile.this) {
ensureOpen();
return i < total;
}
}
synchronized (ZipFile.this) {
ensureOpen();
if (i >= total) {
throw new NoSuchElementException();
}
if (jzentry == 0) {
if (closeRequested) {
message = "ZipFile concurrently closed";
} else {
}
throw new ZipError("jzentry == 0" +
",\n i = " + i +
",\n message = " + message
);
}
return ze;
}
}
};
}
} else {
} else {
}
}
} else {
} else {
}
}
return e;
}
/**
* Returns the number of entries in the ZIP file.
* @return the number of entries in the ZIP file
* @throws IllegalStateException if the zip file has been closed
*/
public int size() {
ensureOpen();
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 occurred
*/
if (closeRequested)
return;
closeRequested = true;
synchronized (this) {
// Close streams, release their inflaters
synchronized (streams) {
}
}
}
}
// Release cached inflaters
synchronized (inflaterCache) {
}
}
if (jzfile != 0) {
// Close the zip file
jzfile = 0;
}
}
}
/**
* Ensures that the system resources held by this ZipFile object are
* released when there are no more references to it.
*
* <p>
* Since the time when GC would invoke this method is undetermined,
* it is strongly recommended 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.
*
* @throws IOException if an I/O error has occurred
* @see java.util.zip.ZipFile#close()
*/
close();
}
private void ensureOpen() {
if (closeRequested) {
throw new IllegalStateException("zip file closed");
}
if (jzfile == 0) {
throw new IllegalStateException("The object is not initialized.");
}
}
if (closeRequested) {
throw new ZipException("ZipFile closed");
}
}
/*
* Inner class implementing the input stream used to read a
* (possibly compressed) zip file entry.
*/
private volatile boolean closeRequested = false;
pos = 0;
}
if (rem == 0) {
return -1;
}
if (len <= 0) {
return 0;
}
}
synchronized (ZipFile.this) {
}
if (len > 0) {
}
if (rem == 0) {
close();
}
return len;
}
byte[] b = new byte[1];
return b[0] & 0xff;
} else {
return -1;
}
}
public long skip(long n) {
if (n > rem)
n = rem;
pos += n;
rem -= n;
if (rem == 0) {
close();
}
return n;
}
public int available() {
}
public long size() {
return size;
}
public void close() {
if (closeRequested)
return;
closeRequested = true;
rem = 0;
synchronized (ZipFile.this) {
jzentry = 0;
}
}
synchronized (streams) {
}
}
protected void finalize() {
close();
}
}
static {
return zip.startsWithLocHeader();
}
}
);
}
/**
* Returns {@code true} if, and only if, the zip file begins with {@code
* LOCSIG}.
*/
private boolean startsWithLocHeader() {
return locsig;
}
boolean usemmap) throws IOException;
// access to the native zentry object
}