java.lang.Object | ||||
↳ | java.io.OutputStream | |||
↳ | java.io.FilterOutputStream | |||
↳ | java.util.zip.DeflaterOutputStream | |||
↳ | java.util.zip.ZipOutputStream |
Known Direct Subclasses |
This class provides an implementation of FilterOutputStream
that
compresses data entries into a ZIP-archive output stream.
ZipOutputStream
is used to write ZipEntries
to the underlying
stream. Output from ZipOutputStream
conforms to the ZipFile
file format.
While DeflaterOutputStream
can write a compressed ZIP-archive
entry, this extension can write uncompressed entries as well. In this case
special rules apply, for this purpose refer to the file format
specification.
Using ZipOutputStream
is a little more complicated than GZIPOutputStream
because ZIP archives are containers that can contain multiple files. This code creates a ZIP
archive containing several files, similar to the zip(1)
utility.
OutputStream os = ... ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(os)); try { for (int i = 0; i < fileCount; ++i) { String filename = ... byte[] bytes = ... ZipEntry entry = new ZipEntry(filename); zos.putNextEntry(entry); zos.write(bytes); zos.closeEntry(); } } finally { zos.close(); }
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | CENATT | ||||||||||
int | CENATX | ||||||||||
int | CENCOM | ||||||||||
int | CENCRC | ||||||||||
int | CENDSK | ||||||||||
int | CENEXT | ||||||||||
int | CENFLG | ||||||||||
int | CENHDR | ||||||||||
int | CENHOW | ||||||||||
int | CENLEN | ||||||||||
int | CENNAM | ||||||||||
int | CENOFF | ||||||||||
long | CENSIG | ||||||||||
int | CENSIZ | ||||||||||
int | CENTIM | ||||||||||
int | CENVEM | ||||||||||
int | CENVER | ||||||||||
int | DEFLATED | Indicates deflated entries. | |||||||||
int | ENDCOM | ||||||||||
int | ENDHDR | ||||||||||
int | ENDOFF | ||||||||||
long | ENDSIG | ||||||||||
int | ENDSIZ | ||||||||||
int | ENDSUB | ||||||||||
int | ENDTOT | ||||||||||
int | EXTCRC | ||||||||||
int | EXTHDR | ||||||||||
int | EXTLEN | ||||||||||
long | EXTSIG | ||||||||||
int | EXTSIZ | ||||||||||
int | LOCCRC | ||||||||||
int | LOCEXT | ||||||||||
int | LOCFLG | ||||||||||
int | LOCHDR | ||||||||||
int | LOCHOW | ||||||||||
int | LOCLEN | ||||||||||
int | LOCNAM | ||||||||||
long | LOCSIG | ||||||||||
int | LOCSIZ | ||||||||||
int | LOCTIM | ||||||||||
int | LOCVER | ||||||||||
int | STORED | Indicates uncompressed entries. |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.util.zip.DeflaterOutputStream
| |||||||||||
From class
java.io.FilterOutputStream
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new
ZipOutputStream with the specified output
stream. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Closes the current
ZipEntry , if any, and the underlying output
stream. | |||||||||||
Closes the current
ZipEntry . | |||||||||||
Indicates that all entries have been written to the stream.
| |||||||||||
Writes entry information to the underlying stream.
| |||||||||||
Sets the
ZipFile comment associated with the file being written. | |||||||||||
Sets the compression level to be used for writing entry data.
| |||||||||||
Sets the compression method to be used when compressing entry data.
| |||||||||||
Writes data for the current entry to the underlying stream.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.util.zip.DeflaterOutputStream
| |||||||||||
From class
java.io.FilterOutputStream
| |||||||||||
From class
java.io.OutputStream
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.io.Closeable
| |||||||||||
From interface
java.io.Flushable
|
Indicates deflated entries.
Indicates uncompressed entries.
Constructs a new ZipOutputStream
with the specified output
stream.
p1 | the OutputStream to write the data to.
|
---|
Closes the current ZipEntry
, if any, and the underlying output
stream. If the stream is already closed this method does nothing.
IOException | If an error occurs closing the stream. |
---|
Closes the current ZipEntry
. Any entry terminal data is written
to the underlying stream.
IOException | If an error occurs closing the entry. |
---|
Indicates that all entries have been written to the stream. Any terminal information is written to the underlying stream.
IOException | if an error occurs while terminating the stream. |
---|
Writes entry information to the underlying stream. Data associated with
the entry can then be written using write()
. After data is
written closeEntry()
must be called to complete the writing of
the entry to the underlying stream.
ze | the ZipEntry to store. |
---|
IOException | If an error occurs storing the entry. |
---|
Sets the ZipFile
comment associated with the file being written.
comment | the comment associated with the file. |
---|
Sets the compression level to be used for writing entry data. This level
may be set on a per entry basis. The level must have a value between -1
and 8 according to the Deflater
compression level bounds.
level | the compression level (ranging from -1 to 8). |
---|
Sets the compression method to be used when compressing entry data.
method must be one of STORED
(for no compression) or DEFLATED
.
method | the compression method to use. |
---|
Writes data for the current entry to the underlying stream.
buffer | the buffer to write. |
---|---|
offset | the index of the first byte in buffer to write. |
byteCount | the number of bytes in buffer to write. |
IOException | If an error occurs writing to the stream |
---|