/*
* 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 implements an input stream filter for reading files in the
* ZIP file format. Includes support for both compressed and uncompressed
* entries.
*
* @author David Connelly
*/
public
private int flag;
private long remaining;
private boolean closed = false;
// this flag is set to true after EOF has reached for
// one entry
private boolean entryEOF = false;
/**
* Check to make sure that this stream has not been closed
*/
if (closed) {
throw new IOException("Stream closed");
}
}
/**
* Creates a new ZIP input stream.
*
* <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
* decode the entry names.
*
* @param in the actual input stream
*/
}
/**
* Creates a new ZIP input stream.
*
* @param in the actual input stream
*
* @param charset
* The {@linkplain java.nio.charset.Charset charset} to be
* used to decode the ZIP entry name (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).
*
* @since 1.7
*/
usesDefaultInflater = true;
throw new NullPointerException("in is null");
}
throw new NullPointerException("charset is null");
}
/**
* Reads the next ZIP file entry and positions the stream at the
* beginning of the entry data.
* @return the next ZIP file entry, or null if there are no more entries
* @exception ZipException if a ZIP file error has occurred
* @exception IOException if an I/O error has occurred
*/
ensureOpen();
closeEntry();
}
return null;
}
}
entryEOF = false;
return entry;
}
/**
* Closes the current ZIP entry and positions the stream for reading the
* next entry.
* @exception ZipException if a ZIP file error has occurred
* @exception IOException if an I/O error has occurred
*/
ensureOpen();
entryEOF = true;
}
/**
* Returns 0 after EOF has reached for the current entry data,
* otherwise always return 1.
* <p>
* Programs should not count on this method to return the actual number
* of bytes that could be read without blocking.
*
* @return 1 before EOF and 0 after EOF has reached for current entry.
* @exception IOException if an I/O error occurs.
*
*/
ensureOpen();
if (entryEOF) {
return 0;
} else {
return 1;
}
}
/**
* Reads from the current ZIP entry into an array of bytes.
* If <code>len</code> is not zero, the method
* blocks until some input is available; otherwise, no
* bytes are read and <code>0</code> is returned.
* @param b the buffer into which the data is read
* @param off the start offset in the destination array <code>b</code>
* @param len the maximum number of bytes read
* @return the actual number of bytes read, or -1 if the end of the
* entry is reached
* @exception NullPointerException if <code>b</code> is <code>null</code>.
* @exception IndexOutOfBoundsException if <code>off</code> is negative,
* <code>len</code> is negative, or <code>len</code> is greater than
* <code>b.length - off</code>
* @exception ZipException if a ZIP file error has occurred
* @exception IOException if an I/O error has occurred
*/
ensureOpen();
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
return -1;
}
case DEFLATED:
if (len == -1) {
entryEOF = true;
} else {
}
return len;
case STORED:
if (remaining <= 0) {
entryEOF = true;
return -1;
}
}
if (len == -1) {
throw new ZipException("unexpected EOF");
}
throw new ZipException(
}
return len;
default:
throw new ZipException("invalid compression method");
}
}
/**
* Skips specified number of bytes in the current ZIP entry.
* @param n the number of bytes to skip
* @return the actual number of bytes skipped
* @exception ZipException if a ZIP file error has occurred
* @exception IOException if an I/O error has occurred
* @exception IllegalArgumentException if n < 0
*/
if (n < 0) {
throw new IllegalArgumentException("negative skip length");
}
ensureOpen();
int total = 0;
}
if (len == -1) {
entryEOF = true;
break;
}
}
return total;
}
/**
* Closes this input stream and releases any system resources associated
* with the stream.
* @exception IOException if an I/O error has occurred
*/
if (!closed) {
super.close();
closed = true;
}
}
private byte[] b = new byte[256];
/*
* Reads local file (LOC) header for next entry.
*/
try {
} catch (EOFException e) {
return null;
}
return null;
}
// get flag first, we need check EFS.
// get the entry name and create the ZipEntry first
do
b = new byte[blen];
}
// Force to use UTF-8 if the EFS bit is ON, even the cs is NOT UTF-8
// now get the remaining fields for the entry
throw new ZipException("encrypted ZIP entry not supported");
}
/* "Data Descriptor" present */
throw new ZipException(
"only DEFLATED entries can have EXT descriptor");
}
} else {
}
if (len > 0) {
// extra fields are in "HeaderID(2)DataSize(2)Data... format
int off = 0;
off += 4;
// LOC extra zip64 entry MUST include BOTH original and
// compressed file size fields
// Invalid zip64 extra fields, simply skip. Even it's
// rare, it's possible the entry size happens to be
// the magic value and it "accidnetly" has some bytes
// in extra match the id.
return e;
}
break;
}
}
}
}
return e;
}
/**
* Creates a new <code>ZipEntry</code> object for the specified
* entry name.
*
* @param name the ZIP file entry name
* @return the ZipEntry just created
*/
}
/*
* Reads end of deflated entry as well as EXT descriptor if present.
*/
int n = inf.getRemaining();
if (n > 0) {
}
/* "Data Descriptor" present */
// ZIP64 format
} else {
}
} else {
} else {
}
}
}
throw new ZipException(
"invalid entry size (expected " + e.size +
}
throw new ZipException(
"invalid entry compressed size (expected " + e.csize +
}
throw new ZipException(
}
}
/*
* Reads bytes, blocking until all bytes are read.
*/
while (len > 0) {
if (n == -1) {
throw new EOFException();
}
off += n;
len -= n;
}
}
/*
* Fetches unsigned 16-bit value from byte array at specified offset.
* The bytes are assumed to be in Intel (little-endian) byte order.
*/
}
/*
* Fetches unsigned 32-bit value from byte array at specified offset.
* The bytes are assumed to be in Intel (little-endian) byte order.
*/
}
/*
* Fetches signed 64-bit value from byte array at specified offset.
* The bytes are assumed to be in Intel (little-endian) byte order.
*/
}
}