Javazip 简明教程

Java Zip - Quick Guide

java.util.zip - Adler32

java.util.zip.Adler32 类是一个类,可用于计算数据流的 Adler-32 校验和。Adler-32 校验和几乎与 CRC-32 一样可靠,但计算速度要快得多。

The java.util.zip.Adler32 class is a class that can be used to compute the Adler-32 checksum of a data stream. An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed much faster.

Class Declaration

这是 java.util.zip.Adler32 类声明 −

Following is the declaration for java.util.zip.Adler32 class −

public class Adler32
   extends Object
      implements Checksum

Constructors

Sr.No.

Constructor & Description

1

Adler32() Creates a new Adler32 object.

Class Methods

Sr.No.

Method & Description

1

long getValue()Returns the checksum value.

2

void reset() Resets the checksum to initial value.

3

void update(byte[] b)Updates the checksum with the specified array of bytes.

4

void update(byte[] b, int off, int len)Updates the checksum with the specified array of bytes.

5

void update(int b)Updates the checksum with the specified byte (the low eight bits of the argument b).

Methods Inherited

此类从以下类中继承方法:

This class inherits methods from the following classes −

  1. java.lang.Object

java.util.zip - CheckedInputStream Class

Introduction

java.util.zip.CheckedInputStream 类是一个输入流,它还维护读取数据的校验和。然后,可以利用校验和来验证输入数据的完整性。

The java.util.zip.CheckedInputStream class is an input stream that also maintains a checksum of the data being read. The checksum can then be used to verify the integrity of the input data.

Class Declaration

下面是 java.util.zip.CheckedInputStream 类的声明−

Following is the declaration for java.util.zip.CheckedInputStream class −

public class CheckedInputStream
   extends FilterInputStream

Constructors

Sr.No.

Constructor & Description

1

CheckedInputStream(InputStream in, Checksum cksum) Creates an input stream using the specified Checksum.

Class Methods

Sr.No.

Method & Description

1

Checksum getChecksum()Returns the Checksum for this input stream.

2

int read()Reads a byte.

3

int read(byte[] buf, int off, int len)Reads into an array of bytes.

4

long skip(long n)Skips specified number of bytes of input.

Methods Inherited

此类从以下类中继承方法:

This class inherits methods from the following classes −

  1. java.io.FilterInputStream

  2. java.lang.Object

java.util.zip - CheckedOutputStream Class

Introduction

java.util.zip.CheckedOutputStream 类是一个输出流,还维护着正在写入的数据的校验和。然后可以使用校验和验证输出数据的完整性。

The java.util.zip.CheckedOutputStream class is an output stream that also maintains a checksum of the data being written. The checksum can then be used to verify the integrity of the output data.

Class Declaration

java.util.zip.CheckedOutputStream 类的声明如下所示:

Following is the declaration for java.util.zip.CheckedOutputStream class −

public class CheckedOutputStream
   extends FilterOutputStream

Constructors

Sr.No.

Constructor & Description

1

CheckedOutputStream(OutputStream out, Checksum cksum) Creates an output stream with the specified Checksum.

Class Methods

Sr.No.

Method & Description

1

Checksum getChecksum()Returns the Checksum for this output stream.

2

void write(byte[] b, int off, int len)Writes an array of bytes.

3

void write(int b)Writes a byte.

Methods Inherited

此类从以下类中继承方法:

This class inherits methods from the following classes −

  1. java.io.FilterOutputStream

  2. java.lang.Object

java.util.zip - CRC32 Class

Introduction

java.util.zip.CRC32 类是一个可用于计算数据流 CRC-32 的类。

The java.util.zip.CRC32 class is a class that can be used to compute the CRC-32 of a data stream.

Class Declaration

下面是 java.util.zip.CRC32 类的声明−

Following is the declaration for java.util.zip.CRC32 class −

public class CRC32
   extends Object
      implements Checksum

Constructors

Sr.No.

Constructor & Description

1

CRC32() Creates a new CRC32 object.

Class Methods

Sr.No.

Method & Description

1

long getValue()Returns the CRC-32 value.

2

void reset() Resets the CRC-32 to initial value.

3

void update(byte[] b)Updates the CRC-32 checksum with the specified array of bytes.

4

void update(byte[] b, int off, int len)Updates the CRC-32 checksum with the specified array of bytes.

5

void update(int b)Updates the CRC-32 checksum with the specified byte (the low eight bits of the argument b).

