Class Decode


  • final class Decode
    extends java.lang.Object
    API for Brotli decompression.
    • Field Detail

      • COMPRESSED_BLOCK_START

        private static final int COMPRESSED_BLOCK_START
        See Also:
        Constant Field Values
      • COPY_FROM_COMPOUND_DICTIONARY

        private static final int COPY_FROM_COMPOUND_DICTIONARY
        See Also:
        Constant Field Values
      • CODE_LENGTH_REPEAT_CODE

        private static final int CODE_LENGTH_REPEAT_CODE
        See Also:
        Constant Field Values
      • NUM_BLOCK_LENGTH_CODES

        private static final int NUM_BLOCK_LENGTH_CODES
        See Also:
        Constant Field Values
      • MAX_HUFFMAN_TABLE_SIZE

        static final int[] MAX_HUFFMAN_TABLE_SIZE
        Maximum possible Huffman table size for an alphabet size of (index * 32), max code length 15 and root table bits 8. The biggest alphabet is "command" - 704 symbols. Though "distance" alphabet could theoretically outreach that limit (for 62 extra bit distances), practically it is limited by MAX_ALLOWED_DISTANCE and never gets bigger than 544 symbols.
      • HUFFMAN_TABLE_SIZE_258

        private static final int HUFFMAN_TABLE_SIZE_258
        See Also:
        Constant Field Values
      • CODE_LENGTH_CODE_ORDER

        private static final int[] CODE_LENGTH_CODE_ORDER
      • NUM_DISTANCE_SHORT_CODES

        private static final int NUM_DISTANCE_SHORT_CODES
        See Also:
        Constant Field Values
      • DISTANCE_SHORT_CODE_INDEX_OFFSET

        private static final int[] DISTANCE_SHORT_CODE_INDEX_OFFSET
      • DISTANCE_SHORT_CODE_VALUE_OFFSET

        private static final int[] DISTANCE_SHORT_CODE_VALUE_OFFSET
      • FIXED_TABLE

        private static final int[] FIXED_TABLE
        Static Huffman code for the code length code lengths.
      • MAX_TRANSFORMED_WORD_LENGTH

        static final int MAX_TRANSFORMED_WORD_LENGTH
        See Also:
        Constant Field Values
      • MAX_LARGE_WINDOW_DISTANCE_BITS

        private static final int MAX_LARGE_WINDOW_DISTANCE_BITS
        See Also:
        Constant Field Values
      • MAX_ALLOWED_DISTANCE

        private static final int MAX_ALLOWED_DISTANCE
        Safe distance limit. Limit ((1 << 31) - 4) allows safe distance calculation without overflows, given the distance alphabet size is limited to corresponding size.
        See Also:
        Constant Field Values
      • BLOCK_LENGTH_OFFSET

        static final int[] BLOCK_LENGTH_OFFSET
      • BLOCK_LENGTH_N_BITS

        static final int[] BLOCK_LENGTH_N_BITS
      • INSERT_LENGTH_N_BITS

        static final short[] INSERT_LENGTH_N_BITS
      • COPY_LENGTH_N_BITS

        static final short[] COPY_LENGTH_N_BITS
      • CMD_LOOKUP

        static final short[] CMD_LOOKUP
    • Constructor Detail

      • Decode

        Decode()
    • Method Detail

      • log2floor

        private static int log2floor​(int i)
      • calculateDistanceAlphabetSize

        private static int calculateDistanceAlphabetSize​(int npostfix,
                                                         int ndirect,
                                                         int maxndistbits)
      • calculateDistanceAlphabetLimit

        private static int calculateDistanceAlphabetLimit​(int maxDistance,
                                                          int npostfix,
                                                          int ndirect)
      • unpackCommandLookupTable

        private static void unpackCommandLookupTable​(short[] cmdLookup)
      • decodeWindowBits

        private static int decodeWindowBits​(State s)
        Reads brotli stream header and parses "window bits".
        Parameters:
        s - initialized state, before any read is performed.
        Returns:
        -1 if header is invalid
      • enableEagerOutput

        static void enableEagerOutput​(State s)
        Switch decoder to "eager" mode. In "eager" mode decoder returns as soon as there is enough data to fill output buffer.
        Parameters:
        s - initialized state, before any read is performed.
      • enableLargeWindow

        static void enableLargeWindow​(State s)
      • attachDictionaryChunk

        static void attachDictionaryChunk​(State s,
                                          byte[] data)
      • initState

        static void initState​(State s,
                              java.io.InputStream input)
        Associate input with decoder state.
        Parameters:
        s - uninitialized state without associated input
        input - compressed data source
      • close

        static void close​(State s)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • decodeVarLenUnsignedByte

        private static int decodeVarLenUnsignedByte​(State s)
        Decodes a number in the range [0..255], by reading 1 - 11 bits.
      • decodeMetaBlockLength

        private static void decodeMetaBlockLength​(State s)
      • readSymbol

        private static int readSymbol​(int[] tableGroup,
                                      int tableIdx,
                                      State s)
        Decodes the next Huffman code from bit-stream.
      • readBlockLength

        private static int readBlockLength​(int[] tableGroup,
                                           int tableIdx,
                                           State s)
      • moveToFront

        private static void moveToFront​(int[] v,
                                        int index)
      • inverseMoveToFrontTransform

        private static void inverseMoveToFrontTransform​(byte[] v,
                                                        int vLen)
      • readHuffmanCodeLengths

        private static void readHuffmanCodeLengths​(int[] codeLengthCodeLengths,
                                                   int numSymbols,
                                                   int[] codeLengths,
                                                   State s)
      • checkDupes

        private static void checkDupes​(int[] symbols,
                                       int length)
      • readSimpleHuffmanCode

        private static int readSimpleHuffmanCode​(int alphabetSizeMax,
                                                 int alphabetSizeLimit,
                                                 int[] tableGroup,
                                                 int tableIdx,
                                                 State s)
        Reads up to 4 symbols directly and applies predefined histograms.
      • readComplexHuffmanCode

        private static int readComplexHuffmanCode​(int alphabetSizeLimit,
                                                  int skip,
                                                  int[] tableGroup,
                                                  int tableIdx,
                                                  State s)
      • readHuffmanCode

        private static int readHuffmanCode​(int alphabetSizeMax,
                                           int alphabetSizeLimit,
                                           int[] tableGroup,
                                           int tableIdx,
                                           State s)
        Decodes Huffman table from bit-stream.
        Returns:
        number of slots used by resulting Huffman table
      • decodeContextMap

        private static int decodeContextMap​(int contextMapSize,
                                            byte[] contextMap,
                                            State s)
      • decodeBlockTypeAndLength

        private static int decodeBlockTypeAndLength​(State s,
                                                    int treeType,
                                                    int numBlockTypes)
      • decodeLiteralBlockSwitch

        private static void decodeLiteralBlockSwitch​(State s)
      • decodeCommandBlockSwitch

        private static void decodeCommandBlockSwitch​(State s)
      • decodeDistanceBlockSwitch

        private static void decodeDistanceBlockSwitch​(State s)
      • maybeReallocateRingBuffer

        private static void maybeReallocateRingBuffer​(State s)
      • readNextMetablockHeader

        private static void readNextMetablockHeader​(State s)
      • readMetablockPartition

        private static int readMetablockPartition​(State s,
                                                  int treeType,
                                                  int numBlockTypes)
      • calculateDistanceLut

        private static void calculateDistanceLut​(State s,
                                                 int alphabetSizeLimit)
      • readMetablockHuffmanCodesAndContextMaps

        private static void readMetablockHuffmanCodesAndContextMaps​(State s)
      • copyUncompressedData

        private static void copyUncompressedData​(State s)
      • writeRingBuffer

        private static int writeRingBuffer​(State s)
      • decodeHuffmanTreeGroup

        private static int[] decodeHuffmanTreeGroup​(int alphabetSizeMax,
                                                    int alphabetSizeLimit,
                                                    int n,
                                                    State s)
      • calculateFence

        private static int calculateFence​(State s)
      • doUseDictionary

        private static void doUseDictionary​(State s,
                                            int fence)
      • initializeCompoundDictionary

        private static void initializeCompoundDictionary​(State s)
      • initializeCompoundDictionaryCopy

        private static void initializeCompoundDictionaryCopy​(State s,
                                                             int address,
                                                             int length)
      • copyFromCompoundDictionary

        private static int copyFromCompoundDictionary​(State s,
                                                      int fence)
      • decompress

        static void decompress​(State s)
        Actual decompress implementation.