Package net.sf.jazzlib
Class ZipOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- net.sf.jazzlib.DeflaterOutputStream
-
- net.sf.jazzlib.ZipOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable,ZipConstants
public class ZipOutputStream extends DeflaterOutputStream implements ZipConstants
This is a FilterOutputStream that writes the files into a zip archive one after another. It has a special method to start a new zip entry. The zip entries contains information about the file name size, compressed size, CRC, etc. It includes support for STORED and DEFLATED entries. This class is not thread safe.
-
-
Field Summary
Fields Modifier and Type Field Description private CRC32crcprivate ZipEntrycurEntryprivate intcurMethodprivate intdefaultMethodstatic intDEFLATEDCompression method.private java.util.Vectorentriesprivate intoffsetprivate intsizestatic intSTOREDCompression method.private static intZIP_DEFLATED_VERSIONprivate static intZIP_STORED_VERSIONOur Zip version is hard coded to 1.0 resp.private byte[]zipComment-
Fields inherited from class net.sf.jazzlib.DeflaterOutputStream
buf, def
-
Fields inherited from interface net.sf.jazzlib.ZipConstants
CENATT, CENATX, CENCOM, CENCRC, CENDSK, CENEXT, CENFLG, CENHDR, CENHOW, CENLEN, CENNAM, CENOFF, CENSIG, CENSIZ, CENTIM, CENVEM, CENVER, ENDCOM, ENDDCD, ENDHDR, ENDNRD, ENDOFF, ENDSIG, ENDSIZ, ENDSUB, ENDTOT, EXTCRC, EXTHDR, EXTLEN, EXTSIG, EXTSIZ, LOCCRC, LOCEXT, LOCFLG, LOCHDR, LOCHOW, LOCLEN, LOCNAM, LOCSIG, LOCSIZ, LOCTIM, LOCVER
-
-
Constructor Summary
Constructors Constructor Description ZipOutputStream(java.io.OutputStream out)Creates a new Zip output stream, writing a zip archive.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcloseEntry()Closes the current entry.voidfinish()Finishes the stream.voidputNextEntry(ZipEntry entry)Starts a new Zip entry.voidsetComment(java.lang.String comment)Set the zip file comment.voidsetLevel(int level)Sets default compression level.voidsetMethod(int method)Sets default compression method.voidwrite(byte[] b, int off, int len)Writes the given buffer to the current entry.private voidwriteLeInt(int value)Write an int in little endian byte order.private voidwriteLeShort(int value)Write an unsigned short in little endian byte order.-
Methods inherited from class net.sf.jazzlib.DeflaterOutputStream
close, deflate, flush, write
-
-
-
-
Field Detail
-
entries
private java.util.Vector entries
-
crc
private final CRC32 crc
-
curEntry
private ZipEntry curEntry
-
curMethod
private int curMethod
-
size
private int size
-
offset
private int offset
-
zipComment
private byte[] zipComment
-
defaultMethod
private int defaultMethod
-
ZIP_STORED_VERSION
private static final int ZIP_STORED_VERSION
Our Zip version is hard coded to 1.0 resp. 2.0- See Also:
- Constant Field Values
-
ZIP_DEFLATED_VERSION
private static final int ZIP_DEFLATED_VERSION
- See Also:
- Constant Field Values
-
STORED
public static final int STORED
Compression method. This method doesn't compress at all.- See Also:
- Constant Field Values
-
DEFLATED
public static final int DEFLATED
Compression method. This method uses the Deflater.- See Also:
- Constant Field Values
-
-
Method Detail
-
setComment
public void setComment(java.lang.String comment)
Set the zip file comment.- Parameters:
comment- the comment.- Throws:
java.lang.IllegalArgumentException- if encoding of comment is longer than 0xffff bytes.
-
setMethod
public void setMethod(int method)
Sets default compression method. If the Zip entry specifies another method its method takes precedence.
-
setLevel
public void setLevel(int level)
Sets default compression level. The new level will be activated immediately.- Throws:
java.lang.IllegalArgumentException- if level is not supported.- See Also:
Deflater
-
writeLeShort
private final void writeLeShort(int value) throws java.io.IOExceptionWrite an unsigned short in little endian byte order.- Throws:
java.io.IOException
-
writeLeInt
private final void writeLeInt(int value) throws java.io.IOExceptionWrite an int in little endian byte order.- Throws:
java.io.IOException
-
putNextEntry
public void putNextEntry(ZipEntry entry) throws java.io.IOException
Starts a new Zip entry. It automatically closes the previous entry if present. If the compression method is stored, the entry must have a valid size and crc, otherwise all elements (except name) are optional, but must be correct if present. If the time is not set in the entry, the current time is used.- Parameters:
entry- the entry.- Throws:
java.io.IOException- if an I/O error occured.ZipException- if stream was finished.
-
closeEntry
public void closeEntry() throws java.io.IOExceptionCloses the current entry.- Throws:
java.io.IOException- if an I/O error occured.ZipException- if no entry is active.
-
write
public void write(byte[] b, int off, int len) throws java.io.IOExceptionWrites the given buffer to the current entry.- Overrides:
writein classDeflaterOutputStream- Parameters:
b- the byte array.off- the offset into the byte array where to start.len- the number of bytes to write.- Throws:
java.io.IOException- if an I/O error occured.ZipException- if no entry is active.
-
finish
public void finish() throws java.io.IOExceptionFinishes the stream. This will write the central directory at the end of the zip file and flush the stream.- Overrides:
finishin classDeflaterOutputStream- Throws:
java.io.IOException- if an I/O error occured.
-
-