Methods Inherited

此类从以下类中继承方法:

This class inherits methods from the following classes −

  1. java.lang.Object

java.util.zip - Deflater Class

Introduction

java.util.zip.Deflater 类利用流行的 ZLIB 压缩库提供对通用压缩的支持。ZLIB 压缩库最初作为 PNG 图形标准的一部分开发,而且不受专利保护。在 java.util.zip 包说明中进行了详细介绍。

The java.util.zip.Deflater class provides support for general purpose compression using the popular ZLIB compression library. The ZLIB compression library was initially developed as part of the PNG graphics standard and is not protected by patents. It is fully described in the specifications at the java.util.zip package description.

Class Declaration

下面是 java.util.zip.Deflater 类的声明−

Following is the declaration for java.util.zip.Deflater class −

public class Deflater
   extends Object

Fields

下面是 java.util.zip.Deflater 类的字段−

Following are the fields for java.util.zip.Deflater class −

  1. static int BEST_COMPRESSION − Compression level for best compression.

  2. static int BEST_SPEED − Compression level for fastest compression.

  3. static int DEFAULT_COMPRESSION − Default compression level.

  4. static int DEFAULT_STRATEGY − Default compression strategy.

  5. static int DEFLATED − Compression method for the deflate algorithm (the only one currently supported).

  6. static int FILTERED − Compression strategy best used for data consisting mostly of small values with a somewhat random distribution.

  7. static int FULL_FLUSH − Compression flush mode used to flush out all pending output and reset the deflater.

  8. static int HUFFMAN_ONLY − Compression strategy for Huffman coding only.

  9. static int NO_COMPRESSION − Compression level for no compression.

  10. static int NO_FLUSH − Compression flush mode used to achieve best compression result.

  11. static int SYNC_FLUSH − Compression flush mode used to flush out all pending output; may degrade compression for some compression algorithms.

Constructors

Sr.No.

Constructor & Description

1

Deflater() Creates a new compressor with the default compression level.

2

Deflater(int level) Creates a new compressor using the specified compression level.

3

Deflater(int level, boolean nowrap) Creates a new compressor using the specified compression level.

Class Methods

Sr.No.

Method & Description

1

int deflate(byte[] b)Compresses the input data and fills specified buffer with compressed data.

2

int deflate(byte[] b, int off, int len)Compresses the input data and fills specified buffer with compressed data.

3

int deflate(byte[] b, int off, int len, int flush)Compresses the input data and fills the specified buffer with compressed data.

4

void end()Closes the compressor and discards any unprocessed input.

5

void finish()When called, indicates that compression should end with the current contents of the input buffer.

6

boolean finished()Returns true if the end of the compressed data output stream has been reached.

7

int getAdler()Returns the ADLER-32 value of the uncompressed data.

8

long getBytesRead()Returns the total number of uncompressed bytes input so far.

9

long getBytesWritten()Returns the total number of compressed bytes output so far.

10

int getTotalIn()Returns the total number of uncompressed bytes input so far.

11

int getTotalOut()Returns the total number of compressed bytes output so far.

12

boolean needsInput()Returns true if the input data buffer is empty and setInput() should be called in order to provide more input.

13

void reset()Resets deflater so that a new set of input data can be processed.

14

void setDictionary(byte[] b)Sets preset dictionary for compression.

15

void setDictionary(byte[] b, int off, int len)Sets preset dictionary for compression.

16

void setInput(byte[] b)Sets input data for compression.

17

void setInput(byte[] b, int off, int len)Sets input data for compression.

18

void setLevel(int level)Sets the current compression level to the specified value.

19

void setStrategy(int strategy)Sets the compression strategy to the specified value.

Methods Inherited

此类从以下类中继承方法:

This class inherits methods from the following classes −

  1. java.lang.Object

java.util.zip - DeflaterInputStream Class

Introduction

java.util.zip.DeflaterInputStream 类实现用于以“压缩”压缩格式压缩数据的输入流过滤器。

The java.util.zip.DeflaterInputStream class implements an input stream filter for compressing data in the "deflate" compression format.

Class Declaration

以下为 java.util.zip.DeflaterInputStream 类的声明 −

Following is the declaration for java.util.zip.DeflaterInputStream class −

public class DeflaterInputStream
   extends FilterInputStream

Fields

以下为 java.util.zip.DeflaterInputStream 类的字段 −

