Package org.brotli.dec
Class Decode
- java.lang.Object
-
- org.brotli.dec.Decode
-
final class Decode extends java.lang.Object
API for Brotli decompression.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static int[]
BLOCK_LENGTH_N_BITS
(package private) static int[]
BLOCK_LENGTH_OFFSET
private static int
BLOCK_START
private static int
CD_BLOCK_MAP_BITS
private static int
CLOSED
(package private) static short[]
CMD_LOOKUP
private static int[]
CODE_LENGTH_CODE_ORDER
private static int
CODE_LENGTH_CODES
private static int
CODE_LENGTH_REPEAT_CODE
private static int
COMPRESSED_BLOCK_START
private static int
COPY_FROM_COMPOUND_DICTIONARY
(package private) static short[]
COPY_LENGTH_N_BITS
private static int
COPY_LOOP
private static int
COPY_UNCOMPRESSED
private static int
DEFAULT_CODE_LENGTH
private static int
DISTANCE_CONTEXT_BITS
private static int[]
DISTANCE_SHORT_CODE_INDEX_OFFSET
private static int[]
DISTANCE_SHORT_CODE_VALUE_OFFSET
private static int
FINISHED
private static int[]
FIXED_TABLE
Static Huffman code for the code length code lengths.private static int
HUFFMAN_TABLE_BITS
private static int
HUFFMAN_TABLE_MASK
private static int
HUFFMAN_TABLE_SIZE_258
private static int
HUFFMAN_TABLE_SIZE_26
private static int
INIT_WRITE
private static int
INITIALIZED
(package private) static short[]
INSERT_LENGTH_N_BITS
private static int
INSERT_LOOP
private static int
LITERAL_CONTEXT_BITS
private static int
MAIN_LOOP
private static int
MAX_ALLOWED_DISTANCE
Safe distance limit.private static int
MAX_DISTANCE_BITS
(package private) static 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.(package private) static int
MAX_LARGE_WINDOW_BITS
private static int
MAX_LARGE_WINDOW_DISTANCE_BITS
(package private) static int
MAX_TRANSFORMED_WORD_LENGTH
(package private) static int
MIN_LARGE_WINDOW_BITS
private static int
NUM_BLOCK_LENGTH_CODES
private static int
NUM_COMMAND_CODES
private static int
NUM_DISTANCE_SHORT_CODES
private static int
NUM_LITERAL_CODES
private static int
READ_METADATA
private static int
UNINITIALIZED
private static int
USE_DICTIONARY
private static int
WRITE
-
Constructor Summary
Constructors Constructor Description Decode()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static void
attachDictionaryChunk(State s, byte[] data)
private static int
calculateDistanceAlphabetLimit(int maxDistance, int npostfix, int ndirect)
private static int
calculateDistanceAlphabetSize(int npostfix, int ndirect, int maxndistbits)
private static void
calculateDistanceLut(State s, int alphabetSizeLimit)
private static int
calculateFence(State s)
private static void
checkDupes(int[] symbols, int length)
(package private) static void
close(State s)
private static int
copyFromCompoundDictionary(State s, int fence)
private static void
copyUncompressedData(State s)
private static int
decodeBlockTypeAndLength(State s, int treeType, int numBlockTypes)
private static void
decodeCommandBlockSwitch(State s)
private static int
decodeContextMap(int contextMapSize, byte[] contextMap, State s)
private static void
decodeDistanceBlockSwitch(State s)
private static int[]
decodeHuffmanTreeGroup(int alphabetSizeMax, int alphabetSizeLimit, int n, State s)
private static void
decodeLiteralBlockSwitch(State s)
private static void
decodeMetaBlockLength(State s)
private static int
decodeVarLenUnsignedByte(State s)
Decodes a number in the range [0..255], by reading 1 - 11 bits.private static int
decodeWindowBits(State s)
Reads brotli stream header and parses "window bits".(package private) static void
decompress(State s)
Actual decompress implementation.private static void
doUseDictionary(State s, int fence)
(package private) static void
enableEagerOutput(State s)
Switch decoder to "eager" mode.(package private) static void
enableLargeWindow(State s)
private static void
initializeCompoundDictionary(State s)
private static void
initializeCompoundDictionaryCopy(State s, int address, int length)
(package private) static void
initState(State s, java.io.InputStream input)
Associate input with decoder state.private static void
inverseMoveToFrontTransform(byte[] v, int vLen)
private static int
log2floor(int i)
private static void
maybeReallocateRingBuffer(State s)
private static void
moveToFront(int[] v, int index)
private static int
readBlockLength(int[] tableGroup, int tableIdx, State s)
private static int
readComplexHuffmanCode(int alphabetSizeLimit, int skip, int[] tableGroup, int tableIdx, State s)
private static int
readHuffmanCode(int alphabetSizeMax, int alphabetSizeLimit, int[] tableGroup, int tableIdx, State s)
Decodes Huffman table from bit-stream.private static void
readHuffmanCodeLengths(int[] codeLengthCodeLengths, int numSymbols, int[] codeLengths, State s)
private static void
readMetablockHuffmanCodesAndContextMaps(State s)
private static int
readMetablockPartition(State s, int treeType, int numBlockTypes)
private static void
readNextMetablockHeader(State s)
private static int
readSimpleHuffmanCode(int alphabetSizeMax, int alphabetSizeLimit, int[] tableGroup, int tableIdx, State s)
Reads up to 4 symbols directly and applies predefined histograms.private static int
readSymbol(int[] tableGroup, int tableIdx, State s)
Decodes the next Huffman code from bit-stream.private static void
unpackCommandLookupTable(short[] cmdLookup)
private static int
writeRingBuffer(State s)
-
-
-
Field Detail
-
MIN_LARGE_WINDOW_BITS
static final int MIN_LARGE_WINDOW_BITS
- See Also:
- Constant Field Values
-
MAX_LARGE_WINDOW_BITS
static final int MAX_LARGE_WINDOW_BITS
- See Also:
- Constant Field Values
-
UNINITIALIZED
private static final int UNINITIALIZED
- See Also:
- Constant Field Values
-
INITIALIZED
private static final int INITIALIZED
- See Also:
- Constant Field Values
-
BLOCK_START
private static final int BLOCK_START
- See Also:
- Constant Field Values
-
COMPRESSED_BLOCK_START
private static final int COMPRESSED_BLOCK_START
- See Also:
- Constant Field Values
-
MAIN_LOOP
private static final int MAIN_LOOP
- See Also:
- Constant Field Values
-
READ_METADATA
private static final int READ_METADATA
- See Also:
- Constant Field Values
-
COPY_UNCOMPRESSED
private static final int COPY_UNCOMPRESSED
- See Also:
- Constant Field Values
-
INSERT_LOOP
private static final int INSERT_LOOP
- See Also:
- Constant Field Values
-
COPY_LOOP
private static final int COPY_LOOP
- See Also:
- Constant Field Values
-
USE_DICTIONARY
private static final int USE_DICTIONARY
- See Also:
- Constant Field Values
-
FINISHED
private static final int FINISHED
- See Also:
- Constant Field Values
-
CLOSED
private static final int CLOSED
- See Also:
- Constant Field Values
-
INIT_WRITE
private static final int INIT_WRITE
- See Also:
- Constant Field Values
-
WRITE
private static final int WRITE
- See Also:
- Constant Field Values
-
COPY_FROM_COMPOUND_DICTIONARY
private static final int COPY_FROM_COMPOUND_DICTIONARY
- See Also:
- Constant Field Values
-
DEFAULT_CODE_LENGTH
private static final int DEFAULT_CODE_LENGTH
- See Also:
- Constant Field Values
-
CODE_LENGTH_REPEAT_CODE
private static final int CODE_LENGTH_REPEAT_CODE
- See Also:
- Constant Field Values
-
NUM_LITERAL_CODES
private static final int NUM_LITERAL_CODES
- See Also:
- Constant Field Values
-
NUM_COMMAND_CODES
private static final int NUM_COMMAND_CODES
- See Also:
- Constant Field Values
-
NUM_BLOCK_LENGTH_CODES
private static final int NUM_BLOCK_LENGTH_CODES
- See Also:
- Constant Field Values
-
LITERAL_CONTEXT_BITS
private static final int LITERAL_CONTEXT_BITS
- See Also:
- Constant Field Values
-
DISTANCE_CONTEXT_BITS
private static final int DISTANCE_CONTEXT_BITS
- See Also:
- Constant Field Values
-
CD_BLOCK_MAP_BITS
private static final int CD_BLOCK_MAP_BITS
- See Also:
- Constant Field Values
-
HUFFMAN_TABLE_BITS
private static final int HUFFMAN_TABLE_BITS
- See Also:
- Constant Field Values
-
HUFFMAN_TABLE_MASK
private static final int HUFFMAN_TABLE_MASK
- 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_26
private static final int HUFFMAN_TABLE_SIZE_26
- See Also:
- Constant Field Values
-
HUFFMAN_TABLE_SIZE_258
private static final int HUFFMAN_TABLE_SIZE_258
- See Also:
- Constant Field Values
-
CODE_LENGTH_CODES
private static final int CODE_LENGTH_CODES
- 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_DISTANCE_BITS
private static final int MAX_DISTANCE_BITS
- 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
-
-
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 inputinput
- 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.
-
-