类 ZipOutputStream
- 所有已实现的接口:
Closeable,Flushable,AutoCloseable
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 putNextEntry can be called.
-
嵌套类概要
嵌套类修饰符和类型类说明static final classenum that represents the possible policies for creating Unicode extra fields. -
字段概要
字段修饰符和类型字段说明protected byte[]This buffer servers as a Deflater.protected static final byte[]central file header signatureprotected static final byte[]data descriptor signatureprotected DeflaterThis Deflater object is used for output.static final intDefault compression level for deflated entries.static final intCompression method for deflated entries.static final intGeneral purpose flag, which indicates that filenames are written in utf-8.protected static final byte[]end of central dir signatureprotected static final byte[]local file header signaturestatic final intCompression method for stored entries.static final intGeneral purpose flag, which indicates that filenames are written in utf-8.从类继承的字段 java.io.FilterOutputStream
out -
构造器概要
构造器构造器说明ZipOutputStream(File file) Creates a new ZIP OutputStream writing to a File.Creates a new ZIP OutputStream filtering the underlying stream. -
方法概要
修饰符和类型方法说明protected static longadjustToLong(int i) Assumes a negative integer really is a positive integer that has wrapped around and re-creates the original value.voidclose()Closes this output stream and releases any system resources associated with the stream.voidWrites all necessary data for this entry.protected final voiddeflate()Writes next block of compressed data to the output stream.voidfinish()Finishs writing the contents and closes this as well as the underlying stream.voidflush()Flushes this output stream and forces any buffered output bytes to be written out to the stream.protected byte[]Retrieve the bytes for the given String in the encoding set for this Stream.The encoding to use for filenames and the file comment.booleanThis method indicates whether this archive is writing to a seekable stream (i.e., to a random access file).voidputNextEntry(ZipEntry ze) Begin writing next entry.voidsetComment(String comment) Set the file comment.voidWhether to create Unicode Extra Fields.voidsetEncoding(String encoding) The encoding to use for filenames and the file comment.voidsetFallbackToUTF8(boolean b) Whether to fall back to UTF and the language encoding flag if the file name cannot be encoded using the specified encoding.voidsetLevel(int level) Sets the compression level for subsequent entries.voidsetMethod(int method) Sets the default compression method for subsequent entries.voidsetUseLanguageEncodingFlag(boolean b) Whether to set the language encoding flag if the file name encoding is UTF-8.protected static byte[]toDosTime(long t) Convert a Date object to a DOS date/time field.protected static ZipLongConvert a Date object to a DOS date/time field.voidwrite(byte[] b, int offset, int length) Writes bytes to ZIP entry.voidwrite(int b) Writes a single byte to ZIP entry.protected voidWrites the "End of central dir record".protected voidWrites the central file header entry.protected voidWrites the data descriptor entry.protected voidWrites the local file header entryprotected final voidwriteOut(byte[] data) Write bytes to output or random access file.protected final voidwriteOut(byte[] data, int offset, int length) Write bytes to output or random access file.从类继承的方法 java.io.FilterOutputStream
write从类继承的方法 java.io.OutputStream
nullOutputStream
-
字段详细资料
-
DEFLATED
public static final int DEFLATEDCompression method for deflated entries.- 从以下版本开始:
- 1.1
- 另请参阅:
-
DEFAULT_COMPRESSION
public static final int DEFAULT_COMPRESSIONDefault compression level for deflated entries.- 从以下版本开始:
- Ant 1.7
- 另请参阅:
-
STORED
public static final int STOREDCompression method for stored entries.- 从以下版本开始:
- 1.1
- 另请参阅:
-
UFT8_NAMES_FLAG
public static final int UFT8_NAMES_FLAGGeneral purpose flag, which indicates that filenames are written in utf-8.- 另请参阅:
-
EFS_FLAG
public static final int EFS_FLAGGeneral purpose flag, which indicates that filenames are written in utf-8. useUFT8_NAMES_FLAGinstead- 另请参阅:
-
def
This Deflater object is used for output.This attribute is only protected to provide a level of API backwards compatibility. This class used to extend
DeflaterOutputStreamup to Revision 1.13.- 从以下版本开始:
- 1.14
-
buf
protected byte[] bufThis buffer servers as a Deflater.This attribute is only protected to provide a level of API backwards compatibility. This class used to extend
DeflaterOutputStreamup to Revision 1.13.- 从以下版本开始:
- 1.14
-
LFH_SIG
protected static final byte[] LFH_SIGlocal file header signature- 从以下版本开始:
- 1.1
-
DD_SIG
protected static final byte[] DD_SIGdata descriptor signature- 从以下版本开始:
- 1.1
-
CFH_SIG
protected static final byte[] CFH_SIGcentral file header signature- 从以下版本开始:
- 1.1
-
EOCD_SIG
protected static final byte[] EOCD_SIGend of central dir signature- 从以下版本开始:
- 1.1
-
-
构造器详细资料
-
ZipOutputStream
Creates a new ZIP OutputStream filtering the underlying stream.- 参数:
out- the outputstream to zip- 从以下版本开始:
- 1.1
-
ZipOutputStream
Creates a new ZIP OutputStream writing to a File. Will use random access if possible.- 参数:
file- the file to zip to- 抛出:
IOException- on error- 从以下版本开始:
- 1.14
-
-
方法详细资料
-
isSeekable
public boolean isSeekable()This method indicates whether this archive is writing to a seekable stream (i.e., to a random access file).For seekable streams, you don't need to calculate the CRC or uncompressed size for
STOREDentries before invokingputNextEntry(com.sh.common.zip.ZipEntry).- 返回:
- true if seekable
- 从以下版本开始:
- 1.17
-
setEncoding
The encoding to use for filenames and the file comment.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 value- 从以下版本开始:
- 1.3
-
getEncoding
The encoding to use for filenames and the file comment.- 返回:
- null if using the platform's default character encoding.
- 从以下版本开始:
- 1.3
-
setUseLanguageEncodingFlag
public void setUseLanguageEncodingFlag(boolean b) Whether to set the language encoding flag if the file name encoding is UTF-8.Defaults to true.
- 参数:
b- boolean
-
setCreateUnicodeExtraFields
Whether to create Unicode Extra Fields.Defaults to NEVER.
- 参数:
b- UnicodeExtraFieldPolicy
-
setFallbackToUTF8
public 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.Defaults to false.
- 参数:
b- boolean
-
finish
Finishs writing the contents and closes this as well as the underlying stream.- 抛出:
IOException- on error- 从以下版本开始:
- 1.1
-
closeEntry
Writes all necessary data for this entry.- 抛出:
IOException- on error- 从以下版本开始:
- 1.1
-
putNextEntry
Begin writing next entry.- 参数:
ze- the entry to write- 抛出:
IOException- on error- 从以下版本开始:
- 1.1
-
setComment
Set the file comment.- 参数:
comment- the comment- 从以下版本开始:
- 1.1
-
setLevel
public void setLevel(int level) Sets the compression level for subsequent entries.Default is Deflater.DEFAULT_COMPRESSION.
- 参数:
level- the compression level.- 抛出:
IllegalArgumentException- if an invalid compression level is specified.- 从以下版本开始:
- 1.1
-
setMethod
public void setMethod(int method) Sets the default compression method for subsequent entries.Default is DEFLATED.
- 参数:
method- anintfrom java.util.zip.ZipEntry- 从以下版本开始:
- 1.1
-
write
Writes bytes to ZIP entry.- 覆盖:
write在类中FilterOutputStream- 参数:
b- the byte array to writeoffset- the start position to write fromlength- the number of bytes to write- 抛出:
IOException- on error
-
write
Writes a single byte to ZIP entry.Delegates to the three arg method.
- 覆盖:
write在类中FilterOutputStream- 参数:
b- the byte to write- 抛出:
IOException- on error- 从以下版本开始:
- 1.14
-
close
Closes this output stream and releases any system resources associated with the stream.- 指定者:
close在接口中AutoCloseable- 指定者:
close在接口中Closeable- 覆盖:
close在类中FilterOutputStream- 抛出:
IOException- if an I/O error occurs.- 从以下版本开始:
- 1.14
-
flush
Flushes this output stream and forces any buffered output bytes to be written out to the stream.- 指定者:
flush在接口中Flushable- 覆盖:
flush在类中FilterOutputStream- 抛出:
IOException- if an I/O error occurs.- 从以下版本开始:
- 1.14
-
deflate
Writes next block of compressed data to the output stream.- 抛出:
IOException- on error- 从以下版本开始:
- 1.14
-
writeLocalFileHeader
Writes the local file header entry- 参数:
ze- the entry to write- 抛出:
IOException- on error- 从以下版本开始:
- 1.1
-
writeDataDescriptor
Writes the data descriptor entry.- 参数:
ze- the entry to write- 抛出:
IOException- on error- 从以下版本开始:
- 1.1
-
writeCentralFileHeader
Writes the central file header entry.- 参数:
ze- the entry to write- 抛出:
IOException- on error- 从以下版本开始:
- 1.1
-
writeCentralDirectoryEnd
Writes the "End of central dir record".- 抛出:
IOException- on error- 从以下版本开始:
- 1.1
-
toDosTime
Convert a Date object to a DOS date/time field.- 参数:
time- theDateto convert- 返回:
- the date as a
ZipLong - 从以下版本开始:
- 1.1
-
toDosTime
protected static byte[] toDosTime(long t) Convert a Date object to a DOS date/time field.Stolen from InfoZip's
fileio.c- 参数:
t- number of milliseconds since the epoch- 返回:
- the date as a byte array
- 从以下版本开始:
- 1.26
-
getBytes
Retrieve the bytes for the given String in the encoding set for this Stream.- 参数:
name- the string to get bytes from- 返回:
- the bytes as a byte array
- 抛出:
ZipException- on error- 从以下版本开始:
- 1.3
-
writeOut
Write bytes to output or random access file.- 参数:
data- the byte array to write- 抛出:
IOException- on error- 从以下版本开始:
- 1.14
-
writeOut
Write bytes to output or random access file.- 参数:
data- the byte array to writeoffset- the start position to write fromlength- the number of bytes to write- 抛出:
IOException- on error- 从以下版本开始:
- 1.14
-
adjustToLong
protected static long adjustToLong(int i) Assumes a negative integer really is a positive integer that has wrapped around and re-creates the original value.- 参数:
i- the value to treat as unsigned int.- 返回:
- the unsigned int as a long.
- 从以下版本开始:
- 1.34
-