Following are the fields for java.util.zip.DeflaterInputStream class −

  1. protected byte[] buf − Input buffer for reading compressed data.

  2. protected Deflater def − Compressor for this stream.

Constructors

Sr.No.

Constructor & Description

1

DeflaterInputStream(InputStream in) Creates a new input stream with a default compressor and buffer size.

2

DeflaterInputStream(InputStream in, Deflater defl) Creates a new input stream with the specified compressor and a default buffer size.

3

DeflaterInputStream(InputStream in, Deflater defl, int bufLen) Creates a new input stream with the specified compressor and buffer size.

Class Methods

Sr.No.

Method & Description

1

int available()Returns 0 after EOF has been reached, otherwise always return 1.

2

void close()Closes this input stream and its underlying input stream, discarding any pending uncompressed data.

3

int read()Reads a single byte of compressed data from the input stream.

4

int read(byte[] b, int off, int len)Reads compressed data into a byte array.

5

long skip(long n)Skips over and discards data from the input stream.

Methods Inherited

此类从以下类中继承方法:

This class inherits methods from the following classes −

  1. java.io.FilterInputStream

  2. java.lang.Object

java.util.zip - DeflaterOutputStream Class

Introduction

java.util.zip.DeflaterOutputStream 类实现了用于以“压缩”压缩格式压缩数据的输出流过滤器。它也被用作其他类型压缩过滤器的基础,例如 GZIPOutputStream。

The java.util.zip.DeflaterOutputStream class implements an output stream filter for compressing data in the "deflate" compression format. It is also used as the basis for other types of compression filters, such as GZIPOutputStream.

Class Declaration

以下是 java.util.zip.DeflaterOutputStream 类声明 −

Following is the declaration for java.util.zip.DeflaterOutputStream class −

public class DeflaterOutputStream
   extends FilterOutputStream

Fields

以下是 java.util.zip.DeflaterOutputStream 类的字段 −

Following are the fields for java.util.zip.DeflaterOutputStream class −

  1. protected byte[] buf − Output buffer for writing compressed data.

  2. protected Deflater def − Compressor for this stream.

Constructors

Sr.No.

Constructor & Description

1

DeflaterOutputStream(OutputStream out) Creates a new output stream with a default compressor and buffer size.

2

DeflaterOutputStream(OutputStream out, boolean syncFlush) Creates a new output stream with a default compressor, a default buffer size and the specified flush mode.

3

DeflaterOutputStream(OutputStream out, Deflater def) Creates a new output stream with the specified compressor and a default buffer size.

4

DeflaterOutputStream(OutputStream out, Deflater def, boolean syncFlush) Creates a new output stream with the specified compressor, flush mode and a default buffer size.

5

DeflaterOutputStream(OutputStream out, Deflater def, int size) Creates a new output stream with the specified compressor and buffer size.

6

DeflaterOutputStream(OutputStream out, Deflater def, int size, boolean syncFlush) Creates a new output stream with the specified compressor, buffer size and flush mode.

Class Methods

Sr.No.

Method & Description

1

void close()Writes remaining compressed data to the output stream and closes the underlying stream.

2

void finish()Finishes writing compressed data to the output stream without closing the underlying stream.

3

void flush()Flushes the compressed output stream.

4

void write(byte[] b, int off, int len)Writes an array of bytes to the compressed output stream.

5

void write(int b)Writes a byte to the compressed output stream.

Methods Inherited

此类从以下类中继承方法:

This class inherits methods from the following classes −

  1. java.io.FilterOutputStream

  2. java.lang.Object

java.util.zip - GZIPInputStream Class

Introduction

java.util.zip.GZIPInputStream 类实现一个流过滤器,用于读取 GZIP 文件格式中的压缩数据。

The java.util.zip.GZIPInputStream class implements a stream filter for reading compressed data in the GZIP file format.

Class Declaration

这是 java.util.zip.GZIPInputStream 类声明 −

Following is the declaration for java.util.zip.GZIPInputStream class −

public class GZIPInputStream
   extends InflaterInputStream

Fields

以下是 java.util.zip.GZIPInputStream 类中的字段 −

Following are the fields for java.util.zip.GZIPInputStream class −

  1. protected CRC32 crc − CRC-32 for uncompressed data.

  2. protected boolean eos − Indicates end of input stream.

  3. static int GZIP_MAGIC − GZIP header magic number.

Constructors

Sr.No.

Constructor & Description

