Category: 18. Java Zip

https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR3KTh3wGipdhva2iT4Urby8_N1SNDVlrunA2h9k_CFXfUDnU5Uybjs09bAcC4a39Hrg7w

  • GZIPInputStream 

    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 −

    publicclassGZIPInputStreamextendsInflaterInputStream

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    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
    1GZIPInputStream(InputStream in)Creates a new input stream with a default buffer size.
    2GZIPInputStream(InputStream in, int size)Creates a new input stream with the specified buffer size.

    Class Methods

    Sr.No.Method & Description
    1void close()Closes this input stream and releases any system resources associated with the stream.
    2int 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
  • DeflaterOutputStream 

    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 −

    publicclassDeflaterOutputStreamextendsFilterOutputStream

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    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
    1DeflaterOutputStream(OutputStream out)Creates a new output stream with a default compressor and buffer size.
    2DeflaterOutputStream(OutputStream out, boolean syncFlush)Creates a new output stream with a default compressor, a default buffer size and the specified flush mode.
    3DeflaterOutputStream(OutputStream out, Deflater def)Creates a new output stream with the specified compressor and a default buffer size.
    4DeflaterOutputStream(OutputStream out, Deflater def, boolean syncFlush)Creates a new output stream with the specified compressor, flush mode and a default buffer size.
    5DeflaterOutputStream(OutputStream out, Deflater def, int size)Creates a new output stream with the specified compressor and buffer size.
    6DeflaterOutputStream(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
    1void close()Writes remaining compressed data to the output stream and closes the underlying stream.
    2void finish()Finishes writing compressed data to the output stream without closing the underlying stream.
    3void flush()Flushes the compressed output stream.
    4void write(byte[] b, int off, int len)Writes an array of bytes to the compressed output stream.
    5void 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
  • DeflaterInputStream 

    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 −

    publicclassDeflaterInputStreamextendsFilterInputStream

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    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
    1DeflaterInputStream(InputStream in)Creates a new input stream with a default compressor and buffer size.
    2DeflaterInputStream(InputStream in, Deflater defl)Creates a new input stream with the specified compressor and a default buffer size.
    3DeflaterInputStream(InputStream in, Deflater defl, int bufLen)Creates a new input stream with the specified compressor and buffer size.

    Class Methods

    Sr.No.Method & Description
    1int available()Returns 0 after EOF has been reached, otherwise always return 1.
    2void close()Closes this input stream and its underlying input stream, discarding any pending uncompressed data.
    3int read()Reads a single byte of compressed data from the input stream.
    4int read(byte[] b, int off, int len)Reads compressed data into a byte array.
    5long 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
  • Deflater 

    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 −

    publicclassDeflaterextendsObject

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    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
    1Deflater()Creates a new compressor with the default compression level.
    2Deflater(int level)Creates a new compressor using the specified compression level.
    3Deflater(int level, boolean nowrap)Creates a new compressor using the specified compression level.

    Class Methods

    Sr.No.Method & Description
    1int deflate(byte[] b)Compresses the input data and fills specified buffer with compressed data.
    2int deflate(byte[] b, int off, int len)Compresses the input data and fills specified buffer with compressed data.
    3int deflate(byte[] b, int off, int len, int flush)Compresses the input data and fills the specified buffer with compressed data.
    4void end()Closes the compressor and discards any unprocessed input.
    5void finish()When called, indicates that compression should end with the current contents of the input buffer.
    6boolean finished()Returns true if the end of the compressed data output stream has been reached.
    7int getAdler()Returns the ADLER-32 value of the uncompressed data.
    8long getBytesRead()Returns the total number of uncompressed bytes input so far.
    9long getBytesWritten()Returns the total number of compressed bytes output so far.
    10int getTotalIn()Returns the total number of uncompressed bytes input so far.
    11int getTotalOut()Returns the total number of compressed bytes output so far.
    12boolean needsInput()Returns true if the input data buffer is empty and setInput() should be called in order to provide more input.
    13void reset()Resets deflater so that a new set of input data can be processed.
    14void setDictionary(byte[] b)Sets preset dictionary for compression.
    15void setDictionary(byte[] b, int off, int len)Sets preset dictionary for compression.
    16void setInput(byte[] b)Sets input data for compression.
    17void setInput(byte[] b, int off, int len)Sets input data for compression.
    18void setLevel(int level)Sets the current compression level to the specified value.
    19void setStrategy(int strategy)Sets the compression strategy to the specified value.

    Methods Inherited

    This class inherits methods from the following classes −

    • java.lang.Object
  • CRC32 

    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 −

    publicclassCRC32extendsObjectimplementsChecksum

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Constructors

    Sr.No.Constructor & Description
    1CRC32()Creates a new CRC32 object.

    Class Methods

    Sr.No.Method & Description
    1long getValue()Returns the CRC-32 value.
    2void reset()Resets the CRC-32 to initial value.
    3void update(byte[] b)Updates the CRC-32 checksum with the specified array of bytes.
    4void update(byte[] b, int off, int len)Updates the CRC-32 checksum with the specified array of bytes.
    5void 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
  • CheckedOutputStream 

    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 −

    publicclassCheckedOutputStreamextendsFilterOutputStream

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Constructors

    Sr.No.Constructor & Description
    1CheckedOutputStream(OutputStream out, Checksum cksum)Creates an output stream with the specified Checksum.

    Class Methods

    Sr.No.Method & Description
    1Checksum getChecksum()Returns the Checksum for this output stream.
    2void write(byte[] b, int off, int len)Writes an array of bytes.
    3void write(int b)Writes a byte.

    Methods Inherited

    This class inherits methods from the following classes −

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

    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 −

    publicclassCheckedInputStreamextendsFilterInputStream

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Constructors

    Sr.No.Constructor & Description
    1CheckedInputStream(InputStream in, Checksum cksum)Creates an input stream using the specified Checksum.

    Class Methods

    Sr.No.Method & Description
    1Checksum getChecksum()Returns the Checksum for this input stream.
    2int read()Reads a byte.
    3int read(byte[] buf, int off, int len)Reads into an array of bytes.
    4long 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
  • 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 −

    publicclassAdler32extendsObjectimplementsChecksum

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Constructors

    Sr.No.Constructor & Description
    1Adler32()Creates a new Adler32 object.

    Class Methods

    Sr.No.Method & Description
    1long getValue()Returns the checksum value.
    2void reset()Resets the checksum to initial value.
    3void update(byte[] b)Updates the checksum with the specified array of bytes.
    4void update(byte[] b, int off, int len)Updates the checksum with the specified array of bytes.
    5void 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