Class BrotliOutputStream
- All Implemented Interfaces:
-
IFinishable,Closeable,Flushable,AutoCloseable
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:
-
IFinishableBrotliOutputStream
-
Constructor Summary
ConstructorsConstructorDescriptionBrotliOutputStream(OutputStream destination) 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 TypeMethodDescriptionvoidfinish()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, writeMethods inherited from class java.io.OutputStream
nullOutputStream
-
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
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
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
BrotliOutputStreamclass does not close the underlying output stream in itsclose()method, unlikeDeflaterOutputStream. Therefore, callingsuper.close()effectively finishes the compression without closing the destination stream.- Specified by:
-
finishin interfaceIFinishable - Throws:
-
IOException- if an I/O error occurs during finalization
-