Class ZipOutputStream
- All Implemented Interfaces:
- Closeable,- Flushable,- AutoCloseable
- Direct Known Subclasses:
- JarOutputStream
 Unless otherwise noted, passing a null argument to a constructor
 or method in this class will cause a NullPointerException to be
 thrown.
- Since:
- 1.1
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intCentral directory (CEN) header internal file attributes field offset.static final intCentral directory (CEN) header external file attributes field offset.static final intCentral directory (CEN) header comment length field offset.static final intCentral directory (CEN) header uncompressed file crc-32 value field offset.static final intCentral directory (CEN) header disk number start field offset.static final intCentral directory (CEN) header extra field length field offset.static final intCentral directory (CEN) header encrypt, decrypt flags field offset.static final intCentral directory (CEN) header size in bytes (including signature).static final intCentral directory (CEN) header compression method field offset.static final intCentral directory (CEN) header uncompressed size field offset.static final intCentral directory (CEN) header filename length field offset.static final intCentral directory (CEN) header LOC header offset field offset.static final longCentral directory (CEN) header signature.static final intCentral directory (CEN) header compressed size field offset.static final intCentral directory (CEN) header modification time field offset.static final intCentral directory (CEN) header version made by field offset.static final intCentral directory (CEN) header version needed to extract field offset.static final intCompression method for compressed (DEFLATED) entries.static final intEnd of central directory (END) header ZIP file comment length field offset.static final intEnd of central directory (END) header size in bytes (including signature).static final intEnd of central directory (END) header offset for the first CEN header field offset.static final longEnd of central directory (END) header signature.static final intEnd of central directory (END) header central directory size in bytes field offset.static final intEnd of central directory (END) header number of entries on this disk field offset.static final intEnd of central directory (END) header total number of entries field offset.static final intExtra local (EXT) header uncompressed file crc-32 value field offset.static final intExtra local (EXT) header size in bytes (including signature).static final intExtra local (EXT) header uncompressed size field offset.static final longExtra local (EXT) header signature.static final intExtra local (EXT) header compressed size field offset.static final intLocal file (LOC) header uncompressed file crc-32 value field offset.static final intLocal file (LOC) header extra field length field offset.static final intLocal file (LOC) header general purpose bit flag field offset.static final intLocal file (LOC) header size in bytes (including signature).static final intLocal file (LOC) header compression method field offset.static final intLocal file (LOC) header uncompressed size field offset.static final intLocal file (LOC) header filename length field offset.static final longLocal file (LOC) header signature.static final intLocal file (LOC) header compressed size field offset.static final intLocal file (LOC) header modification time field offset.static final intLocal file (LOC) header version needed to extract field offset.static final intCompression method for uncompressed (STORED) entries.Fields declared in class java.util.zip.DeflaterOutputStreambuf, defFields declared in class java.io.FilterOutputStreamout
- 
Constructor SummaryConstructorsConstructorDescriptionCreates a new ZIP output stream.ZipOutputStream(OutputStream out, Charset charset) Creates a new ZIP output stream.
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()Closes the underlying stream and the stream being filtered after the contents of the ZIP output stream are fully written.voidCloses 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.voidBegins 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, writeMethods declared in class java.io.FilterOutputStreamwriteMethods declared in class java.io.OutputStreamnullOutputStream
- 
Field Details- 
STOREDpublic static final int STOREDCompression method for uncompressed (STORED) entries.- See Also:
 
- 
DEFLATEDpublic static final int DEFLATEDCompression method for compressed (DEFLATED) entries.- See Also:
 
- 
LOCSIGstatic final long LOCSIGLocal file (LOC) header signature.- See Also:
 
- 
EXTSIGstatic final long EXTSIGExtra local (EXT) header signature.- See Also:
 
- 
CENSIGstatic final long CENSIGCentral directory (CEN) header signature.- See Also:
 
- 
ENDSIGstatic final long ENDSIGEnd of central directory (END) header signature.- See Also:
 
- 
LOCHDRstatic final int LOCHDRLocal file (LOC) header size in bytes (including signature).- See Also:
 
- 
EXTHDRstatic final int EXTHDRExtra local (EXT) header size in bytes (including signature).- See Also:
 
- 
CENHDRstatic final int CENHDRCentral directory (CEN) header size in bytes (including signature).- See Also:
 
- 
ENDHDRstatic final int ENDHDREnd of central directory (END) header size in bytes (including signature).- See Also:
 
- 
LOCVERstatic final int LOCVERLocal file (LOC) header version needed to extract field offset.- See Also:
 
- 
LOCFLGstatic final int LOCFLGLocal file (LOC) header general purpose bit flag field offset.- See Also:
 
- 
LOCHOWstatic final int LOCHOWLocal file (LOC) header compression method field offset.- See Also:
 
- 
LOCTIMstatic final int LOCTIMLocal file (LOC) header modification time field offset.- See Also:
 
