Package org.brotli.dec
Class Decode
- java.lang.Object
-
- org.brotli.dec.Decode
-
final class Decode extends java.lang.ObjectAPI 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_OFFSETprivate static intBLOCK_STARTprivate static intCD_BLOCK_MAP_BITSprivate static intCLOSED(package private) static short[]CMD_LOOKUPprivate static int[]CODE_LENGTH_CODE_ORDERprivate static intCODE_LENGTH_CODESprivate static intCODE_LENGTH_REPEAT_CODEprivate static intCOMPRESSED_BLOCK_STARTprivate static intCOPY_FROM_COMPOUND_DICTIONARY(package private) static short[]COPY_LENGTH_N_BITSprivate static intCOPY_LOOPprivate static intCOPY_UNCOMPRESSEDprivate static intDEFAULT_CODE_LENGTHprivate static intDISTANCE_CONTEXT_BITSprivate static int[]DISTANCE_SHORT_CODE_INDEX_OFFSETprivate static int[]DISTANCE_SHORT_CODE_VALUE_OFFSETprivate static intFINISHEDprivate static int[]FIXED_TABLEStatic Huffman code for the code length code lengths.private static intHUFFMAN_TABLE_BITSprivate static intHUFFMAN_TABLE_MASKprivate static intHUFFMAN_TABLE_SIZE_258private static intHUFFMAN_TABLE_SIZE_26private static intINIT_WRITEprivate static intINITIALIZED(package private) static short[]INSERT_LENGTH_N_BITSprivate static intINSERT_LOOPprivate static intLITERAL_CONTEXT_BITSprivate static intMAIN_LOOPprivate static intMAX_ALLOWED_DISTANCESafe distance limit.private static intMAX_DISTANCE_BITS(package private) static int[]MAX_HUFFMAN_TABLE_SIZEMaximum possible Huffman table size for an alphabet size of (index * 32), max code length 15 and root table bits 8.(package private) static intMAX_LARGE_WINDOW_BITSprivate static intMAX_LARGE_WINDOW_DISTANCE_BITS(package private) static intMAX_TRANSFORMED_WORD_LENGTH(package private) static intMIN_LARGE_WINDOW_BITSprivate static intNUM_BLOCK_LENGTH_CODESprivate static intNUM_COMMAND_CODESprivate static intNUM_DISTANCE_SHORT_CODESprivate static intNUM_LITERAL_CODESprivate static intREAD_METADATAprivate static intUNINITIALIZEDprivate static intUSE_DICTIONARYprivate static intWRITE
-
Constructor Summary
Constructors Constructor Description Decode()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static voidattachDictionaryChunk(State s, byte[] data)private static intcalculateDistanceAlphabetLimit(int maxDistance, int npostfix, int ndirect)private static intcalculateDistanceAlphabetSize(int npostfix, int ndirect, int maxndistbits)private static voidcalculateDistanceLut(State s, int alphabetSizeLimit)private static intcalculateFence(State s)private static voidcheckDupes(int[] symbols, int length)(package private) static voidclose(State s)private static intcopyFromCompoundDictionary(State s, int fence)private static voidcopyUncompressedData(State s)private static intdecodeBlockTypeAndLength(State s, int treeType, int numBlockTypes)private static voiddecodeCommandBlockSwitch(State s)private static intdecodeContextMap(int contextMapSize, byte[] contextMap, State s)private static voiddecodeDistanceBlockSwitch(State s)private static int[]decodeHuffmanTreeGroup(int alphabetSizeMax, int alphabetSizeLimit, int n, State s)private static voiddecodeLiteralBlockSwitch(State s)private static voiddecodeMetaBlockLength(State s)private static intdecodeVarLenUnsignedByte(State s)Decodes a number in the range [0..255], by reading 1 - 11 bits.private static intdecodeWindowBits(State s)Reads brotli stream header and parses "window bits".(package private) static voiddecompress(State s)Actual decompress implementation.private static voiddoUseDictionary(State s, int fence)(package private) static voidenableEagerOutput(State s)Switch decoder to "eager" mode.(package private) static voidenableLargeWindow(State s)private static voidinitializeCompoundDictionary(State s)private static voidinitializeCompoundDictionaryCopy(State s, int address, int length)(package private) static voidinitState(State s, java.io.InputStream input)Associate input with decoder state.private static voidinverseMoveToFrontTransform(byte[] v, int vLen)private static intlog2floor(int i)private static voidmaybeReallocateRingBuffer(State s)private static voidmoveToFront(int[] v, int index)private static intreadBlockLength(int[] tableGroup, int tableIdx, State s)private static intreadComplexHuffmanCode(int alphabetSizeLimit, int skip, int[] tableGroup, int tableIdx, State s)private static intreadHuffmanCode(int alphabetSizeMax, int alphabetSizeLimit, int[] tableGroup, int tableIdx, State s)Decodes Huffman table from bit-stream.private static voidreadHuffmanCodeLengths(int[] codeLengthCodeLengths, int numSymbols, int[] codeLengths, State s)private static voidreadMetablockHuffmanCodesAndContextMaps(State s)private static intreadMetablockPartition(State s, int treeType, int numBlockTypes)private static voidreadNextMetablockHeader(State s)private static intreadSimpleHuffmanCode(int alphabetSizeMax, int alphabetSizeLimit, int[] tableGroup, int tableIdx, State s)Reads up to 4 symbols directly and applies predefined histograms.private static intreadSymbol(int[] tableGroup, int tableIdx, State s)Decodes the next Huffman code from bit-stream.private static voidunpackCommandLookupTable(short[] cmdLookup)private static intwriteRingBuffer(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.
-
-