Class Decoder
- java.lang.Object
-
- com.aayushatharva.brotli4j.decoder.Decoder
-
- All Implemented Interfaces:
java.lang.AutoCloseable
- Direct Known Subclasses:
BrotliDecoderChannel
public class Decoder extends java.lang.Object implements java.lang.AutoCloseableBase class for InputStream / Channel implementations.
-
-
Constructor Summary
Constructors Constructor Description Decoder(java.nio.channels.ReadableByteChannel source, int inputBufferSize)Creates a Decoder wrapper.Decoder(java.nio.channels.ReadableByteChannel source, int inputBufferSize, int maxOutputChunkSize)Creates a Decoder wrapper with a per-pull output cap.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()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.voidenableEagerOutput()
-
-
-
Constructor Detail
-
Decoder
public Decoder(java.nio.channels.ReadableByteChannel source, int inputBufferSize) throws java.io.IOExceptionCreates a Decoder wrapper.- Parameters:
source- underlying sourceinputBufferSize- read buffer size- Throws:
java.io.IOException- If any failure during initialization
-
Decoder
public Decoder(java.nio.channels.ReadableByteChannel source, int inputBufferSize, int maxOutputChunkSize) throws java.io.IOExceptionCreates 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:
java.io.IOException- If any failure during initialization
-
-
Method Detail
-
decompress
public static DirectDecompress decompress(byte[] data) throws java.io.IOException
Decodes the given data buffer.- Parameters:
data- byte array of data to be decoded- Returns:
DirectDecompressinstance- Throws:
java.io.IOException- If an error occurs during decoding
-
decompress
public static DirectDecompress decompress(byte[] data, int maxOutputSize) throws java.io.IOException
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:
java.io.IOException- If an error occurs during decoding, or output exceedsmaxOutputSize
-
enableEagerOutput
public void enableEagerOutput()
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
java.io.IOException
-
decompress
public static byte[] decompress(byte[] data, int offset, int length) throws java.io.IOExceptionDecodes the given data buffer starting at offset till length.- Throws:
java.io.IOException
-
decompress
public static byte[] decompress(byte[] data, int offset, int length, int maxOutputSize) throws java.io.IOExceptionDecodes 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:
java.io.IOException- if input is corrupted, or output exceedsmaxOutputSize
-
-