Class Decoder

java.lang.Object
com.aayushatharva.brotli4j.decoder.Decoder
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
BrotliDecoderChannel

public class Decoder extends Object implements AutoCloseable
Base class for InputStream / Channel implementations.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Decoder(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 Type
    Method
    Description
    void
     
    decompress(byte[] data)
    Decodes the given data buffer.
    decompress(byte[] data, int maxOutputSize)
    Decodes the given data buffer, failing if decompressed output would exceed maxOutputSize bytes.
    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 exceed maxOutputSize bytes.
    void
     

    Methods inherited from class java.lang.Object

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

    • Decoder

      public Decoder(ReadableByteChannel source, int inputBufferSize) throws IOException
      Creates a Decoder wrapper.
      Parameters:
      source - underlying source
      inputBufferSize - 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 source
      inputBufferSize - read buffer size
      maxOutputChunkSize - per-pull output cap in bytes; 0 for no cap
      Throws:
      IOException - If any failure during initialization
  • Method Details

    • decompress

      public static DirectDecompress decompress(byte[] data) throws IOException
      Decodes the given data buffer.
      Parameters:
      data - byte array of data to be decoded
      Returns:
      DirectDecompress instance
      Throws:
      IOException - If an error occurs during decoding
    • decompress

      public static DirectDecompress decompress(byte[] data, int maxOutputSize) throws IOException
      Decodes the given data buffer, failing if decompressed output would exceed maxOutputSize bytes. Use to mitigate decompression bombs.
      Parameters:
      data - byte array of data to be decoded
      maxOutputSize - cap on total decompressed bytes; 0 for no cap
      Returns:
      DirectDecompress instance
      Throws:
      IOException - If an error occurs during decoding, or output exceeds maxOutputSize
    • enableEagerOutput

      public void enableEagerOutput()
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException
    • decompress

      public static byte[] decompress(byte[] data, int offset, int length) throws IOException
      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 exceed maxOutputSize bytes. Use to mitigate decompression bombs.
      Parameters:
      data - source byte array
      offset - offset within data
      length - compressed length
      maxOutputSize - cap on total decompressed bytes; 0 for no cap
      Returns:
      decompressed bytes
      Throws:
      IOException - if input is corrupted, or output exceeds maxOutputSize