}
}
}
private Vector ReadAndDecodePackedStreams(long baseOffset, int dataStartPosIndex) throws IOException {
LongVector packSizes = new LongVector();
BoolVector packCRCsDefined = new BoolVector();
IntVector packCRCs = new IntVector();
long type = this.inStream.ReadID();
assert (type == Header.NID.kPackInfo);
this.ReadPackInfo(packSizes, packCRCsDefined, packCRCs, dataStartPosIndex);
type = this.inStream.ReadID();
assert (type == Header.NID.kUnPackInfo);
Vector folders = ReadUnPackInfo(null);
type = this.inStream.ReadID();
assert (type == Header.NID.kEnd);
int packIndex = 0;
Decoder decoder = new Decoder(false); // _ST_MODE
Vector dataVector = new Vector();
long dataStartPos = baseOffset + ((dataStartPosIndex == 0) ?
this.ArchiveInfo.DataStartPosition : this.ArchiveInfo.DataStartPosition2);
for(int i=0; i<folders.size(); i++) {
Folder folder = (Folder)folders.get(i);
long unPackSize = folder.GetUnPackSize();
if (unPackSize > InStream.kNumMax || unPackSize > 0xFFFFFFFFL)
throw new IOException("unPackSize too great: " + unPackSize);
ByteArrayOutputStream baos = new ByteArrayOutputStream((int)unPackSize);
decoder.Decode(
this.inStream.stream, dataStartPos,
packSizes, packIndex,
folder, baos, null);
byte[] data; // TODO: stream belassen!
dataVector.add(data = baos.toByteArray());
if (folder.UnPackCRCDefined)
if (!CRC.VerifyDigest(folder.UnPackCRC, data, (int)unPackSize))
throw new IOException("Incorrect Header, CRCs of packed folder don't match: archive: " +
Integer.toHexString(folder.UnPackCRC) + ", calculated: " +
Integer.toHexString(CRC.CalculateDigest(data, (int)unPackSize)) +
". Either is the archive corrupted or an internal error occured");
for (int j = 0; j < folder.PackStreams.size(); j++)
dataStartPos += packSizes.get(packIndex++);
}
return dataVector;
}