Java Zip - Quick Guide



java.util.zip - Adler32

Introduction

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

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 −

  • java.lang.Object

java.util.zip - CheckedInputStream Class

Introduction

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

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 −

  • java.io.FilterInputStream
  • java.lang.Object

java.util.zip - CheckedOutputStream Class

Introduction

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

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 −

  • java.io.FilterOutputStream
  • java.lang.Object

java.util.zip - CRC32 Class

Introduction

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

Class declaration

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 −

  • java.lang.Object

java.util.zip - Deflater Class

Introduction

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

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

public class Deflater
   extends Object

Fields

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

  • static int BEST_COMPRESSION − Compression level for best compression.

  • static int BEST_SPEED − Compression level for fastest compression.

  • static int DEFAULT_COMPRESSION − Default compression level.

  • static int DEFAULT_STRATEGY − Default compression strategy.

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

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

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

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

  • static int NO_COMPRESSION − Compression level for no compression.

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

  • 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 −

  • java.lang.Object

java.util.zip - DeflaterInputStream Class

Introduction

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

Class declaration

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

public class DeflaterInputStream
   extends FilterInputStream

Fields

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

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

  • 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 −

  • java.io.FilterInputStream
  • java.lang.Object

java.util.zip - DeflaterOutputStream Class

Introduction

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

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

public class DeflaterOutputStream
   extends FilterOutputStream

Fields

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

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

  • 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 −

  • java.io.FilterOutputStream
  • java.lang.Object

java.util.zip - GZIPInputStream Class

Introduction

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

Class declaration

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

public class GZIPInputStream
   extends InflaterInputStream

Fields

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

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

  • protected boolean eos − Indicates end of input stream.

  • 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 −

  • java.util.zip.InflaterInputStream
  • java.io.FilterInputStream
  • java.lang.Object

java.util.zip - GZIPOutputStream Class

Introduction

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

Class declaration

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

public class GZIPOutputStream
   extends DeflaterOutputStream

Fields

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

  • 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 −

  • java.util.zip.DeflaterOutputStream
  • java.io.FilterOutputStream
  • java.lang.Object

java.util.zip - Inflater Class

Introduction

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

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 −

  • java.lang.Object

java.util.zip - InflaterInputStream Class

Introduction

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

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

public class InflaterInputStream
   extends FilterInputStream

Fields

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

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

  • protected Inflater inf − Decompressor for this stream.

  • 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 −

  • java.io.FilterInputStream
  • java.lang.Object

java.util.zip - InflaterOutputStream Class

Introduction

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

Class declaration

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

public class InflaterOutputStream
   extends FilterOutputStream

Fields

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

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

  • 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 −

  • java.io.FilterOutputStream
  • java.lang.Object

java.util.zip - ZipEntry Class

Introduction

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

Class declaration

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

public class ZipEntry
   extends Object
      implements Cloneable

Fields

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

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

  • protected Inflater inf − Decompressor for this stream.

  • static int CENATT

  • static int CENATX

  • static int CENCOM

  • static int CENCRC

  • static int CENDSK

  • static int CENEXT

  • static int CENFLG

  • static int CENHDR

  • static int CENHOW

  • static int CENLEN

  • static int CENNAM

  • static int CENOFF

  • static long CENSIG

  • static int CENSIZ

  • static int CENTIM

  • static int CENVEM

  • static int CENVER

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

  • static int ENDCOM

  • static int ENDHDR

  • static int ENDOFF

  • static long ENDSIG

  • static int ENDSIZ

  • static int ENDSUB

  • static int ENDTOT

  • static int EXTCRC

  • static int EXTHDR

  • static int EXTLEN

  • static long EXTSIG

  • static int EXTSIZ

  • static int LOCCRC

  • static int LOCEXT

  • static int LOCFLG

  • static int LOCHDR

  • static int LOCHOW

  • static int LOCLEN

  • static int LOCNAM

  • static long LOCSIG

  • static int LOCSIZ

  • static int LOCTIM

  • static int LOCVER

  • 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 −

  • java.io.FilterOutputStream
  • java.lang.Object

