in tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/chm/ChmLzxBlock.java [108:211]
private void extractContent() throws TikaException {
assertStateNotNull();
if (getChmSection().getData() != null) {
boolean continueLoop = true;
while (continueLoop && getContentLength() < getBlockLength()) {
if (getState() != null && getState().getBlockRemaining() == 0) {
if (getState().getHadStarted() == LzxState.NOT_STARTED_DECODING) {
getState().setHadStarted(LzxState.STARTED_DECODING);
if (getChmSection().getSyncBits(1) == 1) {
int intelSizeTemp = (getChmSection().getSyncBits(16) << 16) +
getChmSection().getSyncBits(16);
if (intelSizeTemp >= 0) {
getState().setIntelFileSize(intelSizeTemp);
} else {
getState().setIntelFileSize(0);
}
}
}
getState().setBlockType(getChmSection().getSyncBits(3));
getState().setBlockLength((getChmSection().getSyncBits(16) << 8) +
getChmSection().getSyncBits(8));
getState().setBlockRemaining(getState().getBlockLength());
// ----------------------------------------
// Trying to handle 3 - 7 block types
// ----------------------------------------
if (getState().getBlockType() > 3) {
if (previousBlockType >= 0 && previousBlockType < 3) {
getState().setBlockType(previousBlockType);
}
}
switch (getState().getBlockType()) {
case ChmCommons.ALIGNED_OFFSET:
createAlignedTreeTable();
//fall through
case ChmCommons.VERBATIM:
/* Creates mainTreeTable */
createMainTreeTable();
createLengthTreeTable();
if (getState().getMainTreeLengtsTable()[0xe8] != 0) {
getState().setIntelState(IntelState.STARTED);
}
break;
case ChmCommons.UNCOMPRESSED:
getState().setIntelState(IntelState.STARTED);
if (getChmSection().getTotal() > 16) {
getChmSection().setSwath(getChmSection().getSwath() - 1);
}
getState().setR0((new BigInteger(getChmSection()
.reverseByteOrder(getChmSection().unmarshalBytes(4)))
.longValue()));
getState().setR1((new BigInteger(getChmSection()
.reverseByteOrder(getChmSection().unmarshalBytes(4)))
.longValue()));
getState().setR2((new BigInteger(getChmSection()
.reverseByteOrder(getChmSection().unmarshalBytes(4)))
.longValue()));
break;
default:
break;
}
} //end of if BlockRemaining == 0
int tempLen;
if (getContentLength() + getState().getBlockRemaining() > getBlockLength()) {
getState().setBlockRemaining(
getContentLength() + getState().getBlockRemaining() -
(int) getBlockLength());
tempLen = (int) getBlockLength();
} else {
tempLen = getContentLength() + getState().getBlockRemaining();
getState().setBlockRemaining(0);
}
int lastLength = getContentLength();
switch (getState().getBlockType()) {
case ChmCommons.ALIGNED_OFFSET:
// if(prevblock.lzxState.length>prevblock.lzxState.remaining)
decompressAlignedBlock(tempLen, getChmSection().getPrevContent() == null ?
getChmSection().getData() :
getChmSection().getPrevContent());// prevcontext
break;
case ChmCommons.VERBATIM:
decompressVerbatimBlock(tempLen, getChmSection().getPrevContent() == null ?
getChmSection().getData() : getChmSection().getPrevContent());
break;
case ChmCommons.UNCOMPRESSED:
decompressUncompressedBlock(tempLen,
getChmSection().getPrevContent() == null ?
getChmSection().getData() :
getChmSection().getPrevContent());
break;
}
getState().increaseFramesRead();
if ((getState().getFramesRead() < 32768) && getState().getIntelFileSize() != 0) {
intelE8Decoding();
}
continueLoop = getContentLength() > lastLength;
}
}
}