SplitFileInserterCrossSegmentStorage(SplitFileInserterStorage parent, DataInputStream dis,
int segNo) throws StorageFormatException, IOException {
this.segNo = segNo;
this.parent = parent;
this.dataBlockCount = dis.readInt();
if(dataBlockCount <= 0) throw new StorageFormatException("Negative cross-segment data block count");
this.crossCheckBlockCount = dis.readInt();
if(crossCheckBlockCount <= 0) throw new StorageFormatException("Negative cross-check block count");
this.totalBlocks = dataBlockCount + crossCheckBlockCount;
if(totalBlocks > FECCodec.MAX_TOTAL_BLOCKS_PER_SEGMENT)
throw new StorageFormatException("Bogus total block count");
segments = new SplitFileInserterSegmentStorage[totalBlocks];
blockNumbers = new int[totalBlocks];
for(int i=0;i<totalBlocks;i++) {
int readSegmentNumber = dis.readInt();
if(readSegmentNumber < 0 || readSegmentNumber >= parent.segments.length)
throw new StorageFormatException("Bogus segment number "+readSegmentNumber);
int readBlockNumber = dis.readInt();
SplitFileInserterSegmentStorage segment = parent.segments[readSegmentNumber];
if(readBlockNumber < 0 ||
(readBlockNumber >= segment.dataBlockCount + segment.crossCheckBlockCount)
|| (i < dataBlockCount && readBlockNumber >= segment.dataBlockCount)
|| (i >= dataBlockCount && readBlockNumber < segment.dataBlockCount))
throw new StorageFormatException("Bogus block number "+readBlockNumber+" for slot "+i);
segments[i] = segment;
blockNumbers[i] = readBlockNumber;
}
for(int i=0;i<crossCheckBlockCount;i++) {
segments[i+dataBlockCount].setCrossCheckBlock(this, blockNumbers[i+dataBlockCount], i+dataBlockCount);
}
statusLength = dis.readInt();
if(statusLength < 0) throw new StorageFormatException("Bogus status length");
try {
CountedOutputStream cos = new CountedOutputStream(new NullOutputStream());
DataOutputStream dos = new DataOutputStream(cos);
innerStoreStatus(dos);
dos.close();
int computedStatusLength = (int) cos.written() + parent.checker.checksumLength();
if(computedStatusLength > statusLength)
throw new StorageFormatException("Stored status length smaller than required");
} catch (IOException e) {
throw new Error(e); // Impossible
}
}