@ThreadSafe public class ZipOutputStream extends RawZipOutputStream<ZipEntry>
java.util.zip.ZipOutputStream.
This class starts writing ordinary ZIP32 File Format. It automatically adds ZIP64 extensions if required, i.e. if the file size exceeds 4GB or more than 65535 entries are written. This implies that the class may produce ZIP archive files which cannot be read by older ZIP implementations.
If the system property de.schlichtherle.truezip.io.zip.zip64ext
is set to true (case is ignored),
then ZIP64 extensions are always added when writing a ZIP archive file,
regardless of its size.
This system property is primarily intended for unit testing purposes.
During normal operations, it should not be set as many
third party tools would not treat the redundant ZIP64 extensions
correctly.
Note that it's impossible to inhibit ZIP64 extensions.
This class provides some limited support for multithreading: You can read its properties from multiple threads, but obviously you cannot concurrently write multiple entries at the same time by different threads.
ZipFile| Modifier and Type | Field and Description |
|---|---|
static Charset |
DEFAULT_CHARSET
The default character set used for entry names and comments in ZIP files.
|
delegate| Constructor and Description |
|---|
ZipOutputStream(OutputStream out)
Constructs a ZIP output stream which decorates the given output stream
using the
"UTF-8" charset. |
ZipOutputStream(OutputStream out,
Charset charset)
Constructs a ZIP output stream which decorates the given output stream
using the given charset.
|
ZipOutputStream(OutputStream out,
ZipFile appendee)
Constructs a ZIP output stream which decorates the given output stream
and appends to the given ZIP file.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this output stream and releases any system resources
associated with the stream.
|
void |
closeEntry()
Writes all necessary data for this entry to the underlying stream.
|
void |
finish()
Closes the current entry and writes the Central Directory to the
underlying output stream.
|
String |
getComment()
Returns the file comment.
|
ZipCryptoParameters |
getCryptoParameters()
Returns the parameters for encryption or authentication of entries.
|
ZipEntry |
getEntry(String name)
Returns a clone of the entry for the given name or
null if no
entry with this name exists. |
int |
getLevel()
Returns the compression level for entries.
|
int |
getMethod()
Returns the default compression method for subsequent entries.
|
boolean |
isBusy()
Returns
true if and only if this
RawZipOutputStream is currently writing a ZIP entry. |
Iterator<ZipEntry> |
iterator()
Returns a safe iteration of clones for all entries written to this ZIP
file so far.
|
long |
length()
Returns the total number of (compressed) bytes this stream has written
to the underlying stream.
|
void |
putNextEntry(ZipEntry entry,
boolean process)
Starts writing the next ZIP entry to the underlying stream.
|
void |
setComment(String comment)
Sets the file comment.
|
void |
setCryptoParameters(ZipCryptoParameters cryptoParameters)
Sets the parameters for encryption or authentication of entries.
|
void |
setLevel(int level)
Sets the compression level for entries.
|
void |
setMethod(int method)
Sets the default compression method for entries.
|
int |
size()
Returns the number of ZIP entries written so far.
|
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
getCharset, getRawCharset, putNextEntryflush, toString, writepublic static final Charset DEFAULT_CHARSET
"UTF-8" for compatibility with Sun's JDK implementation.@CreatesObligation public ZipOutputStream(@WillCloseWhenClosed OutputStream out)
"UTF-8" charset.out - The output stream to write the ZIP file to.@CreatesObligation public ZipOutputStream(@WillCloseWhenClosed OutputStream out, Charset charset)
out - The output stream to write the ZIP file to.charset - the character set to use.@CreatesObligation public ZipOutputStream(@WillCloseWhenClosed OutputStream out, ZipFile appendee)
out - The output stream to write the ZIP file to.
If appendee is not null, then this must be set
up so that it appends to the same ZIP file from which
appendee is reading.appendee - the ZIP file to append to.
This may already be closed.public void close()
throws IOException
RawZipOutputStreamclose in interface Closeableclose in interface AutoCloseableclose in class RawZipOutputStream<ZipEntry>IOException - On any I/O error.public void closeEntry()
throws IOException
RawZipOutputStreamcloseEntry in class RawZipOutputStream<ZipEntry>ZipException - If and only if writing the entry is impossible
because the resulting file would not comply to the ZIP file
format specification.IOException - On any I/O error.public void finish()
throws IOException
RawZipOutputStreamNotes:
finish in class RawZipOutputStream<ZipEntry>ZipException - If and only if writing the entry is impossible
because the resulting file would not comply to the ZIP file
format specification.IOException - On any I/O error.public String getComment()
RawZipOutputStreamgetComment in class RawZipOutputStream<ZipEntry>@Nullable public ZipCryptoParameters getCryptoParameters()
RawZipOutputStreamgetCryptoParameters in class RawZipOutputStream<ZipEntry>public ZipEntry getEntry(String name)
null if no
entry with this name exists.getEntry in class RawZipOutputStream<ZipEntry>name - the name of the ZIP entry.public int getLevel()
ZipEntry.DEFLATED or ZipEntry.BZIP2.
The initial value is Deflater#DEFAULT_COMPRESSION.
getLevel in class RawZipOutputStream<ZipEntry>RawZipOutputStream.setLevel(int)public int getMethod()
ZipEntry does not specify a
compression method.
The initial value is ZipEntry.DEFLATED.
The initial value is ZipEntry#DEFLATED.
getMethod in class RawZipOutputStream<ZipEntry>RawZipOutputStream.setMethod(int),
ZipEntry.getMethod()public final boolean isBusy()
RawZipOutputStreamtrue if and only if this
RawZipOutputStream is currently writing a ZIP entry.isBusy in class RawZipOutputStream<ZipEntry>public Iterator<ZipEntry> iterator()
public long length()
RawZipOutputStreamlength in class RawZipOutputStream<ZipEntry>public void putNextEntry(ZipEntry entry, boolean process) throws IOException
RawZipOutputStreamjava.util.zip.ZipOutputStream which would throw a ZipException
in this method when another entry with the same name is to be written.putNextEntry in class RawZipOutputStream<ZipEntry>entry - The entry to write.process - Whether or not the entry contents should get processed,
e.g. deflated.
This should be set to false if and only if the
application is going to copy entries from an input ZIP file to
an output ZIP file.
The entries' CRC-32, compressed size and uncompressed
size properties must be set in advance.ZipException - If and only if writing the entry is impossible
because the resulting file would not comply to the ZIP file
format specification.IOException - On any I/O error.public void setComment(String comment)
RawZipOutputStreamsetComment in class RawZipOutputStream<ZipEntry>comment - the file comment.public void setCryptoParameters(@CheckForNull ZipCryptoParameters cryptoParameters)
Note that only WinZip AES encryption is
currently supported.
cryptoParameters - the parameters for encryption or authentication
of entries.public void setLevel(int level)
RawZipOutputStreamZipEntry.DEFLATED or ZipEntry.BZIP2.
Legal values are Deflater.DEFAULT_COMPRESSION or range from
Deflater#BEST_SPEED to Deflater#BEST_COMPRESSION.setLevel in class RawZipOutputStream<ZipEntry>level - the compression level for entries.RawZipOutputStream.getLevel()public void setMethod(int method)
RawZipOutputStreamZipEntry does not specify a
compression method.
Legal values are ZipEntry.STORED, ZipEntry.DEFLATED
and ZipEntry.BZIP2.setMethod in class RawZipOutputStream<ZipEntry>method - the default compression method for entries.RawZipOutputStream.getMethod(),
ZipEntry.setMethod(int)public int size()
RawZipOutputStreamsize in class RawZipOutputStream<ZipEntry>public void write(byte[] b,
int off,
int len)
throws IOException
write in class DecoratingOutputStreamIOExceptionpublic void write(int b)
throws IOException
write in class DecoratingOutputStreamIOExceptionCopyright © 2005-2013 Schlichtherle IT Services. All Rights Reserved.