|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.io.OutputStream
com.mucommander.file.impl.zip.provider.ZipOutputStream
public class ZipOutputStream
Reimplementation of java.util.zip.ZipOutputStream that handles the extended
functionality of this package, especially internal/external file attributes and extra fields with different layouts
for local file data and central directory entries.
--------------------------------------------------------------------------------------------------------------
This class is based off the org.apache.tools.zip package of the Apache Ant project. The Ant
code has been modified under the terms of the Apache License which you can find in the bundled muCommander license
file. It was forked at version 1.7.0 of Ant.
| Field Summary | |
|---|---|
protected java.util.zip.Deflater |
deflater
Deflater instance that is used to compress DEFLATED entries |
protected byte[] |
deflaterBuf
Buffer used by Deflater to deflate data |
protected java.io.OutputStream |
out
The underlying stream this ZipOutputStream writes zip-compressed data to. |
| Fields inherited from interface com.mucommander.file.impl.zip.provider.ZipConstants |
|---|
CFH_SIG, DD_SIG, DEFAULT_DEFLATER_BUFFER_SIZE, DEFAULT_DEFLATER_COMPRESSION, DEFLATED, EOCD_SIG, LFH_SIG, MAX_ZIP32_SIZE, STORED, UTF_8, WRITE_BUFFER_SIZE |
| Constructor Summary | |
|---|---|
ZipOutputStream(java.io.OutputStream out)
Creates a new ZipOutputStream that writes Zip-compressed data to the given OutputStream. |
|
| Method Summary | |
|---|---|
protected static long |
adjustToLong(int i)
Returns a long that is the unsigned intepretation of the given (signed) int. |
void |
close()
Closes this output stream and releases any system resources associated with the stream. |
void |
closeEntry()
Writes all necessary data for this entry. |
protected static void |
finalizeEntryData(ZipEntry entry,
ZipEntryOutputStream zeos,
java.io.OutputStream out,
boolean useDataDescriptor,
ZipBuffer zipBuffer)
Writes the size and CRC information of an entry. |
void |
finish()
Finishs writing the contents and closes this as well as the underlying stream. |
void |
flush()
Flushes this output stream and forces any buffered output bytes to be written out to the stream. |
protected static byte[] |
getBytes(java.lang.String name,
java.lang.String encoding)
Retrieve the bytes for the given String in the encoding set for this Stream. |
java.lang.String |
getEncoding()
The encoding to use for filenames and the file comment. |
boolean |
isSeekable()
This method indicates whether this archive is writing to a RandomAccessOutputStream. |
void |
putNextEntry(ZipEntry ze)
Start writing the given entry. |
void |
setComment(java.lang.String comment)
Sets the file comment. |
void |
setEncoding(java.lang.String encoding)
The encoding to use for filenames and the file comment. |
void |
setLevel(int level)
Sets the compression level for subsequent entries. |
void |
setMethod(int method)
Sets the default compression method for subsequent entries. |
void |
write(byte[] b)
Writes the given bytes to the current Zip entry opened with putNextEntry(ZipEntry), using the entry's
compression method. |
void |
write(byte[] b,
int offset,
int length)
Writes the given bytes to the current Zip entry opened with putNextEntry(ZipEntry), using the entry's
compression method. |
void |
write(int b)
Writes a single byte to the current Zip entry opened with putNextEntry(ZipEntry), using the entry's
compression method. |
protected static void |
writeCentralDirectoryEnd(java.io.OutputStream out,
int nbEntries,
long cdLength,
long cdOffset,
java.lang.String comment,
java.lang.String encoding,
ZipBuffer zipBuffer)
Writes the end of the central directory record. |
protected static long |
writeCentralFileHeader(ZipEntry ze,
java.io.OutputStream out,
java.lang.String encoding,
long localFileHeaderOffset,
boolean useDataDescriptor,
ZipBuffer zipBuffer)
Writes the central file header for the given entry. |
protected static long |
writeDataDescriptor(ZipEntry ze,
java.io.OutputStream out,
ZipBuffer zipBuffer)
Writes the data descriptor, using the CRC, compressed and uncompressed size attributes contained in the given ZipEntry. |
protected static long |
writeLocalFileHeader(ZipEntry ze,
java.io.OutputStream out,
java.lang.String encoding,
boolean useDataDescriptor,
ZipBuffer zipBuffer)
Writes the local file header entry. |
protected static long |
writeVersionAndGPBF(java.io.OutputStream out,
java.lang.String encoding,
boolean useDataDescriptor)
Writes the 'version needed to extract' (2 bytes) and 'general purpose bit flag' (2 bytes) fields. |
protected static long |
writeVersionMadeBy(ZipEntry ze,
java.io.OutputStream out,
ZipBuffer zipBuffer)
Writes central file header's 'Version made by' field, using the platform contained in the given ZipEntry. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected java.util.zip.Deflater deflater
protected byte[] deflaterBuf
protected java.io.OutputStream out
| Constructor Detail |
|---|
public ZipOutputStream(java.io.OutputStream out)
ZipOutputStream that writes Zip-compressed data to the given OutputStream.
If a RandomAccessOutputStream is supplied, the Zip entries will be written without data descriptor,
which will yield a slightly smaller file.
out - the underlying OutputStream stream where compressed data is written to| Method Detail |
|---|
public boolean isSeekable()
RandomAccessOutputStream.
public void setEncoding(java.lang.String encoding)
For a list of possible values see http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html. Defaults to the platform's default character encoding.
encoding - the encoding valuepublic java.lang.String getEncoding()
public void finish()
throws java.io.IOException
java.io.IOException - on error
public void closeEntry()
throws java.io.IOException
putNextEntry(ZipEntry) has finished being written.
java.io.IOException - on error
protected static void finalizeEntryData(ZipEntry entry,
ZipEntryOutputStream zeos,
java.io.OutputStream out,
boolean useDataDescriptor,
ZipBuffer zipBuffer)
throws java.io.IOException
The size and CRC information is written to the given OutputStream, either as a data descriptor or
in the entry's local file header, and is set in the given ZipEntry instance.
entry - the entryzeos - the Zip entry's output streamout - theuseDataDescriptor - if true, a data descriptor will be written to out. If false, size and CRC information
will be written in the local file header (requires out to be a RandomAccessOutputStream).zipBuffer - a ZipBuffer instance used to convert integer values to Zip variants
java.io.IOException - if an I/O error occurred
public void putNextEntry(ZipEntry ze)
throws java.io.IOException
write() of this class.
When the entry has finished being written, closeEntry() must be called.
ze - the entry to write
java.io.IOException - on errorpublic void setComment(java.lang.String comment)
comment - the commentpublic void setLevel(int level)
Default is Deflater.DEFAULT_COMPRESSION.
level - the compression level.
java.lang.IllegalArgumentException - if an invalid compression level is specified.public void setMethod(int method)
Default is DEFLATED.
method - an int from java.util.zip.ZipEntry
protected static long writeLocalFileHeader(ZipEntry ze,
java.io.OutputStream out,
java.lang.String encoding,
boolean useDataDescriptor,
ZipBuffer zipBuffer)
throws java.io.IOException
ze - the entry to writeout - the OutputStream to write the header toencoding - the encoding to use for writing the entry's filename. If UTF-8 is used, the general purpose bit
flag will be set accordingly.useDataDescriptor - indicates whether a data descriptor will follow the file entry's data. The general
purpose bit flag will be set accordingly.zipBuffer - a ZipBuffer instance used to convert integer values to Zip variants
java.io.IOException - if an I/O error occurred
protected static long writeDataDescriptor(ZipEntry ze,
java.io.OutputStream out,
ZipBuffer zipBuffer)
throws java.io.IOException
ze - the entry for which to write the data descriptorout - the OutputStream where to write the data descriptor tozipBuffer - a ZipBuffer instance used to convert integer values to Zip variants
java.io.IOException - if an I/O error occurred
protected static long writeVersionMadeBy(ZipEntry ze,
java.io.OutputStream out,
ZipBuffer zipBuffer)
throws java.io.IOException
ze - the entry for which to write the 'Version made by' fieldout - the OutputStream where to write the fieldzipBuffer - a ZipBuffer instance used to convert integer values to Zip variants
java.io.IOException - if an I/O error occurred
protected static long writeCentralFileHeader(ZipEntry ze,
java.io.OutputStream out,
java.lang.String encoding,
long localFileHeaderOffset,
boolean useDataDescriptor,
ZipBuffer zipBuffer)
throws java.io.IOException
ze - the entry for which to write the central file headerout - the OutputStream to write the central file header toencoding - the encoding to use for writing the filename and optional commentlocalFileHeaderOffset - the offset to the local file header startuseDataDescriptor - true if a data descriptor is used for the entryzipBuffer - a ZipBuffer instance used to convert integer values to Zip variants
java.io.IOException - if an I/O error occurred
protected static long writeVersionAndGPBF(java.io.OutputStream out,
java.lang.String encoding,
boolean useDataDescriptor)
throws java.io.IOException
out - the OutputStream to write the fields toencoding - the encoding used for writing the filename and optional commentuseDataDescriptor - true if a data descriptor is used for the entry
java.io.IOException - if an I/O error occurred
protected static void writeCentralDirectoryEnd(java.io.OutputStream out,
int nbEntries,
long cdLength,
long cdOffset,
java.lang.String comment,
java.lang.String encoding,
ZipBuffer zipBuffer)
throws java.io.IOException
out - the OutputStream to write the end of the central directory record tonbEntries - number of entries the Zip file containscdLength - length (in bytes) of the central directory recordcdOffset - offset from the beginning of the Zip file to the start of the central directory recordcomment - the optional Zip file commentencoding - the encoding to use for writing the optional Zip commentzipBuffer - a ZipBuffer instance used to convert integer values to Zip variants
java.io.IOException - if an I/O error occurred
protected static byte[] getBytes(java.lang.String name,
java.lang.String encoding)
throws java.util.zip.ZipException
name - the string to get bytes fromencoding - the encoding the string is encoded with
java.util.zip.ZipException - on errorprotected static long adjustToLong(int i)
i - the value to treat as unsigned int
public void write(byte[] b,
int offset,
int length)
throws java.io.IOException
putNextEntry(ZipEntry), using the entry's
compression method. If no entry is currently open, the bytes will be written as-is to the underlying
OutputStream.
write in class java.io.OutputStreamb - the byte array to writeoffset - the start position to write fromlength - the number of bytes to write
java.io.IOException - on error
public void write(byte[] b)
throws java.io.IOException
putNextEntry(ZipEntry), using the entry's
compression method. If no entry is currently open, the bytes will be written as-is to the underlying
OutputStream.
write in class java.io.OutputStreamb - the byte array to write
java.io.IOException - on error
public void write(int b)
throws java.io.IOException
putNextEntry(ZipEntry), using the entry's
compression method. If no entry is currently open, the bytes will be written as-is to the underlying
OutputStream.
Delegates to the three arg method.
write in class java.io.OutputStreamb - the byte to write
java.io.IOException - on error
public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in class java.io.OutputStreamjava.io.IOException - if an I/O error occurs.
public void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.OutputStreamjava.io.IOException - if an I/O error occurs.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard