Most visited

Recently visited

Added in API level 1

ZipOutputStream

public class ZipOutputStream
extends DeflaterOutputStream

java.lang.Object
   ↳ java.io.OutputStream
     ↳ java.io.FilterOutputStream
       ↳ java.util.zip.DeflaterOutputStream
         ↳ java.util.zip.ZipOutputStream
Known Direct Subclasses


该类实现一个输出流过滤器,用于以ZIP文件格式写入文件。 包括对压缩和未压缩条目的支持。

Summary

Constants

int CENATT

int CENATX

int CENCOM

int CENCRC

int CENDSK

int CENEXT

int CENFLG

int CENHDR

int CENHOW

int CENLEN

int CENNAM

int CENOFF

long CENSIG

int CENSIZ

int CENTIM

int CENVEM

int CENVER

int DEFLATED

压缩(DEFLATED)条目的压缩方法。

int ENDCOM

int ENDHDR

int ENDOFF

long ENDSIG

int ENDSIZ

int ENDSUB

int ENDTOT

int EXTCRC

int EXTHDR

int EXTLEN

long EXTSIG

int EXTSIZ

int LOCCRC

int LOCEXT

int LOCFLG

int LOCHDR

int LOCHOW

int LOCLEN

int LOCNAM

long LOCSIG

int LOCSIZ

int LOCTIM

int LOCVER

int STORED

未压缩(STORED)条目的压缩方法。

Inherited fields

From class java.util.zip.DeflaterOutputStream
From class java.io.FilterOutputStream

Public constructors

ZipOutputStream(OutputStream out)

创建一个新的ZIP输出流。

ZipOutputStream(OutputStream out, Charset charset)

创建一个新的ZIP输出流。

Public methods

void close()

关闭ZIP输出流以及正在过滤的流。

void closeEntry()

关闭当前的ZIP条目并定位写入下一个条目的流。

void finish()

完成编写ZIP输出流的内容而不关闭底层流。

void putNextEntry(ZipEntry e)

开始编写新的ZIP文件条目并将流定位到条目数据的开头。

void setComment(String comment)

设置ZIP文件评论。

void setLevel(int level)

为后续的DEFLATED条目设置压缩级别。

void setMethod(int method)

为后续条目设置默认压缩方法。

void write(byte[] b, int off, int len)

将一个字节数组写入当前ZIP条目数据。

Inherited methods

From class java.util.zip.DeflaterOutputStream
From class java.io.FilterOutputStream
From class java.io.OutputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.io.Flushable
From interface java.lang.AutoCloseable

Constants

CENATT

Added in API level 21
int CENATT

常量值:36(0x00000024)

CENATX

Added in API level 21
int CENATX

常量值:38(0x00000026)

CENCOM

Added in API level 21
int CENCOM

常量值:32(0x00000020)

CENCRC

Added in API level 21
int CENCRC

常量值:16(0x00000010)

CENDSK

Added in API level 21
int CENDSK

常量值:34(0x00000022)

CENEXT

Added in API level 21
int CENEXT

常量值:30(0x0000001e)

CENFLG

Added in API level 21
int CENFLG

常量值:8(0x00000008)

CENHDR

Added in API level 21
int CENHDR

常量值:46(0x0000002e)

CENHOW

Added in API level 21
int CENHOW

常量值:10(0x0000000a)

CENLEN

Added in API level 21
int CENLEN

常量值:24(0x00000018)

CENNAM

Added in API level 21
int CENNAM

常量值:28(0x0000001c)

CENOFF

Added in API level 21
int CENOFF

常量值:42(0x0000002a)

CENSIG

Added in API level 21
long CENSIG

Constant Value: 33639248 (0x0000000002014b50)

CENSIZ

Added in API level 21
int CENSIZ

常量值:20(0x00000014)

CENTIM

Added in API level 21
int CENTIM

常量值:12(0x0000000c)

CENVEM

Added in API level 21
int CENVEM

常量值:4(0x00000004)

CENVER

Added in API level 21
int CENVER

常数值:6(0x00000006)

DEFLATED

Added in API level 1
int DEFLATED

压缩(DEFLATED)条目的压缩方法。

常量值:8(0x00000008)

ENDCOM

Added in API level 21
int ENDCOM

Constant Value: 20 (0x00000014)

ENDHDR

Added in API level 21
int ENDHDR

常量值:22(0x00000016)

ENDOFF

Added in API level 21
int ENDOFF

常量值:16(0x00000010)

ENDSIG

Added in API level 21
long ENDSIG

Constant Value: 101010256 (0x0000000006054b50)

ENDSIZ

Added in API level 21
int ENDSIZ

常量值:12(0x0000000c)

ENDSUB

Added in API level 21
int ENDSUB

常量值:8(0x00000008)

ENDTOT

Added in API level 21
int ENDTOT

常量值:10(0x0000000a)

EXTCRC

Added in API level 21
int EXTCRC

常量值:4(0x00000004)

EXTHDR

Added in API level 21
int EXTHDR

常量值:16(0x00000010)

EXTLEN

Added in API level 21
int EXTLEN

Constant Value: 12 (0x0000000c)

EXTSIG

Added in API level 21
long EXTSIG

常量值:134695760(0x0000000008074b50)

EXTSIZ

Added in API level 21
int EXTSIZ

常量值:8(0x00000008)

LOCCRC

Added in API level 21
int LOCCRC

Constant Value: 14 (0x0000000e)

LOCEXT

Added in API level 21
int LOCEXT

常量值:28(0x0000001c)

LOCFLG

Added in API level 21
int LOCFLG

常数值:6(0x00000006)

LOCHDR

Added in API level 21
int LOCHDR

常量值:30(0x0000001e)

LOCHOW

Added in API level 21
int LOCHOW

常量值:8(0x00000008)

LOCLEN

Added in API level 21
int LOCLEN

常量值:22(0x00000016)

LOCNAM

Added in API level 21
int LOCNAM

常量值:26(0x0000001a)

LOCSIG

Added in API level 21
long LOCSIG

常量值:67324752(0x0000000004034b50)

LOCSIZ

Added in API level 21
int LOCSIZ

常量值:18(0x00000012)

LOCTIM

Added in API level 21
int LOCTIM

常量值:10(0x0000000a)

LOCVER

Added in API level 21
int LOCVER

常量值:4(0x00000004)

STORED

Added in API level 1
int STORED

未压缩(STORED)条目的压缩方法。

常量值:0(0x00000000)

Public constructors

ZipOutputStream

Added in API level 1
ZipOutputStream (OutputStream out)

创建一个新的ZIP输出流。

UTF-8 charset用于对条目名称和注释进行编码。

Parameters
out OutputStream: the actual output stream

ZipOutputStream

Added in API level 24
ZipOutputStream (OutputStream out, 
                Charset charset)

创建一个新的ZIP输出流。

Parameters
out OutputStream: the actual output stream
charset Charset: the charset to be used to encode the entry names and comments

Public methods

close

Added in API level 1
void close ()

关闭ZIP输出流以及正在过滤的流。

Throws
ZipException if a ZIP file error has occurred
IOException if an I/O error has occurred

closeEntry

Added in API level 1
void closeEntry ()

关闭当前的ZIP条目并定位写入下一个条目的流。

Throws
ZipException if a ZIP format error has occurred
IOException if an I/O error has occurred

finish

Added in API level 1
void finish ()

完成编写ZIP输出流的内容而不关闭底层流。 连续应用多个过滤器到相同的输出流时使用此方法。

Throws
ZipException if a ZIP file error has occurred
IOException if an I/O exception has occurred

putNextEntry

Added in API level 1
void putNextEntry (ZipEntry e)

开始编写新的ZIP文件条目并将流定位到条目数据的开头。 如果仍然有效,则关闭当前条目。 如果没有为条目指定压缩方法,将使用默认压缩方法,如果条目没有设置修改时间,则使用当前时间。

Parameters
e ZipEntry: the ZIP entry to be written
Throws
ZipException if a ZIP format error has occurred
IOException if an I/O error has occurred

setComment

Added in API level 1
void setComment (String comment)

设置ZIP文件评论。

Parameters
comment String: the comment string
Throws
IllegalArgumentException if the length of the specified ZIP file comment is greater than 0xFFFF bytes

setLevel

Added in API level 1
void setLevel (int level)

为后续的DEFLATED条目设置压缩级别。 默认设置是DEFAULT_COMPRESSION。

Parameters
level int: the compression level (0-9)
Throws
IllegalArgumentException if the compression level is invalid

setMethod

Added in API level 1
void setMethod (int method)

为后续条目设置默认压缩方法。 只要没有为单个ZIP文件条目指定压缩方法并且最初设置为DEFLATED,就会使用此默认值。

Parameters
method int: the default compression method
Throws
IllegalArgumentException if the specified compression method is invalid

write

Added in API level 1
void write (byte[] b, 
                int off, 
                int len)

将一个字节数组写入当前ZIP条目数据。 该方法将阻塞,直到写入所有字节。

Parameters
b byte: the data to be written
off int: the start offset in the data
len int: the number of bytes that are written
Throws
ZipException if a ZIP file error has occurred
IOException if an I/O error has occurred

Hooray!