Package proguard.io
Class ZipOutput
java.lang.Object
proguard.io.ZipOutput
This class writes zip data to a given output stream. It returns a new output stream for each zip
entry that is opened. An entry can be compressed or uncompressed. Uncompressed entries can be
aligned to a multiple of a given number of bytes.
Multiple entries and output streams can be open at the same time. The entries are added to the central directory in the order in which they are opened, but the corresponding data are only written when their output streams are closed.
The code automatically computes the CRC and lengths of the data, for compressed and uncompressed data.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThis output stream is mostly identical to DataOutputStream, except it stores the amount of bytes written so far in a long instead of an int. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionZipOutput(OutputStream outputStream) Creates a new ZipOutput.ZipOutput(OutputStream outputStream, boolean useZip64) Creates a new ZipOutput.ZipOutput(OutputStream outputStream, boolean useZip64, int uncompressedAlignment) Creates a new ZipOutput that aligns uncompressed entries.ZipOutput(OutputStream outputStream, byte[] header, int uncompressedAlignment, boolean useZip64) Creates a new ZipOutput that aligns uncompressed entries.ZipOutput(OutputStream outputStream, byte[] header, int uncompressedAlignment, boolean useZip64, String comment) Creates a new ZipOutput that aligns uncompressed entries and contains a comment.ZipOutput(OutputStream outputStream, int uncompressedAlignment) Creates a new ZipOutput that aligns uncompressed entries.ZipOutput(OutputStream outputStream, int uncompressedAlignment, boolean useZip64, String comment) Creates a new ZipOutput that aligns uncompressed entries and contains a comment. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the zip archive, writing out its central directory and closing the underlying output stream.voidclose(long centralDirectoryOffset) Closes the zip archive, writing out its central directory and closing the underlying output stream.createOutputStream(String name, boolean compress, int modificationTime) Creates a new zip entry, returning an output stream to write its data.createOutputStream(String name, boolean compress, int uncompressedAlignment, int modificationTime) Creates a new zip entry, returning an output stream to write its data.createOutputStream(String name, boolean compress, int uncompressedAlignment, int modificationTime, byte[] extraField, String comment) Creates a new zip entry, returning an output stream to write its data.static voidProvides a simple test for this class, creating a zip file with the given name and a few aligned/compressed/uncompressed zip entries.protected longsize()Returns the current size of the data written to the output stream.protected voidwriteEndOfCentralDirectory(long centralDirectoryOffset, long centralDirectorySize) Ends the central directory.protected longWrites the zip entries in the central directory.protected voidwriteInt(int value) Writes out a little-endian int value to the zip output stream.protected voidwriteInt(long value) Writes out a little-endian int value to the zip output stream.protected voidwriteLong(long value) Writes out a little-endian long value to the zip output stream.protected voidwriteShort(int value) Writes out a little-endian short value to the zip output stream.protected longStarts the central directory.protected voidwriteZip64EndOfCentralDirectory(long centralDirectoryOffset, long centralDirectorySize) Writes out a ZIP64 end of central directory entry.protected voidwriteZip64EndOfCentralDirectoryLocator(long zip64CentralDirectoryOffset) Writes out a ZIP64 end of central directory locator.
-
Field Details
-
outputStream
-
-
Constructor Details
-
ZipOutput
Creates a new ZipOutput.- Parameters:
outputStream- the output stream to which the zip data will be written.
-
ZipOutput
Creates a new ZipOutput.- Parameters:
outputStream- the output stream to which the zip data will be written.useZip64- Whether to write out the archive in zip64 format.
-
ZipOutput
Creates a new ZipOutput that aligns uncompressed entries.- Parameters:
outputStream- the output stream to which the zip data will be written.uncompressedAlignment- the default alignment of uncompressed data.
-
ZipOutput
Creates a new ZipOutput that aligns uncompressed entries.- Parameters:
outputStream- the output stream to which the zip data will be written.useZip64- Whether to write out the archive in zip64 format.uncompressedAlignment- the default alignment of uncompressed data.
-
ZipOutput
public ZipOutput(OutputStream outputStream, int uncompressedAlignment, boolean useZip64, String comment) Creates a new ZipOutput that aligns uncompressed entries and contains a comment.- Parameters:
outputStream- the output stream to which the zip data will be written.uncompressedAlignment- the default alignment of uncompressed data.useZip64- Whether to write out the archive in zip64 format.comment- optional comment for the entire zip file.
-
ZipOutput
public ZipOutput(OutputStream outputStream, byte[] header, int uncompressedAlignment, boolean useZip64) throws IOException Creates a new ZipOutput that aligns uncompressed entries.- Parameters:
outputStream- the output stream to which the zip data will be written.header- an optional header for the zip file.useZip64- Whether to write out the archive in zip64 format.uncompressedAlignment- the requested alignment of uncompressed data.- Throws:
IOException
-
ZipOutput
public ZipOutput(OutputStream outputStream, byte[] header, int uncompressedAlignment, boolean useZip64, String comment) throws IOException Creates a new ZipOutput that aligns uncompressed entries and contains a comment.- Parameters:
outputStream- the output stream to which the zip data will be written.header- an optional header for the zip file.uncompressedAlignment- the requested alignment of uncompressed data.useZip64- Whether to write out the archive in zip64 format.comment- optional comment for the entire zip file.- Throws:
IOException
-
-
Method Details
-
createOutputStream
public OutputStream createOutputStream(String name, boolean compress, int modificationTime) throws IOException Creates a new zip entry, returning an output stream to write its data. It is the caller's responsibility to close the output stream.- Parameters:
name- the name of the zip entry.compress- specifies whether the entry should be compressed with the default alignment.modificationTime- the modification date and time of the zip entry, in DOS format.- Returns:
- an output stream for writing the data of the zip entry.
- Throws:
IOException
-
createOutputStream
public OutputStream createOutputStream(String name, boolean compress, int uncompressedAlignment, int modificationTime) throws IOException Creates a new zip entry, returning an output stream to write its data. It is the caller's responsibility to close the output stream.- Parameters:
name- the name of the zip entry.compress- specifies whether the entry should be compressed.uncompressedAlignment- the requested alignment of uncompressed data.modificationTime- the modification date and time of the zip entry, in DOS format.- Returns:
- an output stream for writing the data of the zip entry.
- Throws:
IOException
-
createOutputStream
public OutputStream createOutputStream(String name, boolean compress, int uncompressedAlignment, int modificationTime, byte[] extraField, String comment) throws IOException Creates a new zip entry, returning an output stream to write its data. It is the caller's responsibility to close the output stream.- Parameters:
name- the name of the zip entry.compress- specifies whether the entry should be compressed.uncompressedAlignment- the requested alignment of uncompressed data.modificationTime- the modification date and time of the zip entry, in DOS format.extraField- optional extra field data. These should contain chunks, each with a short ID, a short length (little endian), and their corresponding data. The IDs 0-31 are reserved for Pkware. Java's jar tool just specifies an ID 0xcafe on its first entry.comment- an optional comment.- Returns:
- an output stream for writing the data of the zip entry.
- Throws:
IOException
-
close
Closes the zip archive, writing out its central directory and closing the underlying output stream.- Throws:
IOException
-
close
Closes the zip archive, writing out its central directory and closing the underlying output stream.- Throws:
IOException
-
size
protected long size()Returns the current size of the data written to the output stream. -
writeStartOfCentralDirectory
protected long writeStartOfCentralDirectory()Starts the central directory.- Returns:
- the current position in the output stream.
-
writeEntriesOfCentralDirectory
Writes the zip entries in the central directory.- Returns:
- the total size of the directory entries.
- Throws:
IOException
-
writeEndOfCentralDirectory
protected void writeEndOfCentralDirectory(long centralDirectoryOffset, long centralDirectorySize) throws IOException Ends the central directory.- Parameters:
centralDirectoryOffset- the offset of the central directory.centralDirectorySize- the size of the central directory, not counting the empty header and the trailer.- Throws:
IOException
-
writeZip64EndOfCentralDirectory
protected void writeZip64EndOfCentralDirectory(long centralDirectoryOffset, long centralDirectorySize) throws IOException Writes out a ZIP64 end of central directory entry.- Parameters:
centralDirectoryOffset- The offset from the start of the archive to the first central directory record.centralDirectorySize- The total size of all central directory records.- Throws:
IOException- In case a problem occurs during writing.
-
writeZip64EndOfCentralDirectoryLocator
protected void writeZip64EndOfCentralDirectoryLocator(long zip64CentralDirectoryOffset) throws IOException Writes out a ZIP64 end of central directory locator.- Parameters:
zip64CentralDirectoryOffset- The offset to the zip64 end of central directory record.- Throws:
IOException- In case a problem occurs during writing.
-
writeShort
Writes out a little-endian short value to the zip output stream.- Throws:
IOException
-
writeInt
Writes out a little-endian int value to the zip output stream.- Throws:
IOException
-
writeInt
Writes out a little-endian int value to the zip output stream.- Throws:
IOException
-
writeLong
Writes out a little-endian long value to the zip output stream.- Throws:
IOException
-
main
Provides a simple test for this class, creating a zip file with the given name and a few aligned/compressed/uncompressed zip entries.
-