1

GZIPInputStream(InputStream in) Creates a new input stream with a default buffer size.

2

GZIPInputStream(InputStream in, int size) Creates a new input stream with the specified buffer size.

Class Methods

Sr.No.

Method & Description

1

void close()Closes this input stream and releases any system resources associated with the stream.

2

int read(byte[] buf, int off, int len)Reads uncompressed data into an array of bytes.

Methods Inherited

此类从以下类中继承方法:

This class inherits methods from the following classes −

  1. java.util.zip.InflaterInputStream

  2. java.io.FilterInputStream

  3. java.lang.Object

java.util.zip - GZIPOutputStream Class

Introduction

java.util.zip.GZIPOutputStream 类实现一个流过滤器,用于以 GZIP 文件格式写入压缩数据。

The java.util.zip.GZIPOutputStream class implements a stream filter for writing compressed data in the GZIP file format.

Class Declaration

以下是 java.util.zip.GZIPOutputStream 类的声明 −

Following is the declaration for java.util.zip.GZIPOutputStream class −

public class GZIPOutputStream
   extends DeflaterOutputStream

Fields

以下为 java.util.zip.GZIPOutputStream 类的字段 −

Following are the fields for java.util.zip.GZIPOutputStream class −

  1. protected CRC32 crc − CRC-32 for uncompressed data.

Constructors

Sr.No.

Constructor & Description

1

GZIPOutputStream(OutputStream out) Creates a new output stream with a default buffer size.

2

GZIPOutputStream(OutputStream out, boolean syncFlush) Creates a new output stream with a default buffer size and the specified flush mode.

3

GZIPOutputStream(OutputStream out, int size) Creates a new output stream with the specified buffer size.

4

GZIPOutputStream(OutputStream out, int size, boolean syncFlush) Creates a new output stream with the specified buffer size and flush mode.

Class Methods

Sr.No.

Method & Description

1

void finish()Finishes writing compressed data to the output stream without closing the underlying stream.

2

int write(byte[] buf, int off, int len)Writes array of bytes to the compressed output stream.

Methods Inherited

此类从以下类中继承方法:

This class inherits methods from the following classes −

  1. java.util.zip.DeflaterOutputStream

  2. java.io.FilterOutputStream

  3. java.lang.Object

java.util.zip - Inflater Class

Introduction

java.util.zip.Inflater 类使用流行的 ZLIB 压缩库提供通用解压缩支持。ZLIB 压缩库最初是作为 PNG 图形标准的一部分开发的,不受专利保护。该标准在 java.util.zip 包说明中得到了全面阐述。

The java.util.zip.Inflater class provides support for general purpose decompression using the popular ZLIB compression library. The ZLIB compression library was initially developed as part of the PNG graphics standard and is not protected by patents. It is fully described in the specifications at the java.util.zip package description.

Class Declaration

下面是 java.util.zip.Inflater 类的声明 −

Following is the declaration for java.util.zip.Inflater class −

public class Inflater
   extends Object

Constructors

Sr.No.

Constructor & Description

1

Inflater() Creates a new decompressor.

2

Inflater(boolean nowrap) Creates a new decompressor.

Class Methods

Sr.No.

Method & Description

1

void end()Closes the decompressor and discards any unprocessed input.

2

boolean finished()Returns true if the end of the compressed data stream has been reached.

3

int getAdler()Returns the ADLER-32 value of the uncompressed data.

4

long getBytesRead()Returns the total number of compressed bytes input so far.

5

long getBytesWritten()Returns the total number of uncompressed bytes output so far.

6

int getRemaining()Returns the total number of bytes remaining in the input buffer.

7

int getTotalIn()Returns the total number of compressed bytes input so far.

8

int getTotalOut()Returns the total number of uncompressed bytes output so far.

9

int inflate(byte[] b)Uncompresses bytes into specified buffer.

10

int inflate(byte[] b, int off, int len)Uncompresses bytes into specified buffer.

11

boolean needsDictionary()Returns true if a preset dictionary is needed for decompression.

12

boolean needsInput()Returns true if no data remains in the input buffer.

13

void reset()Resets inflater so that a new set of input data can be processed.

14

void setDictionary(byte[] b)Sets the preset dictionary to the given array of bytes.

15

void setDictionary(byte[] b, int off, int len)Sets the preset dictionary to the given array of bytes.

16

void setInput(byte[] b)Sets input data for decompression.

