Class Decoder

  • All Implemented Interfaces:
    java.lang.AutoCloseable
    Direct Known Subclasses:
    BrotliDecoderChannel

    public class Decoder
    extends java.lang.Object
    implements java.lang.AutoCloseable
    Base 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
      void close()  
      static DirectDecompress decompress​(byte[] data)
      Decodes the given data buffer.
      static DirectDecompress 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 enableEagerOutput()  
      • Methods inherited from class java.lang.Object

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

      • Decoder

        public Decoder​(java.nio.channels.ReadableByteChannel source,
                       int inputBufferSize)
                throws java.io.IOException
        Creates a Decoder wrapper.
        Parameters:
        source - underlying source
        inputBufferSize - 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.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:
        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:
        DirectDecompress instance
        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 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:
        java.io.IOException - If an error occurs during decoding, or output exceeds maxOutputSize
      • enableEagerOutput

        public void enableEagerOutput()
      • close

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

        public static byte[] decompress​(byte[] data,
                                        int offset,
                                        int length)
                                 throws java.io.IOException
        Decodes 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.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:
        java.io.IOException - if input is corrupted, or output exceeds maxOutputSize