E
- the type of the ZIP entries.@NotThreadSafe public abstract class AbstractZipOutputStream<E extends ZipEntry> extends net.java.truecommons.io.DecoratingOutputStream implements 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(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.
|
String |
getCharset()
Returns the name of the character set which is used for
encoding entry names and the file comment.
|
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.
|
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. |
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(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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
@CreatesObligation protected AbstractZipOutputStream(net.java.truecommons.io.Sink sink, @CheckForNull @WillNotClose AbstractZipFile<E> appendee, ZipOutputStreamParameters param) throws 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.IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class net.java.truecommons.io.DecoratingOutputStream
IOException
- On any I/O error.public void closeEntry() throws IOException
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 E entry(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.public void finish() throws IOException
Notes:
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 getCharset()
@Nullable public String getComment()
@CheckForNull protected abstract ZipCryptoParameters getCryptoParameters()
public int getLevel()
ZipEntry.DEFLATED
or ZipEntry.BZIP2
.setLevel(int)
public int getMethod()
ZipEntry
does not specify a
compression method.
The initial value is ZipEntry.DEFLATED
.setMethod(int)
,
ZipEntry.getMethod()
public Charset getRawCharset()
public boolean isBusy()
true
if and only if this
AbstractZipOutputStream
is currently writing a ZIP entry.public Iterator<E> iterator()
public long length()
public final void putNextEntry(E entry) throws IOException
putNextEntry(entry, true)
.IOException
public void putNextEntry(E entry, boolean process) throws ZipException, 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.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(@CheckForNull String comment)
comment
- the file comment.IllegalArgumentException
- if the encoded comment is longer than
UShort.MAX_VALUE
bytes.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.IllegalArgumentException
- if the compression level is invalid.getLevel()
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.IllegalArgumentException
- if the method is invalid.getMethod()
,
ZipEntry.setMethod(int)
public int size()
Copyright © 2005–2018 Schlichtherle IT Services. All rights reserved.