17

void setInput(byte[] b, int off, int len)Sets input data for decompression.

Methods Inherited

此类从以下类中继承方法:

This class inherits methods from the following classes −

  1. java.lang.Object

java.util.zip - InflaterInputStream Class

Introduction

java.util.zip.InflaterInputStream 类实现“deflate”压缩格式中用于解压缩数据的流过滤器。它还用作其他解压缩过滤器的基础,例如 GZIPInputStream。

The java.util.zip.InflaterInputStream class implements a stream filter for uncompressing data in the "deflate" compression format. It is also used as the basis for other decompression filters, such as GZIPInputStream.

Class Declaration

以下是 java.util.zip.InflaterInputStream 类的声明 −

Following is the declaration for java.util.zip.InflaterInputStream class −

public class InflaterInputStream
   extends FilterInputStream

Fields

以下为 java.util.zip.InflaterInputStream 类的字段 −

Following are the fields for java.util.zip.InflaterInputStream class −

  1. protected byte[] buf − Input buffer for decompression.

  2. protected Inflater inf − Decompressor for this stream.

  3. protected int len − Length of input buffer.

Constructors

Sr.No.

Constructor & Description

1

InflaterInputStream(InputStream in) Creates a new input stream with a default decompressor and buffer size.

2

InflaterInputStream(InputStream in, Inflater inf) Creates a new input stream with the specified decompressor and a default buffer size.

3

InflaterInputStream(InputStream in, Inflater inf, int size) Creates a new input stream with the specified decompressor and buffer size.

Class Methods

Sr.No.

Method & Description

1

int available()Returns 0 after EOF has been reached, otherwise always return 1.

2

void close()Closes this input stream and releases any system resources associated with the stream.

3

void mark(int readlimit)Marks the current position in this input stream.

4

boolean markSupported()Tests if this input stream supports the mark and reset methods.

5

int read()Reads a byte of uncompressed data.

6

int read(byte[] b, int off, int len)Reads uncompressed data into an array of bytes.

7

void reset()Repositions this stream to the position at the time the mark method was last called on this input stream.

8

long skip(long n)Skips specified number of bytes of uncompressed data.

Methods Inherited

此类从以下类中继承方法:

This class inherits methods from the following classes −

  1. java.io.FilterInputStream

  2. java.lang.Object

java.util.zip - InflaterOutputStream Class

Introduction

java.util.zip.InflaterOutputStream 类实现一个输出流过滤器,用于解压缩以“deflate”压缩格式存储的数据。

The java.util.zip.InflaterOutputStream class implements an output stream filter for uncompressing data stored in the "deflate" compression format.

Class Declaration

以下是 java.util.zip.InflaterOutputStream 类的声明 −

Following is the declaration for java.util.zip.InflaterOutputStream class −

public class InflaterOutputStream
   extends FilterOutputStream

Fields

以下是 java.util.zip.InflaterOutputStream 类的字段 −

Following are the fields for java.util.zip.InflaterOutputStream class −

  1. protected byte[] buf − Output buffer for writing uncompressed data.

  2. protected Inflater inf − Decompressor for this stream.

Constructors

Sr.No.

Constructor & Description

1

InflaterOutputStream(OutputStream out) Creates a new output stream with a default decompressor and buffer size.

2

InflaterOutputStream(OutputStream out, Inflater infl) Creates a new output stream with the specified decompressor and a default buffer size.

3

InflaterOutputStream(OutputStream out, Inflater infl, int bufLen) Creates a new output stream with the specified decompressor and buffer size.

Class Methods

Sr.No.

Method & Description

1

void close()Writes remaining compressed data to the output stream and closes the underlying stream.

2

void finish()Finishes writing uncompressed data to the output stream without closing the underlying stream.

3

void flush()Flushes this output stream, forcing any pending buffered output bytes to be written.

4

void write(byte[] b, int off, int len)Writes an array of bytes to the compressed output stream.

5

void write(int b)Writes a byte to the compressed output stream.

Methods Inherited

此类从以下类中继承方法:

This class inherits methods from the following classes −

  1. java.io.FilterOutputStream

  2. java.lang.Object

java.util.zip - ZipEntry Class

Introduction

java.util.zip.ZipEntry 类用于表示 ZIP 文件条目。

The java.util.zip.ZipEntry class is used to represent a ZIP file entry.

Class Declaration

以下是 java.util.zip.ZipEntry 类的声明 −