java.util.zip - ZipFile Class

Introduction

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

Class declaration

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

public class ZipFile
   extends Object
      implements Closeable

Fields

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

  • static int CENATT

  • static int CENATX

  • static int CENCOM

  • static int CENCRC

  • static int CENDSK

  • static int CENEXT

  • static int CENFLG

  • static int CENHDR

  • static int CENHOW

  • static int CENLEN

  • static int CENNAM

  • static int CENOFF

  • static long CENSIG

  • static int CENSIZ

  • static int CENTIM

  • static int CENVEM

  • static int CENVER

  • static int ENDCOM

  • static int ENDHDR

  • static int ENDOFF

  • static long ENDSIG

  • static int ENDSIZ

  • static int ENDSUB

  • static int ENDTOT

  • static int EXTCRC

  • static int EXTHDR

  • static int EXTLEN

  • static long EXTSIG

  • static int EXTSIZ

  • static int LOCCRC

  • static int LOCEXT

  • static int LOCFLG

  • static int LOCHDR

  • static int LOCHOW

  • static int LOCLEN

  • static int LOCNAM

  • static long LOCSIG

  • static int LOCSIZ

  • static int LOCTIM

  • static int LOCVER

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

  • 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 −

  • Java.lang.Object

java.util.zip - ZipInputStream Class

Introduction

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

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

public class ZipInputStream
   extends InflaterInputStream

Fields

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

  • static int CENATT

  • static int CENATX

  • static int CENCOM

  • static int CENCRC

  • static int CENDSK

  • static int CENEXT

  • static int CENFLG

  • static int CENHDR

  • static int CENHOW

  • static int CENLEN

  • static int CENNAM

  • static int CENOFF

  • static long CENSIG

  • static int CENSIZ

  • static int CENTIM

  • static int CENVEM

  • static int CENVER

  • static int ENDCOM

  • static int ENDHDR

  • static int ENDOFF

  • static long ENDSIG

  • static int ENDSIZ

  • static int ENDSUB

  • static int ENDTOT

  • static int EXTCRC

  • static int EXTHDR

  • static int EXTLEN

  • static long EXTSIG

  • static int EXTSIZ

  • static int LOCCRC

  • static int LOCEXT

  • static int LOCFLG

  • static int LOCHDR

  • static int LOCHOW

  • static int LOCLEN

  • static int LOCNAM

  • static long LOCSIG

  • static int LOCSIZ

  • static int LOCTIM

  • 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 −

  • java.util.zip.InflaterInputStream
  • java.io.FilterInputStream
  • java.lang.Object

java.util.zip - ZipOutputStream Class

Introduction

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

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

public class ZipOutputStream
   extends DeflaterOutputStream

Fields

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

  • static int CENATT

  • static int CENATX

  • static int CENCOM

  • static int CENCRC

  • static int CENDSK

  • static int CENEXT

  • static int CENFLG

  • static int CENHDR

  • static int CENHOW

  • static int CENLEN

  • static int CENNAM

  • static int CENOFF

  • static long CENSIG

  • static int CENSIZ

  • static int CENTIM

  • static int CENVEM

  • static int CENVER

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

  • static int ENDCOM

  • static int ENDHDR

  • static int ENDOFF

  • static long ENDSIG

  • static int ENDSIZ

  • static int ENDSUB

  • static int ENDTOT

  • static int EXTCRC

  • static int EXTHDR

  • static int EXTLEN

  • static long EXTSIG

  • static int EXTSIZ

  • static int LOCCRC

  • static int LOCEXT

  • static int LOCFLG

  • static int LOCHDR

  • static int LOCHOW

  • static int LOCLEN

  • static int LOCNAM

  • static long LOCSIG

  • static int LOCSIZ

  • static int LOCTIM

  • static int LOCVER

  • 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 −

  • java.util.zip.DeflaterOutputStream
  • java.io.FilterOutputStream
  • java.lang.Object

Java Zip - Exceptions

Introduction

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

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.

Advertisements