@NotThreadSafe @DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class) public abstract class RawZipOutputStream<E extends ZipEntry> extends DecoratingOutputStream implements Iterable<E>
ZipEntry instances.
Warning: This class is not intended for public use - its API may change at will without prior notification!
RawZipFile| Modifier and Type | Class and Description |
|---|---|
private static class |
RawZipOutputStream.AppendingLEDataOutputStream
Adjusts the number of written bytes in the offset for appending mode.
|
private class |
RawZipOutputStream.BZip2OutputMethod |
private class |
RawZipOutputStream.Crc32CheckingOutputMethod |
private class |
RawZipOutputStream.Crc32OutputMethod |
private class |
RawZipOutputStream.Crc32UpdatingOutputMethod |
private class |
RawZipOutputStream.DeflaterOutputMethod |
private class |
RawZipOutputStream.EncryptedOutputMethod |
private class |
RawZipOutputStream.RawOutputMethod |
private class |
RawZipOutputStream.WinZipAesOutputMethod |
| Modifier and Type | Field and Description |
|---|---|
private long |
cdOffset
Start of central directory.
|
private Charset |
charset
The charset to use for entry names and comments.
|
private boolean |
closed |
private byte[] |
comment
The encoded file comment.
|
private LEDataOutputStream |
dos |
private Map<String,E> |
entries
The list of ZIP entries started to be written so far.
|
private ZipEntry |
entry
Current ZIP entry.
|
private boolean |
finished |
private int |
level
Default compression level for the methods DEFLATED and BZIP2.
|
private int |
method
Default compression method for next entry.
|
private OutputMethod |
processor |
delegate| Modifier | Constructor and Description |
|---|---|
protected |
RawZipOutputStream(OutputStream out,
RawZipFile<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.
|
private String |
decode(byte[] bytes) |
private byte[] |
encode(String string) |
void |
finish()
Closes the current entry and writes the Central Directory to the
underlying output stream.
|
private int |
getBZip2BlockSize() |
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.
|
private byte[] |
getCommentEncoded(ZipEntry entry) |
protected abstract ZipCryptoParameters |
getCryptoParameters()
Returns the parameters for encryption or authentication of entries.
|
E |
getEntry(String name)
Returns 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.
|
Charset |
getRawCharset()
Returns the character set which is used for
encoding entry names and the file comment.
|
private byte[] |
getRawComment() |
boolean |
isBusy()
Returns
true if and only if this
RawZipOutputStream 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.
|
private RawZipOutputStream.EncryptedOutputMethod |
newEncryptedOutputMethod(RawZipOutputStream.RawOutputMethod processor,
ZipParameters param)
Returns a new
EncryptedOutputMethod. |
private static LEDataOutputStream |
newLEDataOutputStream(OutputStream out,
RawZipFile<?> appendee) |
private OutputMethod |
newOutputMethod(ZipEntry entry,
boolean process)
Returns a new output method for the given entry.
|
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.
|
private void |
setLevel0(int level) |
void |
setMethod(int method)
Sets the default compression method for entries.
|
private void |
setMethod0(int method) |
int |
size()
Returns the number of ZIP entries written so far.
|
private boolean |
writeCentralFileHeader(ZipEntry entry)
Writes a Central File Header record.
|
private void |
writeEndOfCentralDirectory()
Writes the End Of Central Directory record.
|
private long cdOffset
private final Charset charset
private boolean closed
@CheckForNull private byte[] comment
private final LEDataOutputStream dos
private final Map<String,E extends ZipEntry> entries
private boolean finished
private int level
private int method
@Nullable private OutputMethod processor
protected RawZipOutputStream(OutputStream out, @CheckForNull RawZipFile<E> appendee, ZipOutputStreamParameters param)
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 nullable raw ZIP file to append to.
This may already be closed.param - the parameters for writing the ZIP file.public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class DecoratingOutputStreamIOException - 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.private String decode(byte[] bytes)
private byte[] encode(String string)
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.private int getBZip2BlockSize()
public String getCharset()
private byte[] getCommentEncoded(ZipEntry entry)
@CheckForNull protected abstract ZipCryptoParameters getCryptoParameters()
public E getEntry(String name)
null if no entry with
this name exists.
Note that the returned entry is shared with this instance.
It is illegal to change its state!name - the name of the ZIP entry.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()
private byte[] getRawComment()
public boolean isBusy()
true if and only if this
RawZipOutputStream is currently writing a ZIP entry.public Iterator<E> iterator()
public long length()
private RawZipOutputStream.EncryptedOutputMethod newEncryptedOutputMethod(RawZipOutputStream.RawOutputMethod processor, @CheckForNull ZipParameters param) throws ZipParametersException
EncryptedOutputMethod.processor - the output method to decorate.param - the ZipCryptoParameters used to determine and
configure the type of the encrypted ZIP file.
If the run time class of this parameter matches multiple
parameter interfaces, it is at the discretion of this
implementation which one is picked and hence which type of
encrypted ZIP file is created.
If you need more control over this, pass in an instance which's
run time class just implements the
ZipParametersProvider interface.
Instances of this interface are queried to find crypto
parameters which match a known encrypted ZIP file type.
This algorithm is recursively applied.EncryptedOutputMethod.ZipCryptoParametersException - if param is null or
no suitable crypto parameters can get found.ZipParametersExceptionprivate static LEDataOutputStream newLEDataOutputStream(OutputStream out, @CheckForNull RawZipFile<?> appendee)
private OutputMethod newOutputMethod(ZipEntry entry, boolean process) throws ZipException
ZipExceptionpublic final void putNextEntry(E entry) throws IOException
putNextEntry(entry, true).IOExceptionpublic void putNextEntry(E entry, boolean process) throws 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#BEST_SPEED to Deflater#BEST_COMPRESSION.level - the compression level for entries.IllegalArgumentException - if the compression level is invalid.getLevel()private void setLevel0(int level)
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)private void setMethod0(int method)
public int size()
private boolean writeCentralFileHeader(ZipEntry entry) throws IOException
false if and only if the record has been skipped,
i.e. not written for some other reason than an I/O error.IOException - On any I/O error.private void writeEndOfCentralDirectory()
throws IOException
IOException - On any I/O error.Copyright © 2004-2011 Schlichtherle IT Services. All Rights Reserved.