java.util.zip.ZipOutputStream
java.util.zip.DeflaterOutputStream
None
None
New as of JDK 1.1
The ZipOutputStream class writes compressed files in the ZIP format. To write a ZIP file, construct a ZipOutputStream that wraps a regular output stream. You have to create a ZipEntry for each entry in the file. The putNextEntry() method puts the entry in the file, so that you can then use the write() method to write data for that entry. When you finish writing the data for an entry, call closeEntry() to close that entry and putNextEntry() to start another entry.
The setMethod() method specifies whether the data is compressed or uncompressed by default; setLevel() specifies the level of compression that is used by default. These values can be overridden by the method and level set for a particular entry. If you are storing compressed (deflated) files, you need only specify a name for each ZipEntry ; the other fields are filled in automatically. If, however, you are placing uncompressed entries, you need to specify the size of each entry and provide a CRC-32 checksum value.
public class java.util.zip.ZipOutputStream extends java.util.zip.DeflaterOutputStream { // Constants public static final int DEFLATED; public static final int STORED; // Constructors public ZipOutputStream(OutputStream out); // Instance Methods public void close(); public void closeEntry(); public void finish(); public void putNextEntry(ZipEntry e); public void setComment(String comment); public void setLevel(int level); public void setMethod(int method); public synchronized void write(byte[] b, int off, int len); }
A constant that represents an entry is stored using the deflate algorithm.
A constant that represents a ZIP file entry is stored verbatim; in other words, with no compression applied.
The underlying output stream.
This constructor creates a ZipOutputStream that writes compressed data to the given OutputStream.
If a ZIP file format error occurs.
If any other kind of I/O error occurs.
DeflaterOutputStream.close()
This method closes the stream and releases any system resources that are associated with it.
If a ZIP file format error occurs.
If any other kind of I/O error occurs.
This method closes the currently open entry in the ZIP file. A subsequent entry can be started with putNextEntry().
If a ZIP file format error occurs.
If any other kind of I/O error occurs.
DeflaterOutputStream.finish()
This method finishes writing compressed data to the underlying stream without closing it.
The new entry.
If a ZIP file format error occurs.
If any other kind of I/O error occurs.
This method writes the information in the given ZipEntry to the stream and positions the stream for the entry data. The actual entry data can then be written to the stream using write(). The default compression method and level are used if one is not specified for the entry. When all of the entry data has been written, use closeEntry() to finish the entry.
If this method is called when there is already an open entry, that entry is closed and this entry is opened.
The new comment string.
If comment is longer than 0xFFFF bytes.
This method sets the comment string for this ZIP file.
A compression level, from 0 (NO_COMPRESSION) to 9 (BEST_COMPRESSION).
If level is not valid.
This method sets the default compression level of subsequent DEFLATED entries. The default value is Deflater.DEFAULT_COMPRESSION.
A compression method, either DEFLATED or STORED.
If method is not valid.
This method sets the default compression method of this ZipOutputStream for entries that do not specify a method.
public synchronized void write(byte[] b, int off, int len) throws IOException
An array of bytes to write to the stream.
An offset into the byte array.
The number of bytes to write.
If a ZIP file format error occurs.
If any other kind of I/O error occurs.
DeflaterOutputStream.write(byte[], int, int)
This method takes len bytes from the given buffer, starting at off, and compresses them. The method then writes the compressed data to the underlying OutputStream for the current entry. The method blocks until all the bytes have been written.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
equals(Object) |
Object |
finalize() |
Object |
flush() |
FilterOutputStream |
getClass() |
Object |
hashCode() |
Object |
notify() |
Object |
notifyAll() |
Object |
toString() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
write(int) |
DeflaterOutputStream |
write(byte[]) |
FilterOutputStream |
Deflater, DeflaterOutputStream, IllegalArgumentException, IOException, OutputStream, ZipEntry, ZipException