Class Decoder
java.lang.Object
com.aayushatharva.brotli4j.decoder.Decoder
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
BrotliDecoderChannel
Base class for InputStream / Channel implementations.
-
Constructor Summary
ConstructorsConstructorDescriptionDecoder(ReadableByteChannel source, int inputBufferSize) Creates a Decoder wrapper.Decoder(ReadableByteChannel source, int inputBufferSize, int maxOutputChunkSize) Creates a Decoder wrapper with a per-pull output cap. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static DirectDecompressdecompress(byte[] data) Decodes the given data buffer.static DirectDecompressdecompress(byte[] data, int maxOutputSize) Decodes the given data buffer, failing if decompressed output would exceedmaxOutputSizebytes.static byte[]decompress(byte[] data, int offset, int length) Decodes the given data buffer starting at offset till length.static byte[]decompress(byte[] data, int offset, int length, int maxOutputSize) Decodes the given data buffer starting at offset till length, failing if decompressed output would exceedmaxOutputSizebytes.void
-
Constructor Details
-
Decoder
Creates a Decoder wrapper.- Parameters:
source- underlying sourceinputBufferSize- read buffer size- Throws:
IOException- If any failure during initialization
-
Decoder
public Decoder(ReadableByteChannel source, int inputBufferSize, int maxOutputChunkSize) throws IOException Creates a Decoder wrapper with a per-pull output cap.- Parameters:
source- underlying sourceinputBufferSize- read buffer sizemaxOutputChunkSize- per-pull output cap in bytes;0for no cap- Throws:
IOException- If any failure during initialization
-
-
Method Details
-
decompress
Decodes the given data buffer.- Parameters:
data- byte array of data to be decoded- Returns:
DirectDecompressinstance- Throws:
IOException- If an error occurs during decoding
-
decompress
Decodes the given data buffer, failing if decompressed output would exceedmaxOutputSizebytes. Use to mitigate decompression bombs.- Parameters:
data- byte array of data to be decodedmaxOutputSize- cap on total decompressed bytes;0for no cap- Returns:
DirectDecompressinstance- Throws:
IOException- If an error occurs during decoding, or output exceedsmaxOutputSize
-
enableEagerOutput
public void enableEagerOutput() -
close
- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-
decompress
Decodes the given data buffer starting at offset till length.- Throws:
IOException
-
decompress
public static byte[] decompress(byte[] data, int offset, int length, int maxOutputSize) throws IOException Decodes the given data buffer starting at offset till length, failing if decompressed output would exceedmaxOutputSizebytes. Use to mitigate decompression bombs.- Parameters:
data- source byte arrayoffset- offset withindatalength- compressed lengthmaxOutputSize- cap on total decompressed bytes;0for no cap- Returns:
- decompressed bytes
- Throws:
IOException- if input is corrupted, or output exceedsmaxOutputSize
-