Package java.util.zip

Class DeflaterInputStream

All Implemented Interfaces:
Closeable, AutoCloseable

public class DeflaterInputStream
extends FilterInputStream
An InputStream filter to compress data. Callers read compressed data in the "deflate" format from the uncompressed underlying stream.
Since:
1.6
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected byte[] buf  
    protected Deflater def  

    Fields inherited from class java.io.FilterInputStream

    in
  • Constructor Summary

    Constructors
    Constructor Description
    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.
  • Method Summary

    Modifier and Type Method Description
    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 byteCount bytes in this stream.

    Methods inherited from class java.io.InputStream

    read

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • def

      protected final Deflater def
    • buf

      protected final byte[] buf
  • Constructor Details

    • DeflaterInputStream

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

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

      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
  • Method Details

    • close

      public void close() throws IOException
      Closes the underlying input stream and discards any remaining uncompressed data.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class FilterInputStream
      Throws:
      IOException - if an error occurs while closing this stream.
    • read

      public int read() throws IOException
      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.
      Overrides:
      read in class FilterInputStream
      Returns:
      the byte or -1 if the end of the stream has been reached.
      Throws:
      IOException - if the stream is closed or another IOException occurs.
    • read

      public int read​(byte[] buffer, int byteOffset, int byteCount) throws IOException
      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.
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException - if the stream is closed or another IOException occurs.
    • skip

      public long skip​(long byteCount) throws IOException
      Skips byteCount bytes in this stream. Subsequent calls to read will not return these bytes unless reset is used. This implementation skips byteCount bytes in the filtered stream.

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

      Overrides:
      skip in class FilterInputStream
      Parameters:
      byteCount - the number of bytes to skip.
      Returns:
      the number of bytes actually skipped.
      Throws:
      IOException - if this stream is closed or another IOException occurs.
      See Also:
      FilterInputStream.mark(int), FilterInputStream.reset()
    • available

      public int available() throws IOException
      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 InputStream.available(), and violates the Liskov Substitution Principle. This method should not be used.

      Overrides:
      available in class FilterInputStream
      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
    • markSupported

      public boolean markSupported()
      Returns false because DeflaterInputStream does not support mark/reset.
      Overrides:
      markSupported in class FilterInputStream
      Returns:
      true if mark() and reset() are supported, false otherwise.
      See Also:
      FilterInputStream.mark(int), FilterInputStream.reset(), FilterInputStream.skip(long)
    • mark

      public void mark​(int limit)
      This operation is not supported and does nothing.
      Overrides:
      mark in class FilterInputStream
      Parameters:
      limit - the number of bytes that can be read from this stream before the mark is invalidated.
      See Also:
      FilterInputStream.markSupported(), FilterInputStream.reset()
    • reset

      public void reset() throws IOException
      This operation is not supported and throws IOException.
      Overrides:
      reset in class FilterInputStream
      Throws:
      IOException - if this stream is already closed, no mark has been set or the mark is no longer valid because more than readlimit bytes have been read since setting the mark.
      See Also:
      FilterInputStream.mark(int), FilterInputStream.markSupported()