- 
LOCCRCstatic final int LOCCRCLocal file (LOC) header uncompressed file crc-32 value field offset.- See Also:
 
- 
LOCSIZstatic final int LOCSIZLocal file (LOC) header compressed size field offset.- See Also:
 
- 
LOCLENstatic final int LOCLENLocal file (LOC) header uncompressed size field offset.- See Also:
 
- 
LOCNAMstatic final int LOCNAMLocal file (LOC) header filename length field offset.- See Also:
 
- 
LOCEXTstatic final int LOCEXTLocal file (LOC) header extra field length field offset.- See Also:
 
- 
EXTCRCstatic final int EXTCRCExtra local (EXT) header uncompressed file crc-32 value field offset.- See Also:
 
- 
EXTSIZstatic final int EXTSIZExtra local (EXT) header compressed size field offset.- See Also:
 
- 
EXTLENstatic final int EXTLENExtra local (EXT) header uncompressed size field offset.- See Also:
 
- 
CENVEMstatic final int CENVEMCentral directory (CEN) header version made by field offset.- See Also:
 
- 
CENVERstatic final int CENVERCentral directory (CEN) header version needed to extract field offset.- See Also:
 
- 
CENFLGstatic final int CENFLGCentral directory (CEN) header encrypt, decrypt flags field offset.- See Also:
 
- 
CENHOWstatic final int CENHOWCentral directory (CEN) header compression method field offset.- See Also:
 
- 
CENTIMstatic final int CENTIMCentral directory (CEN) header modification time field offset.- See Also:
 
- 
CENCRCstatic final int CENCRCCentral directory (CEN) header uncompressed file crc-32 value field offset.- See Also:
 
- 
CENSIZstatic final int CENSIZCentral directory (CEN) header compressed size field offset.- See Also:
 
- 
CENLENstatic final int CENLENCentral directory (CEN) header uncompressed size field offset.- See Also:
 
- 
CENNAMstatic final int CENNAMCentral directory (CEN) header filename length field offset.- See Also:
 
- 
CENEXTstatic final int CENEXTCentral directory (CEN) header extra field length field offset.- See Also:
 
- 
CENCOMstatic final int CENCOMCentral directory (CEN) header comment length field offset.- See Also:
 
- 
CENDSKstatic final int CENDSKCentral directory (CEN) header disk number start field offset.- See Also:
 
- 
CENATTstatic final int CENATTCentral directory (CEN) header internal file attributes field offset.- See Also:
 
- 
CENATXstatic final int CENATXCentral directory (CEN) header external file attributes field offset.- See Also:
 
- 
CENOFFstatic final int CENOFFCentral directory (CEN) header LOC header offset field offset.- See Also:
 
- 
ENDSUBstatic final int ENDSUBEnd of central directory (END) header number of entries on this disk field offset.- See Also:
 
- 
ENDTOTstatic final int ENDTOTEnd of central directory (END) header total number of entries field offset.- See Also:
 
- 
ENDSIZstatic final int ENDSIZEnd of central directory (END) header central directory size in bytes field offset.- See Also:
 
- 
ENDOFFstatic final int ENDOFFEnd of central directory (END) header offset for the first CEN header field offset.- See Also:
 
- 
ENDCOMstatic final int ENDCOMEnd of central directory (END) header ZIP file comment length field offset.- See Also:
 
 
- 
- 
Constructor Details- 
ZipOutputStreamCreates a new ZIP output stream.The UTF-8 charsetis used to encode the entry names and comments.- Parameters:
- out- the actual output stream
 
- 
ZipOutputStreamCreates 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 Details- 
setCommentSets 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
 
- 
putNextEntryBegins 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. When writing a compressed (DEFLATED) entry, and the compressed size has not been explicitly set with the ZipEntry.setCompressedSize(long)method, then the compressed size will be set to the actual compressed size after deflation.The current time will be used if the entry has no set modification time. - API Note:
- When writing a directory entry, the STORED compression method
 should be used and the size and CRC-32 values should be set to 0:
 
This allows optimal performance when processing directory entries.ZipEntry e = new ZipEntry(entryName); if (e.isDirectory()) { e.setMethod(ZipEntry.STORED); e.setSize(0); e.setCrc(0); } stream.putNextEntry(e);
- 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
 
- 
closeEntryCloses 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
 
- 
writeWrites 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:
 
- 
finishFinishes 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.A ZipException will be thrown if the combined length, after encoding, of the entry name, the extra field data, the entry comment and CEN Header size, exceeds 65,535 bytes. - Overrides:
- finishin class- DeflaterOutputStream
- Throws:
- ZipException- if a ZIP file error has occurred
- IOException- if an I/O exception has occurred
 
- 
closeCloses the underlying stream and the stream being filtered after the contents of the ZIP output stream are fully written.- 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:
 
 
-