Package sk.iway.iwcm.system.zip
Class ZipOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
sk.iway.iwcm.system.zip.DeflaterOutputStream
sk.iway.iwcm.system.zip.ZipOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
This class implements an output stream filter for writing files in the
ZIP file format. Includes support for both compressed and uncompressed
entries.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final long
static final int
static final int
static final int
static final int
static final int
Compression method for compressed (DEFLATED) entries.static final int
static final int
static final int
static final long
static final int
static final int
static final int
static final int
static final int
static final int
static final long
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final long
static final int
static final int
static final int
static final int
Compression method for uncompressed (STORED) entries.Fields inherited from class sk.iway.iwcm.system.zip.DeflaterOutputStream
buf, def
Fields inherited from class java.io.FilterOutputStream
out
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the ZIP output stream as well as the stream being filtered.void
Closes the current ZIP entry and positions the stream for writing the next entry.void
finish()
Finishes writing the contents of the ZIP output stream without closing the underlying stream.void
Begins writing a new ZIP file entry and positions the stream to the start of the entry data.void
setComment
(String comment) Sets the ZIP file comment.void
setLevel
(int level) Sets the compression level for subsequent entries which are DEFLATED.void
setMethod
(int method) Sets the default compression method for subsequent entries.void
write
(byte[] b, int off, int len) Writes an array of bytes to the current ZIP entry data.Methods inherited from class sk.iway.iwcm.system.zip.DeflaterOutputStream
deflate, write
Methods inherited from class java.io.FilterOutputStream
flush, write
Methods inherited from class java.io.OutputStream
nullOutputStream
-
Field Details
-
STORED
public static final int STOREDCompression method for uncompressed (STORED) entries.- See Also:
-
DEFLATED
public static final int DEFLATEDCompression method for compressed (DEFLATED) entries.- See Also:
-
LOCSIG
static final long LOCSIG- See Also:
-
EXTSIG
static final long EXTSIG- See Also:
-
CENSIG
static final long CENSIG- See Also:
-
ENDSIG
static final long ENDSIG- See Also:
-
LOCHDR
static final int LOCHDR- See Also:
-
EXTHDR
static final int EXTHDR- See Also:
-
CENHDR
static final int CENHDR- See Also:
-
ENDHDR
static final int ENDHDR- See Also:
-
LOCVER
static final int LOCVER- See Also:
-
LOCFLG
static final int LOCFLG- See Also:
-
LOCHOW
static final int LOCHOW- See Also:
-
LOCTIM
static final int LOCTIM- See Also:
-
LOCCRC
static final int LOCCRC- See Also:
-
LOCSIZ
static final int LOCSIZ- See Also:
-
LOCLEN
static final int LOCLEN- See Also:
-
LOCNAM
static final int LOCNAM- See Also:
-
LOCEXT
static final int LOCEXT- See Also:
-
EXTCRC
static final int EXTCRC- See Also:
-
EXTSIZ
static final int EXTSIZ- See Also:
-
EXTLEN
static final int EXTLEN- See Also:
-
CENVEM
static final int CENVEM- See Also:
-
CENVER
static final int CENVER- See Also:
-
CENFLG
static final int CENFLG- See Also:
-
CENHOW
static final int CENHOW- See Also:
-
CENTIM
static final int CENTIM- See Also:
-
CENCRC
static final int CENCRC- See Also:
-
CENSIZ
static final int CENSIZ- See Also:
-
CENLEN
static final int CENLEN- See Also:
-
CENNAM
static final int CENNAM- See Also:
-
CENEXT
static final int CENEXT- See Also:
-
CENCOM
static final int CENCOM- See Also:
-
CENDSK
static final int CENDSK- See Also:
-
CENATT
static final int CENATT- See Also:
-
CENATX
static final int CENATX- See Also:
-
CENOFF
static final int CENOFF- See Also:
-
ENDSUB
static final int ENDSUB- See Also:
-
ENDTOT
static final int ENDTOT- See Also:
-
ENDSIZ
static final int ENDSIZ- See Also:
-
ENDOFF
static final int ENDOFF- See Also:
-
ENDCOM
static final int ENDCOM- See Also:
-
-
Constructor Details
-
ZipOutputStream
Creates a new ZIP output stream.- Parameters:
out
- the actual output stream
-
-
Method Details
-
setComment
Sets the ZIP file comment.- Parameters:
comment
- the comment string- Throws:
IllegalArgumentException
- if the length of the specified ZIP file comment is greater than 0xFFFF bytes
-
setMethod
public void setMethod(int method) Sets the default compression method for subsequent entries. This default will be used whenever the compression method is not specified for an individual ZIP file entry, and is initially set to DEFLATED.- Parameters:
method
- the default compression method- Throws:
IllegalArgumentException
- if the specified compression method is invalid
-
setLevel
public void setLevel(int level) Sets the compression level for subsequent entries which are DEFLATED. The default setting is DEFAULT_COMPRESSION.- Parameters:
level
- the compression level (0-9)- Throws:
IllegalArgumentException
- if the compression level is invalid
-
putNextEntry
Begins writing a new ZIP file entry and positions the stream to the start of the entry data. Closes the current entry if still active. The default compression method will be used if no compression method was specified for the entry, and the current time will be used if the entry has no set modification time.- Parameters:
e
- the ZIP entry to be written- Throws:
ZipException
- if a ZIP format error has occurredIOException
- if an I/O error has occurred
-
closeEntry
Closes the current ZIP entry and positions the stream for writing the next entry.- Throws:
ZipException
- if a ZIP format error has occurredIOException
- if an I/O error has occurred
-
write
Writes an array of bytes to the current ZIP entry data. This method will block until all the bytes are written.- Overrides:
write
in classDeflaterOutputStream
- Parameters:
b
- the data to be writtenoff
- the start offset in the datalen
- the number of bytes that are written- Throws:
ZipException
- if a ZIP file error has occurredIOException
- if an I/O error has occurred
-
finish
Finishes writing the contents of the ZIP output stream without closing the underlying stream. Use this method when applying multiple filters in succession to the same output stream.- Overrides:
finish
in classDeflaterOutputStream
- Throws:
ZipException
- if a ZIP file error has occurredIOException
- if an I/O exception has occurred
-
close
Closes the ZIP output stream as well as the stream being filtered.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classDeflaterOutputStream
- Throws:
ZipException
- if a ZIP file error has occurredIOException
- if an I/O error has occurred
-