Following is the declaration for java.util.zip.ZipEntry class −

public class ZipEntry
   extends Object
      implements Cloneable

Fields

以下是 java.util.zip.ZipEntry 类的字段 −

Following are the fields for java.util.zip.ZipEntry class −

  1. protected byte[] buf − Output buffer for writing uncompressed data.

  2. protected Inflater inf − Decompressor for this stream.

  3. static int CENATT

  4. static int CENATX

  5. static int CENCOM

  6. static int CENCRC

  7. static int CENDSK

  8. static int CENEXT

  9. static int CENFLG

  10. static int CENHDR

  11. static int CENHOW

  12. static int CENLEN

  13. static int CENNAM

  14. static int CENOFF

  15. static long CENSIG

  16. static int CENSIZ

  17. static int CENTIM

  18. static int CENVEM

  19. static int CENVER

  20. static int DEFLATED − Compression method for compressed (deflated) entries.

  21. static int ENDCOM

  22. static int ENDHDR

  23. static int ENDOFF

  24. static long ENDSIG

  25. static int ENDSIZ

  26. static int ENDSUB

  27. static int ENDTOT

  28. static int EXTCRC

  29. static int EXTHDR

  30. static int EXTLEN

  31. static long EXTSIG

  32. static int EXTSIZ

  33. static int LOCCRC

  34. static int LOCEXT

  35. static int LOCFLG

  36. static int LOCHDR

  37. static int LOCHOW

  38. static int LOCLEN

  39. static int LOCNAM

  40. static long LOCSIG

  41. static int LOCSIZ

  42. static int LOCTIM

  43. static int LOCVER

  44. static int STORED − Compression method for uncompressed entries.

Constructors

Sr.No.

Constructor & Description

1

ZipEntry(String name) Creates a new zip entry with the specified name.

2

ZipEntry(ZipEntry e) Creates a new zip entry with fields taken from the specified zip entry.

Class Methods

Sr.No.

Method & Description

1

Object clone()Returns a copy of this entry.

2

String getComment()Returns the comment string for the entry, or null if none.

3

long getCompressedSize()Returns the size of the compressed entry data, or -1 if not known.

4

long getCrc()Returns the CRC-32 checksum of the uncompressed entry data, or -1 if not known.

5

byte[] getExtra()Returns the extra field data for the entry, or null if none.

6

int getMethod()Returns the compression method of the entry, or -1 if not specified.

7

String getName()Returns the name of the entry.

8

long getSize()Returns the uncompressed size of the entry data, or -1 if not known.

9

long getTime()Returns the modification time of the entry, or -1 if not specified.

10

int hashCode()Returns the hash code value for this entry.

11

boolean isDirectory()Returns true if this is a directory entry.

12

void setComment(String comment)Sets the optional comment string for the entry.

13

void setCrc(long crc)Sets the CRC-32 checksum of the uncompressed entry data.

14

void setExtra(byte[] extra)Sets the optional extra field data for the entry.

15

void setMethod(int method)Sets the compression method for the entry.

16

void setSize(long size)Sets the uncompressed size of the entry data.

17

void setTime(long time)Sets the modification time of the entry.

18

String toString()Returns a string representation of the ZIP entry.

Methods Inherited

此类从以下类中继承方法:

This class inherits methods from the following classes −

  1. java.io.FilterOutputStream

  2. java.lang.Object

java.util.zip - ZipFile Class

Introduction

java.util.zip.ZipFile 类用于从 zip 文件中读取条目。

The java.util.zip.ZipFile class is used to read entries from a zip file.

Class Declaration

以下是 java.util.zip.ZipFile 类的声明 −

Following is the declaration for java.util.zip.ZipFile class −

public class ZipFile
   extends Object
      implements Closeable

Fields

以下是 java.util.zip.ZipFile 类的字段 −

