/*
* 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 output stream filter for writing files in the
* ZIP file format. Includes support for both compressed and uncompressed
* entries.
*
* @author David Connelly
*/
public
private static class XEntry {
public final long offset;
}
}
private byte[] comment;
private boolean finished;
private boolean closed = false;
switch (e.method) {
case DEFLATED: return 20;
case STORED: return 10;
default: throw new ZipException("unsupported compression method");
}
}
/**
* Checks to make sure that this stream has not been closed.
*/
if (closed) {
throw new IOException("Stream closed");
}
}
/**
* Compression method for uncompressed (STORED) entries.
*/
/**
* Compression method for compressed (DEFLATED) entries.
*/
/**
* Creates a new ZIP output stream.
*
* <p>The UTF-8 {@link java.nio.charset.Charset charset} is used
* to encode the entry names and comments.
*
* @param out the actual output stream
*/
}
/**
* Creates a new ZIP output stream.
*
* @param out the actual output stream
*
* @param charset the {@linkplain java.nio.charset.Charset charset}
* to be used to encode the entry names and comments
*
* @since 1.7
*/
throw new NullPointerException("charset is null");
usesDefaultDeflater = true;
}
/**
* Sets the ZIP file comment.
* @param comment the comment string
* @exception IllegalArgumentException if the length of the specified
* ZIP file comment is greater than 0xFFFF bytes
*/
throw new IllegalArgumentException("ZIP file comment too long.");
}
}
/**
* Sets the default compression method for subsequent entries. This
* default will be used whenever the compression method is not specified
* for an individual ZIP file entry, and is initially set to DEFLATED.
* @param method the default compression method
* @exception IllegalArgumentException if the specified compression method
* is invalid
*/
throw new IllegalArgumentException("invalid compression method");
}
}
/**
* Sets the compression level for subsequent entries which are DEFLATED.
* The default setting is DEFAULT_COMPRESSION.
* @param level the compression level (0-9)
* @exception IllegalArgumentException if the compression level is invalid
*/
}
/**
* Begins writing a new ZIP file entry and positions the stream to the
* start of the entry data. Closes the current entry if still active.
* The default compression method will be used if no compression method
* was specified for the entry, and the current time will be used if
* the entry has no set modification time.
* @param e the ZIP entry to be written
* @exception ZipException if a ZIP format error has occurred
* @exception IOException if an I/O error has occurred
*/
ensureOpen();
closeEntry(); // close previous entry
}
if (e.time == -1) {
}
if (e.method == -1) {
}
// store size, compressed size, and crc-32 in LOC header
e.flag = 0;
switch (e.method) {
case DEFLATED:
// store size, compressed size, and crc-32 in data descriptor
// immediately following the compressed entry data
e.flag = 8;
break;
case STORED:
// compressed size, uncompressed size, and crc-32 must all be
// set for entries using STORED compression method
if (e.size == -1) {
} else if (e.csize == -1) {
throw new ZipException(
"STORED entry where compressed != uncompressed size");
}
throw new ZipException(
"STORED entry missing size, compressed size, or crc-32");
}
break;
default:
throw new ZipException("unsupported compression method");
}
}
}
/**
* Closes the current ZIP entry and positions the stream for writing
* the next entry.
* @exception ZipException if a ZIP format error has occurred
* @exception IOException if an I/O error has occurred
*/
ensureOpen();
switch (e.method) {
case DEFLATED:
deflate();
}
// verify size, compressed size, and crc-32 settings
throw new ZipException(
"invalid entry size (expected " + e.size +
}
throw new ZipException(
"invalid entry compressed size (expected " +
}
throw new ZipException(
"invalid entry CRC-32 (expected 0x" +
}
} else {
writeEXT(e);
}
break;
case STORED:
// we already know that both e.size and e.csize are the same
throw new ZipException(
"invalid entry size (expected " + e.size +
}
throw new ZipException(
"invalid entry crc-32 (expected 0x" +
}
break;
default:
throw new ZipException("invalid compression method");
}
}
}
/**
* Writes an array of bytes to the current ZIP entry data. This method
* will block until all the bytes are written.
* @param b the data to be written
* @param off the start offset in the data
* @param len the number of bytes that are written
* @exception ZipException if a ZIP file error has occurred
* @exception IOException if an I/O error has occurred
*/
throws IOException
{
ensureOpen();
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return;
}
throw new ZipException("no current ZIP entry");
}
case DEFLATED:
break;
case STORED:
throw new ZipException(
"attempt to write past end of STORED entry");
}
break;
default:
throw new ZipException("invalid compression method");
}
}
/**
* Finishes writing the contents of the ZIP output stream without closing
* the underlying stream. Use this method when applying multiple filters
* in succession to the same output stream.
* @exception ZipException if a ZIP file error has occurred
* @exception IOException if an I/O exception has occurred
*/
ensureOpen();
if (finished) {
return;
}
closeEntry();
}
// write central directory
finished = true;
}
/**
* Closes the ZIP output stream as well as the stream being filtered.
* @exception ZipException if a ZIP file error has occurred
* @exception IOException if an I/O error has occurred
*/
if (!closed) {
super.close();
closed = true;
}
}
/*
* Writes local file (LOC) header for specified entry.
*/
boolean hasZip64 = false;
// store size, uncompressed size, and crc-32 in data descriptor
// immediately following compressed entry data
writeInt(0);
writeInt(0);
writeInt(0);
} else {
hasZip64 = true;
} else {
}
if (hasZip64) {
} else {
}
}
if (hasZip64) {
writeShort(16);
}
}
}
/*
* Writes extra data descriptor (EXT) for specified entry.
*/
} else {
}
}
/*
* Write central directory (CEN) header for specified entry.
* REMIND: add support for file attributes
*/
int e64len = 0;
boolean hasZip64 = false;
if (e.csize >= ZIP64_MAGICVAL) {
hasZip64 = true;
}
if (e.size >= ZIP64_MAGICVAL) {
e64len += 8;
hasZip64 = true;
}
hasZip64 = true;
}
if (hasZip64) {
writeShort(45);
} else {
}
if (hasZip64) {
// + headid(2) + datasize(2)
} else {
}
byte[] commentBytes;
} else {
commentBytes = null;
writeShort(0);
}
if (hasZip64) {
if (size == ZIP64_MAGICVAL)
if (csize == ZIP64_MAGICVAL)
if (offset == ZIP64_MAGICVAL)
}
}
if (commentBytes != null) {
}
}
/*
* Writes end of central directory (END) header.
*/
boolean hasZip64 = false;
if (xlen >= ZIP64_MAGICVAL) {
hasZip64 = true;
}
if (xoff >= ZIP64_MAGICVAL) {
hasZip64 = true;
}
if (count >= ZIP64_MAGICCOUNT) {
hasZip64 = true;
}
if (hasZip64) {
//zip64 end of central directory record
//zip64 end of central directory locator
}
} else {
writeShort(0);
}
}
/*
* Writes a 16-bit short to the output stream in little-endian byte order.
*/
written += 2;
}
/*
* Writes a 32-bit int to the output stream in little-endian byte order.
*/
written += 4;
}
/*
* Writes a 64-bit int to the output stream in little-endian byte order.
*/
written += 8;
}
/*
* Writes an array of bytes to the output stream.
*/
}
}