Class ReusableGzipOutputStream

All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class ReusableGzipOutputStream extends DeflaterOutputStream
This class implements a stream filter for writing compressed data in the GZIP file format. It's an adoption of GZIPOutputStream but with a notable difference regarding re-usability:
  • Expose reset() to reset CRC32 and the deflater
  • Don't write the GZIP header upon construction but expose writeHeader()
  • Constructor Details

  • Method Details

    • toByteArray

      public byte[] toByteArray()
    • write

      public void write(byte[] buf, int off, int len) throws IOException
      Writes array of bytes to the compressed output stream. This method will block until all the bytes are written.
      Overrides:
      write in class DeflaterOutputStream
      Parameters:
      buf - the data to be written
      off - the start offset of the data
      len - the length of the data
      Throws:
      IOException - If an I/O error has occurred.
    • finish

      public void finish() throws IOException
      Finishes writing compressed data to the output stream without closing the underlying stream. Use this method when applying multiple filters in succession to the same output stream.
      Overrides:
      finish in class DeflaterOutputStream
      Throws:
      IOException - if an I/O error has occurred
    • writeHeader

      public void writeHeader() throws IOException
      Throws:
      IOException
    • reset

      public void reset()