DeflaterInputStream - JRE Emulation | JRE Emulation
public class

DeflaterInputStream

extends FilterInputStream
java.lang.Object
   ↳ java.io.InputStream
     ↳ java.io.FilterInputStream
       ↳ java.util.zip.DeflaterInputStream

Class Overview

An InputStream filter to compress data. Callers read compressed data in the "deflate" format from the uncompressed underlying stream.

Summary

Fields
protected final byte[] buf
protected final Deflater def
[Expand]
Inherited Fields
From class java.io.FilterInputStream
Public Constructors
DeflaterInputStream(InputStream in)
Constructs a DeflaterInputStream with a new Deflater and an implementation-defined default internal buffer size.
DeflaterInputStream(InputStream in, Deflater deflater)
Constructs a DeflaterInputStream with the given Deflater and an implementation-defined default internal buffer size.
DeflaterInputStream(InputStream in, Deflater deflater, int bufferSize)
Constructs a DeflaterInputStream with the given Deflater and given internal buffer size.
Public Methods
int available()
Returns 0 when when this stream has exhausted its input; and 1 otherwise.
void close()
Closes the underlying input stream and discards any remaining uncompressed data.
void mark(int limit)
This operation is not supported and does nothing.
boolean markSupported()
Returns false because DeflaterInputStream does not support mark/reset.
int read()
Reads a byte from the compressed input stream.
int read(byte[] buffer, int byteOffset, int byteCount)
Reads up to byteCount bytes of compressed data into a byte buffer.
void reset()
This operation is not supported and throws IOException.
long skip(long byteCount)
Skips over and discards n bytes of data from the input stream.

Note: if n > Integer.MAX_VALUE, this stream will only attempt to skip Integer.MAX_VALUE bytes.

Inherited Methods
[Expand]
From class java.io.FilterInputStream
From class java.io.InputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Fields

protected final byte[] buf

protected final Deflater def

Public Constructors

public DeflaterInputStream (InputStream in)

Constructs a DeflaterInputStream with a new Deflater and an implementation-defined default internal buffer size. in is a source of uncompressed data, and this stream will be a source of compressed data.

Parameters
in the source InputStream

public DeflaterInputStream (InputStream in, Deflater deflater)

Constructs a DeflaterInputStream with the given Deflater and an implementation-defined default internal buffer size. in is a source of uncompressed data, and this stream will be a source of compressed data.

Parameters
in the source InputStream
deflater the Deflater to be used for compression

public DeflaterInputStream (InputStream in, Deflater deflater, int bufferSize)

Constructs a DeflaterInputStream with the given Deflater and given internal buffer size. in is a source of uncompressed data, and this stream will be a source of compressed data.

Parameters
in the source InputStream
deflater the Deflater to be used for compression
bufferSize the length in bytes of the internal buffer

Public Methods

public int available ()

Returns 0 when when this stream has exhausted its input; and 1 otherwise. A result of 1 does not guarantee that further bytes can be returned, with or without blocking.

Although consistent with the RI, this behavior is inconsistent with available(), and violates the Liskov Substitution Principle. This method should not be used.

Returns
  • 0 if no further bytes are available. Otherwise returns 1, which suggests (but does not guarantee) that additional bytes are available.
Throws
IOException if this stream is closed or an error occurs

public void close ()

Closes the underlying input stream and discards any remaining uncompressed data.

Throws
IOException

public void mark (int limit)

This operation is not supported and does nothing.

Parameters
limit the maximum limit of bytes that can be read before the mark position becomes invalid.

public boolean markSupported ()

Returns false because DeflaterInputStream does not support mark/reset.

Returns
  • true if this stream type supports the mark and reset method; false otherwise.

public int read ()

Reads a byte from the compressed input stream. The result will be a byte of compressed data corresponding to an uncompressed byte or bytes read from the underlying stream.

Returns
  • the byte or -1 if the end of the stream has been reached.
Throws
IOException

public int read (byte[] buffer, int byteOffset, int byteCount)

Reads up to byteCount bytes of compressed data into a byte buffer. The result will be bytes of compressed data corresponding to an uncompressed byte or bytes read from the underlying stream. Returns the number of bytes read or -1 if the end of the compressed input stream has been reached.

Parameters
buffer the buffer into which the data is read.
byteOffset the start offset in the destination array b
byteCount the maximum number of bytes read.
Returns
  • the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws
IOException

public void reset ()

This operation is not supported and throws IOException.

Throws
IOException

public long skip (long byteCount)

Skips over and discards n bytes of data from the input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. The actual number of bytes skipped is returned.

This method simply performs in.skip(n).

Note: if n > Integer.MAX_VALUE, this stream will only attempt to skip Integer.MAX_VALUE bytes.

Parameters
byteCount the number of bytes to be skipped.
Returns
  • the actual number of bytes skipped.
Throws
IOException