- java.lang.Object
- 
- java.io.OutputStream
- 
- java.io.FilterOutputStream
- 
- java.util.zip.DeflaterOutputStream
- 
- java.util.zip.ZipOutputStream
 
 
 
 
- 
- All Implemented Interfaces:
- Closeable,- Flushable,- AutoCloseable
 - Direct Known Subclasses:
- JarOutputStream
 
 public class ZipOutputStream extends DeflaterOutputStream This class implements an output stream filter for writing files in the ZIP file format. Includes support for both compressed and uncompressed entries.- Since:
- 1.1
 
- 
- 
Field SummaryFields Modifier and Type Field Description static intCENATTstatic intCENATXstatic intCENCOMstatic intCENCRCstatic intCENDSKstatic intCENEXTstatic intCENFLGstatic intCENHDRstatic intCENHOWstatic intCENLENstatic intCENNAMstatic intCENOFFstatic longCENSIGstatic intCENSIZstatic intCENTIMstatic intCENVEMstatic intCENVERstatic intDEFLATEDCompression method for compressed (DEFLATED) entries.static intENDCOMstatic intENDHDRstatic intENDOFFstatic longENDSIGstatic intENDSIZstatic intENDSUBstatic intENDTOTstatic intEXTCRCstatic intEXTHDRstatic intEXTLENstatic longEXTSIGstatic intEXTSIZstatic intLOCCRCstatic intLOCEXTstatic intLOCFLGstatic intLOCHDRstatic intLOCHOWstatic intLOCLENstatic intLOCNAMstatic longLOCSIGstatic intLOCSIZstatic intLOCTIMstatic intLOCVERstatic intSTOREDCompression method for uncompressed (STORED) entries.- 
Fields declared in class java.util.zip.DeflaterOutputStreambuf, def
 - 
Fields declared in class java.io.FilterOutputStreamout
 
- 
 - 
Constructor SummaryConstructors Constructor Description ZipOutputStream(OutputStream out)Creates a new ZIP output stream.ZipOutputStream(OutputStream out, Charset charset)Creates a new ZIP output stream.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the ZIP output stream as well as the stream being filtered.voidcloseEntry()Closes the current ZIP entry and positions the stream for writing the next entry.voidfinish()Finishes writing the contents of the ZIP output stream without closing the underlying stream.voidputNextEntry(ZipEntry e)Begins writing a new ZIP file entry and positions the stream to the start of the entry data.voidsetComment(String comment)Sets the ZIP file comment.voidsetLevel(int level)Sets the compression level for subsequent entries which are DEFLATED.voidsetMethod(int method)Sets the default compression method for subsequent entries.voidwrite(byte[] b, int off, int len)Writes an array of bytes to the current ZIP entry data.- 
Methods declared in class java.util.zip.DeflaterOutputStreamdeflate, flush, write
 - 
Methods declared in class java.io.FilterOutputStreamwrite
 - 
Methods declared in class java.io.OutputStreamnullOutputStream
 
- 
 
- 
- 
- 
Field Detail- 
STOREDpublic static final int STORED Compression method for uncompressed (STORED) entries.- See Also:
- Constant Field Values
 
 - 
DEFLATEDpublic static final int DEFLATED Compression method for compressed (DEFLATED) entries.- See Also:
- Constant Field Values
 
 - 
LOCSIGpublic static final long LOCSIG - See Also:
- Constant Field Values
 
 - 
EXTSIGpublic static final long EXTSIG - See Also:
- Constant Field Values
 
 - 
CENSIGpublic static final long CENSIG - See Also:
- Constant Field Values
 
 - 
ENDSIGpublic static final long ENDSIG - See Also:
- Constant Field Values
 
 - 
LOCHDRpublic static final int LOCHDR - See Also:
- Constant Field Values
 
 - 
EXTHDRpublic static final int EXTHDR - See Also:
- Constant Field Values
 
 - 
CENHDRpublic static final int CENHDR - See Also:
- Constant Field Values
 
 - 
ENDHDRpublic static final int ENDHDR - See Also:
- Constant Field Values
 
 - 
LOCVERpublic static final int LOCVER - See Also:
- Constant Field Values
 
 - 
LOCFLGpublic static final int LOCFLG - See Also:
- Constant Field Values
 
 - 
LOCHOWpublic static final int LOCHOW - See Also:
- Constant Field Values
 
 - 
LOCTIMpublic static final int LOCTIM - See Also:
- Constant Field Values
 
 - 
LOCCRCpublic static final int LOCCRC - See Also:
- Constant Field Values
 
 - 
