// @Override
public void parse(byte[] data, ChmItspHeader chmItspHeader) throws TikaException {
/* we only know how to deal with the 0x58 and 0x60 byte structures */
if (data.length != ChmConstants.CHM_ITSP_V1_LEN)
throw new ChmParsingException("we only know how to deal with the 0x58 and 0x60 byte structures");
/* unmarshal common fields */
chmItspHeader.unmarshalCharArray(data, chmItspHeader, ChmConstants.CHM_SIGNATURE_LEN);
// ChmCommons.unmarshalCharArray(data, chmItspHeader,
// ChmConstants.CHM_SIGNATURE_LEN);
chmItspHeader.setVersion(chmItspHeader.unmarshalInt32(data,
chmItspHeader.getDataRemained(), chmItspHeader.getVersion()));
chmItspHeader
.setHeader_len(chmItspHeader.unmarshalInt32(data,
chmItspHeader.getDataRemained(),
chmItspHeader.getHeader_len()));
chmItspHeader.setUnknown_000c(chmItspHeader.unmarshalInt32(data,
chmItspHeader.getDataRemained(),
chmItspHeader.getUnknown_000c()));
chmItspHeader.setBlock_len(chmItspHeader.unmarshalUInt32(data,
chmItspHeader.getDataRemained(), chmItspHeader.getBlock_len()));
chmItspHeader.setBlockidx_intvl(chmItspHeader.unmarshalInt32(data,
chmItspHeader.getDataRemained(),
chmItspHeader.getBlockidx_intvl()));
chmItspHeader
.setIndex_depth(chmItspHeader.unmarshalInt32(data,
chmItspHeader.getDataRemained(),
chmItspHeader.getIndex_depth()));
chmItspHeader
.setIndex_root(chmItspHeader.unmarshalInt32(data,
chmItspHeader.getDataRemained(),
chmItspHeader.getIndex_root()));
chmItspHeader
.setIndex_head(chmItspHeader.unmarshalInt32(data,
chmItspHeader.getDataRemained(),
chmItspHeader.getIndex_head()));
chmItspHeader.setUnknown_0024(chmItspHeader.unmarshalInt32(data,
chmItspHeader.getDataRemained(),
chmItspHeader.getUnknown_0024()));
chmItspHeader
.setNum_blocks(chmItspHeader.unmarshalUInt32(data,
chmItspHeader.getDataRemained(),
chmItspHeader.getNum_blocks()));
chmItspHeader.setUnknown_002c((chmItspHeader.unmarshalInt32(data,
chmItspHeader.getDataRemained(),
chmItspHeader.getUnknown_002c())));
chmItspHeader.setLang_id(chmItspHeader.unmarshalUInt32(data,
chmItspHeader.getDataRemained(), chmItspHeader.getLang_id()));
chmItspHeader
.setSystem_uuid(chmItspHeader.unmarshalUuid(data,
chmItspHeader.getDataRemained(),
chmItspHeader.getSystem_uuid(),
ChmConstants.BYTE_ARRAY_LENGHT));
chmItspHeader
.setUnknown_0044(chmItspHeader.unmarshalUuid(data,
chmItspHeader.getDataRemained(),
chmItspHeader.getUnknown_0044(),
ChmConstants.BYTE_ARRAY_LENGHT));
/* Checks validity of the itsp header */
try {
if (!new String(chmItspHeader.getSignature(), "UTF-8").equals(ChmConstants.ITSP))
throw new ChmParsingException("seems not valid signature");
} catch (UnsupportedEncodingException e) {
throw new AssertionError("UTF-8 not supported.");
}
if (chmItspHeader.getVersion() != ChmConstants.CHM_VER_1)
throw new ChmParsingException("!=ChmConstants.CHM_VER_1");
if (chmItspHeader.getHeader_len() != ChmConstants.CHM_ITSP_V1_LEN)
throw new ChmParsingException("!= ChmConstants.CHM_ITSP_V1_LEN");
}