|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.io.OutputStream
org.apache.commons.compress.archivers.ArchiveOutputStream
org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
public class ZipArchiveOutputStream
Reimplementation of java.util.zip.ZipOutputStream that does handle 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 will try to use RandomAccessFile when you know that the output is going to go to a
file.
If RandomAccessFile cannot be used, this implementation will use
a Data Descriptor to store size and CRC information for DEFLATED entries, this means, you don't need to
calculate them yourself. Unfortunately this is not possible for
the STORED method, here setting the CRC and
uncompressed size information is required before putArchiveEntry(ArchiveEntry) can be called.
| Nested Class Summary | |
|---|---|
static class |
ZipArchiveOutputStream.UnicodeExtraFieldPolicy
enum that represents the possible policies for creating Unicode extra fields. |
| Field Summary | |
|---|---|
protected java.util.zip.Deflater |
def
This Deflater object is used for output. |
static int |
DEFAULT_COMPRESSION
Default compression level for deflated entries. |
static int |
DEFLATED
Compression method for deflated entries. |
static int |
EFS_FLAG
General purpose flag, which indicates that filenames are written in utf-8. |
protected boolean |
finished
indicates if this archive is finished. |
static int |
STORED
Compression method for stored entries. |
| Constructor Summary | |
|---|---|
ZipArchiveOutputStream(java.io.File file)
Creates a new ZIP OutputStream writing to a File. |
|
ZipArchiveOutputStream(java.io.OutputStream out)
Creates a new ZIP OutputStream filtering the underlying stream. |
|
| Method Summary | |
|---|---|
void |
close()
Closes this output stream and releases any system resources associated with the stream. |
void |
closeArchiveEntry()
Writes all necessary data for this entry. |
ArchiveEntry |
createArchiveEntry(java.io.File inputFile,
java.lang.String entryName)
Create an archive entry using the inputFile and entryName provided. |
protected void |
deflate()
Writes next block of compressed data to the output stream. |
void |
finish()
Finishes the addition of entries to this stream, without closing it. |
void |
flush()
Flushes this output stream and forces any buffered output bytes to be written out to the 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 seekable stream (i.e., to a random access file). |
void |
putArchiveEntry(ArchiveEntry archiveEntry)
Writes the headers for an archive entry to the output stream. |
void |
setComment(java.lang.String comment)
Set the file comment. |
void |
setCreateUnicodeExtraFields(ZipArchiveOutputStream.UnicodeExtraFieldPolicy b)
Whether to create Unicode Extra Fields. |
void |
setEncoding(java.lang.String encoding)
The encoding to use for filenames and the file comment. |
void |
setFallbackToUTF8(boolean b)
Whether to fall back to UTF and the language encoding flag if the file name cannot be encoded using the specified encoding. |
void |
setLevel(int level)
Sets the compression level for subsequent entries. |
void |
setMethod(int method)
Sets the default compression method for subsequent entries. |
void |
setUseLanguageEncodingFlag(boolean b)
Whether to set the language encoding flag if the file name encoding is UTF-8. |
void |
write(byte[] b,
int offset,
int length)
Writes bytes to ZIP entry. |
protected void |
writeCentralDirectoryEnd()
Writes the "End of central dir record". |
protected void |
writeCentralFileHeader(ZipArchiveEntry ze)
Writes the central file header entry. |
protected void |
writeDataDescriptor(ZipArchiveEntry ze)
Writes the data descriptor entry. |
protected void |
writeLocalFileHeader(ZipArchiveEntry ze)
Writes the local file header entry |
protected void |
writeOut(byte[] data)
Write bytes to output or random access file. |
protected void |
writeOut(byte[] data,
int offset,
int length)
Write bytes to output or random access file. |
| Methods inherited from class org.apache.commons.compress.archivers.ArchiveOutputStream |
|---|
count, getCount, write |
| Methods inherited from class java.io.OutputStream |
|---|
write |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected boolean finished
public static final int DEFLATED
public static final int DEFAULT_COMPRESSION
public static final int STORED
public static final int EFS_FLAG
protected final java.util.zip.Deflater def
| Constructor Detail |
|---|
public ZipArchiveOutputStream(java.io.OutputStream out)
out - the outputstream to zip
public ZipArchiveOutputStream(java.io.File file)
throws java.io.IOException
file - the file to zip to
java.io.IOException - on error| Method Detail |
|---|
public boolean isSeekable()
For seekable streams, you don't need to calculate the CRC or
uncompressed size for STORED entries before
invoking putArchiveEntry(ArchiveEntry).
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 UTF-8.
encoding - the encoding to use for file names, use null
for the platform's default encodingpublic java.lang.String getEncoding()
public void setUseLanguageEncodingFlag(boolean b)
Defaults to true.
public void setCreateUnicodeExtraFields(ZipArchiveOutputStream.UnicodeExtraFieldPolicy b)
Defaults to NEVER.
public void setFallbackToUTF8(boolean b)
Defaults to false.
public void finish()
throws java.io.IOException
ArchiveOutputStream
finish in class ArchiveOutputStreamjava.io.IOException
public void closeArchiveEntry()
throws java.io.IOException
closeArchiveEntry in class ArchiveOutputStreamjava.io.IOException - on error
public void putArchiveEntry(ArchiveEntry archiveEntry)
throws java.io.IOException
ArchiveOutputStream.closeArchiveEntry() to complete the process.
putArchiveEntry in class ArchiveOutputStreamarchiveEntry - describes the entry
java.io.IOExceptionpublic 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
public void write(byte[] b,
int offset,
int length)
throws java.io.IOException
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 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.
protected final void deflate()
throws java.io.IOException
java.io.IOException - on error
protected void writeLocalFileHeader(ZipArchiveEntry ze)
throws java.io.IOException
ze - the entry to write
java.io.IOException - on error
protected void writeDataDescriptor(ZipArchiveEntry ze)
throws java.io.IOException
ze - the entry to write
java.io.IOException - on error
protected void writeCentralFileHeader(ZipArchiveEntry ze)
throws java.io.IOException
ze - the entry to write
java.io.IOException - on error
protected void writeCentralDirectoryEnd()
throws java.io.IOException
java.io.IOException - on error
protected final void writeOut(byte[] data)
throws java.io.IOException
data - the byte array to write
java.io.IOException - on error
protected final void writeOut(byte[] data,
int offset,
int length)
throws java.io.IOException
data - the byte array to writeoffset - the start position to write fromlength - the number of bytes to write
java.io.IOException - on error
public ArchiveEntry createArchiveEntry(java.io.File inputFile,
java.lang.String entryName)
throws java.io.IOException
ArchiveOutputStream
createArchiveEntry in class ArchiveOutputStreamjava.io.IOException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||