| java.lang.Object | ||||
| ↳ | java.io.OutputStream | |||
| ↳ | java.io.FilterOutputStream | |||
| ↳ | java.util.zip.DeflaterOutputStream | |||
| ↳ | java.util.zip.ZipOutputStream | |||
Known Direct Subclasses
|
Used to write (compress) data into zip files.
ZipOutputStream is used to write ZipEntrys to the underlying
stream. Output from ZipOutputStream can be read using ZipFile
or ZipInputStream.
While DeflaterOutputStream can write compressed zip file
entries, this extension can write uncompressed entries as well.
Use setMethod(int) or setMethod(int) with the STORED flag.
Using ZipOutputStream is a little more complicated than GZIPOutputStream
because zip files are containers that can contain multiple files. This code creates a zip
file 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 that writes a zip file to the given
OutputStream.
| |||||||||||
| 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 comment associated with the file being written.
| |||||||||||
Sets the compression level to be used
for writing entry data.
| |||||||||||
Sets the default compression method to be used when a
ZipEntry doesn't
explicitly specify a method.
| |||||||||||
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
| |||||||||||
From interface
java.lang.AutoCloseable
| |||||||||||
Indicates deflated entries.
Indicates uncompressed entries.
Constructs a new ZipOutputStream that writes a zip file to the given
OutputStream.
UTF-8 will be used to encode the file comment, entry names and comments.
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 comment associated with the file being written. See getComment().
| IllegalArgumentException | if the comment is >= 64 Ki encoded bytes. |
|---|
Sets the compression level to be used for writing entry data.
Sets the default compression method to be used when a ZipEntry doesn't
explicitly specify a method. See setMethod(int) for more details.
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 |
|---|