Class BrotliOutputStream

java.lang.Object
java.io.OutputStream
com.aayushatharva.brotli4j.encoder.BrotliOutputStream
com.itextpdf.brotlicompressor.BrotliOutputStream
All Implemented Interfaces:
IFinishable, Closeable, Flushable, AutoCloseable

public class BrotliOutputStream extends com.aayushatharva.brotli4j.encoder.BrotliOutputStream implements IFinishable
An output stream that compresses data using the Brotli compression algorithm. This is a wrapper around BrotliOutputStream that implements the IFinishable interface, allowing it to be used in contexts where finalization without closing the underlying stream is required.

Brotli is a generic-purpose lossless compression algorithm that compresses data using a combination of a modern variant of the LZ77 algorithm, Huffman coding, and 2nd order context modeling. It provides compression ratios comparable to the best currently available general-purpose compression methods, while offering significantly faster decompression speeds.

This class provides three constructors with varying levels of control over the compression parameters and buffer size. If no parameters are specified, default Brotli compression settings will be used.

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new Brotli output stream with default compression parameters and buffer size.
    BrotliOutputStream(OutputStream destination, com.aayushatharva.brotli4j.encoder.Encoder.Parameters params)
    Creates a new Brotli output stream with specified compression parameters and default buffer size.
    BrotliOutputStream(OutputStream destination, com.aayushatharva.brotli4j.encoder.Encoder.Parameters params, int bufferSize)
    Creates a new Brotli output stream with specified compression parameters and buffer size.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    finish()
    Finishes writing compressed data to the output stream without closing the underlying stream.

    Methods inherited from class com.aayushatharva.brotli4j.encoder.BrotliOutputStream

    attachDictionary, close, flush, write, write, write

    Methods inherited from class java.io.OutputStream

    nullOutputStream

    Methods inherited from class java.lang.Object

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

    • BrotliOutputStream

      public BrotliOutputStream (OutputStream destination, com.aayushatharva.brotli4j.encoder.Encoder.Parameters params, int bufferSize) throws IOException
      Creates a new Brotli output stream with specified compression parameters and buffer size.

      This constructor provides full control over the compression behavior by allowing specification of both the compression parameters and the internal buffer size.

      Parameters:
      destination - the output stream to write compressed data to
      params - the Brotli compression parameters to use
      bufferSize - the buffer size in bytes for the internal compression buffer
      Throws:
      IOException - if an I/O error occurs during initialization
    • BrotliOutputStream

      public BrotliOutputStream (OutputStream destination, com.aayushatharva.brotli4j.encoder.Encoder.Parameters params) throws IOException
      Creates a new Brotli output stream with specified compression parameters and default buffer size.

      This constructor allows customization of the compression parameters while using the default buffer size provided by the underlying BrotliOutputStream.

      Parameters:
      destination - the output stream to write compressed data to
      params - the Brotli compression parameters to use
      Throws:
      IOException - if an I/O error occurs during initialization
    • BrotliOutputStream

      public BrotliOutputStream (OutputStream destination) throws IOException
      Creates a new Brotli output stream with default compression parameters and buffer size.

      This constructor uses default Brotli compression settings, which provide a good balance between compression ratio and speed for most use cases.

      Parameters:
      destination - the output stream to write compressed data to
      Throws:
      IOException - if an I/O error occurs during initialization
  • Method Details

    • finish

      public void finish() throws IOException
      Finishes writing compressed data to the output stream without closing the underlying stream.

      This method completes the compression process, finalizes the Brotli data format, and destroys the encoder to release its resources. Unlike the standard BrotliOutputStream.close() method, this method does not close the underlying output stream, allowing additional data to be written to it after compression is complete.

      Note: The parent BrotliOutputStream class does not close the underlying output stream in its close() method, unlike DeflaterOutputStream. Therefore, calling super.close() effectively finishes the compression without closing the destination stream.

      Specified by:
      finish in interface IFinishable
      Throws:
      IOException - if an I/O error occurs during finalization