E - the type of the ZIP entries.@NotThreadSafe
public abstract class AbstractZipOutputStream<E extends ZipEntry>
extends net.java.truecommons.io.DecoratingOutputStream
implements java.lang.Iterable<E>
ZipEntry
instances.
Warning: This class is not intended for public use - its API may change at will without prior notification!
AbstractZipFile| Modifier | Constructor and Description |
|---|---|
protected |
AbstractZipOutputStream(net.java.truecommons.io.Sink sink,
AbstractZipFile<E> appendee,
ZipOutputStreamParameters param)
Constructs a raw ZIP output stream which decorates the given output
stream and optionally apppends to the given raw 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.
|
E |
entry(java.lang.String name)
Returns the entry for the given
name or null if no entry
with this name exists in this ZIP file. |
void |
finish()
Closes the current entry and writes the Central Directory to the
underlying output stream.
|
java.lang.String |
getCharset()
Returns the name of the character set which is used for
encoding entry names and the file comment.
|
java.lang.String |
getComment()
Returns the file comment.
|
protected abstract ZipCryptoParameters |
getCryptoParameters()
Returns the parameters for encryption or authentication of entries.
|
int |
getLevel()
Returns the compression level for entries.
|
int |
getMethod()
Returns the default compression method for subsequent entries.
|
java.nio.charset.Charset |
getRawCharset()
Returns the character set which is used for
encoding entry names and the file comment.
|
boolean |
isBusy()
Returns
true if and only if this
AbstractZipOutputStream is currently writing a ZIP entry. |
java.util.Iterator<E> |
iterator()
Returns an iteration of 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(E entry)
Equivalent to
putNextEntry(entry, true). |
void |
putNextEntry(E entry,
boolean process)
Starts writing the next ZIP entry to the underlying stream.
|
void |
setComment(java.lang.String comment)
Sets the file comment.
|
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.
|
flush, toString, write, write, write@CreatesObligation
protected AbstractZipOutputStream(net.java.truecommons.io.Sink sink,
@CheckForNull @WillNotClose
AbstractZipFile<E> appendee,
ZipOutputStreamParameters param)
throws java.io.IOException
sink - the sink 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 nullable raw ZIP file to append to.
This may already be closed.param - the parameters for writing the ZIP file.java.io.IOExceptionpublic java.nio.charset.Charset getRawCharset()
public java.lang.String getCharset()
public int size()
public java.util.Iterator<E> iterator()
public E entry(java.lang.String name)
name or null if no entry
with this name exists in this ZIP file.
Note that the returned entry is shared with this instance - it is an
error to change its state!name - the name of the ZIP entry.name or null if no entry
with this name exists in this ZIP file.@Nullable public java.lang.String getComment()
public void setComment(@CheckForNull
java.lang.String comment)
comment - the file comment.java.lang.IllegalArgumentException - if the encoded comment is longer than
UShort.MAX_VALUE bytes.public int getMethod()
ZipEntry does not specify a
compression method.
The initial value is ZipEntry.DEFLATED.setMethod(int),
ZipEntry.getMethod()public void setMethod(int method)
ZipEntry does not specify a
compression method.
Legal values are ZipEntry.STORED, ZipEntry.DEFLATED
and ZipEntry.BZIP2.method - the default compression method for entries.java.lang.IllegalArgumentException - if the method is invalid.getMethod(),
ZipEntry.setMethod(int)public int getLevel()
ZipEntry.DEFLATED or ZipEntry.BZIP2.setLevel(int)public void setLevel(int level)
ZipEntry.DEFLATED or ZipEntry.BZIP2.
Legal values are Deflater.DEFAULT_COMPRESSION or range from
Deflater.NO_COMPRESSION to Deflater.BEST_COMPRESSION.level - the compression level for entries.java.lang.IllegalArgumentException - if the compression level is invalid.getLevel()@CheckForNull protected abstract ZipCryptoParameters getCryptoParameters()
Returns The parameters for encryption or authentication of entries.
public long length()
public boolean isBusy()
true if and only if this
AbstractZipOutputStream is currently writing a ZIP entry.public final void putNextEntry(E entry) throws java.io.IOException
putNextEntry(entry, true).java.io.IOExceptionpublic void putNextEntry(E entry, boolean process) throws java.util.zip.ZipException, java.io.IOException
java.util.zip.ZipOutputStream which would throw a ZipException
in this method when another entry with the same name is to be written.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.java.util.zip.ZipException - If and only if writing the entry is impossible
because the resulting file would not comply to the ZIP file
format specification.java.io.IOException - On any I/O error.public void closeEntry()
throws java.io.IOException
java.util.zip.ZipException - If and only if writing the entry is impossible
because the resulting file would not comply to the ZIP file
format specification.java.io.IOException - On any I/O error.public void finish()
throws java.io.IOException
Notes:
java.util.zip.ZipException - If and only if writing the entry is impossible
because the resulting file would not comply to the ZIP file
format specification.java.io.IOException - On any I/O error.public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class net.java.truecommons.io.DecoratingOutputStreamjava.io.IOException - On any I/O error.