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:
Closeable,Flushable,AutoCloseable,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
FieldsModifier and TypeFieldDescriptionprivate final CRC32private ZipEntryprivate intprivate intstatic final intCompression method.private Vectorprivate intprivate intstatic final intCompression method.private static final intprivate static final intOur Zip version is hard coded to 1.0 resp.private byte[]Fields inherited from class net.sf.jazzlib.DeflaterOutputStream
buf, defFields inherited from class java.io.FilterOutputStream
outFields 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
ConstructorsConstructorDescriptionCreates a new Zip output stream, writing a zip archive. -
Method Summary
Modifier and TypeMethodDescriptionvoidCloses the current entry.voidfinish()Finishes the stream.voidputNextEntry(ZipEntry entry) Starts a new Zip entry.voidsetComment(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 final voidwriteLeInt(int value) Write an int in little endian byte order.private final voidwriteLeShort(int value) Write an unsigned short in little endian byte order.Methods inherited from class net.sf.jazzlib.DeflaterOutputStream
close, deflate, flush, writeMethods inherited from class java.io.FilterOutputStream
writeMethods inherited from class java.io.OutputStream
nullOutputStream
-
Field Details
-
entries
-
crc
-
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_VERSIONOur Zip version is hard coded to 1.0 resp. 2.0- See Also:
-
ZIP_DEFLATED_VERSION
private static final int ZIP_DEFLATED_VERSION- See Also:
-
STORED
public static final int STOREDCompression method. This method doesn't compress at all.- See Also:
-
DEFLATED
public static final int DEFLATEDCompression method. This method uses the Deflater.- See Also:
-
-
Constructor Details
-
ZipOutputStream
Creates a new Zip output stream, writing a zip archive.- Parameters:
out- the output stream to which the zip archive is written.
-
-
Method Details
-
setComment
Set the zip file comment.- Parameters:
comment- the comment.- Throws:
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.- Parameters:
method- the method.- Throws:
IllegalArgumentException- if method is not supported.- See Also:
-
setLevel
public void setLevel(int level) Sets default compression level. The new level will be activated immediately.- Throws:
IllegalArgumentException- if level is not supported.- See Also:
-
writeLeShort
Write an unsigned short in little endian byte order.- Throws:
IOException
-
writeLeInt
Write an int in little endian byte order.- Throws:
IOException
-
putNextEntry
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:
IOException- if an I/O error occured.ZipException- if stream was finished.
-
closeEntry
Closes the current entry.- Throws:
IOException- if an I/O error occured.ZipException- if no entry is active.
-
write
Writes 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:
IOException- if an I/O error occured.ZipException- if no entry is active.
-
finish
Finishes the stream. This will write the central directory at the end of the zip file and flush the stream.- Overrides:
finishin classDeflaterOutputStream- Throws:
IOException- if an I/O error occured.
-