LOCSIZpublic static final int LOCSIZ - See Also:
- Constant Field Values
 
 - 
LOCLENpublic static final int LOCLEN - See Also:
- Constant Field Values
 
 - 
LOCNAMpublic static final int LOCNAM - See Also:
- Constant Field Values
 
 - 
LOCEXTpublic static final int LOCEXT - See Also:
- Constant Field Values
 
 - 
EXTCRCpublic static final int EXTCRC - See Also:
- Constant Field Values
 
 - 
EXTSIZpublic static final int EXTSIZ - See Also:
- Constant Field Values
 
 - 
EXTLENpublic static final int EXTLEN - See Also:
- Constant Field Values
 
 - 
CENVEMpublic static final int CENVEM - See Also:
- Constant Field Values
 
 - 
CENVERpublic static final int CENVER - See Also:
- Constant Field Values
 
 - 
CENFLGpublic static final int CENFLG - See Also:
- Constant Field Values
 
 - 
CENHOWpublic static final int CENHOW - See Also:
- Constant Field Values
 
 - 
CENTIMpublic static final int CENTIM - See Also:
- Constant Field Values
 
 - 
CENCRCpublic static final int CENCRC - See Also:
- Constant Field Values
 
 - 
CENSIZpublic static final int CENSIZ - See Also:
- Constant Field Values
 
 - 
CENLENpublic static final int CENLEN - See Also:
- Constant Field Values
 
 - 
CENNAMpublic static final int CENNAM - See Also:
- Constant Field Values
 
 - 
CENEXTpublic static final int CENEXT - See Also:
- Constant Field Values
 
 - 
CENCOMpublic static final int CENCOM - See Also:
- Constant Field Values
 
 - 
CENDSKpublic static final int CENDSK - See Also:
- Constant Field Values
 
 - 
CENATTpublic static final int CENATT - See Also:
- Constant Field Values
 
 - 
CENATXpublic static final int CENATX - See Also:
- Constant Field Values
 
 - 
CENOFFpublic static final int CENOFF - See Also:
- Constant Field Values
 
 - 
ENDSUBpublic static final int ENDSUB - See Also:
- Constant Field Values
 
 - 
ENDTOTpublic static final int ENDTOT - See Also:
- Constant Field Values
 
 - 
ENDSIZpublic static final int ENDSIZ - See Also:
- Constant Field Values
 
 - 
ENDOFFpublic static final int ENDOFF - See Also:
- Constant Field Values
 
 - 
ENDCOMpublic static final int ENDCOM - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
ZipOutputStreampublic ZipOutputStream(OutputStream out) Creates a new ZIP output stream.The UTF-8 charsetis used to encode the entry names and comments.- Parameters:
- out- the actual output stream
 
 - 
ZipOutputStreampublic ZipOutputStream(OutputStream out, Charset charset) Creates a new ZIP output stream.- Parameters:
- out- the actual output stream
- charset- the charset to be used to encode the entry names and comments
- Since:
- 1.7
 
 
- 
 - 
Method Detail- 
setCommentpublic void setComment(String comment) 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
 
 - 
setMethodpublic 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
 
 - 
setLevelpublic 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
 
 - 
putNextEntrypublic void putNextEntry(ZipEntry e) throws IOException 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 occurred
- IOException- if an I/O error has occurred
 
 - 
closeEntrypublic void closeEntry() throws IOExceptionCloses the current ZIP entry and positions the stream for writing the next entry.- Throws:
- ZipException- if a ZIP format error has occurred
- IOException- if an I/O error has occurred
 
 - 
writepublic void write(byte[] b, int off, int len) throws IOExceptionWrites an array of bytes to the current ZIP entry data. This method will block until all the bytes are written.- Overrides:
- writein class- DeflaterOutputStream
- Parameters:
- b- the data to be written
- off- the start offset in the data
- len- the number of bytes that are written
- Throws:
- ZipException- if a ZIP file error has occurred
- IOException- if an I/O error has occurred
- See Also:
- FilterOutputStream.write(int)
 
 - 
finishpublic void finish() throws IOExceptionFinishes 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:
- finishin class- DeflaterOutputStream
- Throws:
- ZipException- if a ZIP file error has occurred
- IOException- if an I/O exception has occurred
 
 - 
closepublic void close() throws IOExceptionCloses the ZIP output stream as well as the stream being filtered.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Overrides:
- closein class- DeflaterOutputStream
- Throws:
- ZipException- if a ZIP file error has occurred
- IOException- if an I/O error has occurred
- See Also:
- FilterOutputStream.flush(),- FilterOutputStream.out
 
 
- 
 
-