Following are the fields for java.util.zip.ZipFile class −

  1. static int CENATT

  2. static int CENATX

  3. static int CENCOM

  4. static int CENCRC

  5. static int CENDSK

  6. static int CENEXT

  7. static int CENFLG

  8. static int CENHDR

  9. static int CENHOW

  10. static int CENLEN

  11. static int CENNAM

  12. static int CENOFF

  13. static long CENSIG

  14. static int CENSIZ

  15. static int CENTIM

  16. static int CENVEM

  17. static int CENVER

  18. static int ENDCOM

  19. static int ENDHDR

  20. static int ENDOFF

  21. static long ENDSIG

  22. static int ENDSIZ

  23. static int ENDSUB

  24. static int ENDTOT

  25. static int EXTCRC

  26. static int EXTHDR

  27. static int EXTLEN

  28. static long EXTSIG

  29. static int EXTSIZ

  30. static int LOCCRC

  31. static int LOCEXT

  32. static int LOCFLG

  33. static int LOCHDR

  34. static int LOCHOW

  35. static int LOCLEN

  36. static int LOCNAM

  37. static long LOCSIG

  38. static int LOCSIZ

  39. static int LOCTIM

  40. static int LOCVER

  41. static int OPEN_DELETE − Mode flag to open a zip file and mark it for deletion.

  42. static int OPEN_READ − Mode flag to open a zip file for reading.

Constructors

Sr.No.

Constructor & Description

1

ZipFile(File file) Opens a ZIP file for reading given the specified File object.

2

ZipFile(File file, Charset charset) Opens a ZIP file for reading given the specified File object.

3

ZipFile(File file, int mode) Opens a new ZipFile to read from the specified File object in the specified mode.

4

ZipFile(File file, int mode, Charset charset) Opens a new ZipFile to read from the specified File object in the specified mode.

5

ZipFile(String name) Opens a zip file for reading.

6

ZipFile(String name, Charset charset) Opens a zip file for reading.

Class Methods

Sr.No.

Method & Description

1

void close()Closes the ZIP file.

2

Enumeration<? extends ZipEntry> entries()Returns an enumeration of the ZIP file entries.

3

String getComment()Returns the zip file comment, or null if none.

4

ZipEntry getEntry(String name)Returns the zip file entry for the specified name, or null if not found.

5

InputStream getInputStream(ZipEntry entry)Returns an input stream for reading the contents of the specified zip file entry.

6

String getName()Returns the path name of the ZIP file.

7

int size()Returns the number of entries in the ZIP file.

Methods Inherited

此类从以下类中继承方法:

This class inherits methods from the following classes −

  1. Java.lang.Object

java.util.zip - ZipInputStream Class

Introduction

java.util.zip.ZipInputStream 类实现了用于读取 ZIP 文件格式中的文件的输入流过滤器。包括对压缩和非压缩文件的支持。

The java.util.zip.ZipInputStream class implements an input stream filter for reading files in the ZIP file format. Includes support for both compressed and uncompressed entries.

Class Declaration

java.util.zip.ZipInputStream 类的声明如下所示:

Following is the declaration for java.util.zip.ZipInputStream class −

public class ZipInputStream
   extends InflaterInputStream

Fields

java.util.zip.ZipInputStream 类的字段如下所示:

Following are the fields for java.util.zip.ZipInputStream class −

  1. static int CENATT

  2. static int CENATX

  3. static int CENCOM

  4. static int CENCRC

  5. static int CENDSK

  6. static int CENEXT

  7. static int CENFLG

  8. static int CENHDR

  9. static int CENHOW

  10. static int CENLEN

  11. static int CENNAM

  12. static int CENOFF

  13. static long CENSIG

  14. static int CENSIZ

  15. static int CENTIM

  16. static int CENVEM

  17. static int CENVER

  18. static int ENDCOM

  19. static int ENDHDR

  20. static int ENDOFF

  21. static long ENDSIG

  22. static int ENDSIZ

  23. static int ENDSUB

  24. static int ENDTOT

  25. static int EXTCRC

  26. static int EXTHDR

  27. static int EXTLEN

  28. static long EXTSIG

  29. static int EXTSIZ

  30. static int LOCCRC

  31. static int LOCEXT

  32. static int LOCFLG

  33. static int LOCHDR

  34. static int LOCHOW

  35. static int LOCLEN

  36. static int LOCNAM

  37. static long LOCSIG

  38. static int LOCSIZ

  39. static int LOCTIM

  40. static int LOCVER

Constructors

Sr.No.

Constructor & Description

1

ZipInputStream(InputStream in) Creates a new ZIP input stream.

2

ZipInputStream(InputStream in, Charset charset) Creates a new ZIP input stream.

Class Methods

Sr.No.

Method & Description

1

int available()Returns 0 after EOF has reached for the current entry data, otherwise always return 1.

2

void close()Closes this input stream and releases any system resources associated with the stream.

3

void closeEntry()Closes the current ZIP entry and positions the stream for reading the next entry.

4

ZipEntry getNextEntry()Reads the next ZIP file entry and positions the stream at the beginning of the entry data.

5

int read(byte[] b, int off, int len)Reads from the current ZIP entry into an array of bytes.

6

long skip(long n)Skips specified number of bytes in the current ZIP entry.

Methods Inherited

此类从以下类中继承方法:

This class inherits methods from the following classes −

  1. java.util.zip.InflaterInputStream

  2. java.io.FilterInputStream

  3. java.lang.Object

java.util.zip - ZipOutputStream Class

Introduction

java.util.zip.ZipOutputStream 类实现了用于以 ZIP 文件格式写入文件的输出流过滤器。包括对压缩和非压缩项的支持。

The java.util.zip.ZipOutputStream class implements an output stream filter for writing files in the ZIP file format. Includes support for both compressed and uncompressed entries.

Class Declaration

以下是 java.util.zip.ZipOutputStream 类的声明 −

Following is the declaration for java.util.zip.ZipOutputStream class −

public class ZipOutputStream
   extends DeflaterOutputStream

Fields

以下是 java.util.zip.ZipOutputStream 类的字段 −

Following are the fields for java.util.zip.ZipOutputStream class −

  1. static int CENATT

  2. static int CENATX

  3. static int CENCOM

  4. static int CENCRC

  5. static int CENDSK

  6. static int CENEXT

  7. static int CENFLG

  8. static int CENHDR

  9. static int CENHOW

  10. static int CENLEN

  11. static int CENNAM

  12. static int CENOFF

  13. static long CENSIG

  14. static int CENSIZ

  15. static int CENTIM

  16. static int CENVEM

  17. static int CENVER

  18. static int DEFLATED − Compression method for compressed (DEFLATED) entries.

  19. static int ENDCOM

  20. static int ENDHDR

  21. static int ENDOFF

  22. static long ENDSIG

  23. static int ENDSIZ

  24. static int ENDSUB

  25. static int ENDTOT

  26. static int EXTCRC

  27. static int EXTHDR

  28. static int EXTLEN

  29. static long EXTSIG

  30. static int EXTSIZ

  31. static int LOCCRC

  32. static int LOCEXT

  33. static int LOCFLG

  34. static int LOCHDR

  35. static int LOCHOW

  36. static int LOCLEN

  37. static int LOCNAM

  38. static long LOCSIG

  39. static int LOCSIZ

  40. static int LOCTIM

  41. static int LOCVER

  42. static int STORED − Compression method for uncompressed (STORED) entries.

Constructors

Sr.No.

Constructor & Description

1

ZipOutputStream(OutputStream out) Creates a new ZIP output stream.

2

ZipOutputStream(OutputStream out, Charset charset) Creates a new ZIP output stream.

Class Methods

Sr.No.

Method & Description

1

void close()Closes the ZIP output stream as well as the stream being filtered.

2

void closeEntry() Closes the current ZIP entry and positions the stream for writing the next entry.

3

void finish()Finishes writing the contents of the ZIP output stream without closing the underlying stream.

4

void putNextEntry(ZipEntry e)Begins writing a new ZIP file entry and positions the stream to the start of the entry data.

5

void setComment(String comment)Sets the ZIP file comment.

6

void setLevel(int level)Sets the compression level for subsequent entries which are DEFLATED.

7

void setMethod(int method)Sets the default compression method for subsequent entries.

8

void write(byte[] b, int off, int len)Writes an array of bytes to the current ZIP entry data.

Methods Inherited

此类从以下类中继承方法:

This class inherits methods from the following classes −

  1. java.util.zip.DeflaterOutputStream

  2. java.io.FilterOutputStream

  3. java.lang.Object

Java Zip - Exceptions

Introduction

java.util.zip Exceptions 包含在 zip/unzip 操作期间可能发生的异常。

The java.util.zip Exceptions contains the exceptions which can occur during zip/unzip operations.

Interface Summary

Sr.No.

Exception & Description

1

DataFormatException Signals that a data format error has occurred.

2

ZipException Signals that a Zip exception of some sort has occurred.

Java Zip - Errors

Introduction

java.util.zip Error 包含 ZIP/解压操作期间可能出现的错误。

The java.util.zip Error contains the error which can occur during zip/unzip operations.

Interface Summary

Sr.No.

Error & Description

1

ZipError Signals that an unrecoverable error has occurred.