segments = new SplitFileSegmentKeys[segmentCount];
if(segmentCount == 1) {
// splitfile* will be overwritten, this is bad
// so copy them
segments[0] = new SplitFileSegmentKeys(splitfileBlocks, splitfileCheckBlocks, splitfileSingleCryptoKey, splitfileSingleCryptoAlgorithm);
} else {
int dataBlocksPtr = 0;
int checkBlocksPtr = 0;
for(int i=0;i<segments.length;i++) {
// Create a segment. Give it its keys.
int copyDataBlocks = blocksPerSegment + crossCheckBlocks;
int copyCheckBlocks = checkBlocksPerSegment;
if(i == segments.length - 1) {
// Always accept the remainder as the last segment, but do basic sanity checking.
// In practice this can be affected by various things: 1) On old splitfiles before full even
// segment splitting with deductBlocksFromSegments (i.e. pre-1255), the last segment could be
// significantly smaller than the rest; 2) On 1251-1253, with partial even segment splitting,
// up to 131 data blocks per segment, cutting the check blocks if necessary, and with an extra
// check block if possible, the last segment could have *more* check blocks than the rest.
copyDataBlocks = splitfileBlocks - dataBlocksPtr;
copyCheckBlocks = splitfileCheckBlocks - checkBlocksPtr;
if(copyCheckBlocks <= 0 || copyDataBlocks <= 0)
throw new MetadataParseException("Last segment has bogus block count: total data blocks "+splitfileBlocks+" total check blocks "+splitfileCheckBlocks+" segment size "+blocksPerSegment+" data "+checkBlocksPerSegment+" check "+crossCheckBlocks+" cross check blocks, deduct "+deductBlocksFromSegments+", segments "+segments.length);
} else if(segments.length - i <= deductBlocksFromSegments) {
// Deduct one data block from each of the last deductBlocksFromSegments segments.
// This ensures no segment is more than 1 block larger than any other.
// We do not shrink the check blocks.
copyDataBlocks--;
}
segments[i] = new SplitFileSegmentKeys(copyDataBlocks, copyCheckBlocks, splitfileSingleCryptoKey, splitfileSingleCryptoAlgorithm);
if(logMINOR) Logger.minor(this, "REQUESTING: Segment "+i+" of "+segments.length+" : "+copyDataBlocks+" data blocks "+copyCheckBlocks+" check blocks");
dataBlocksPtr += copyDataBlocks;
checkBlocksPtr += copyCheckBlocks;
}
if(dataBlocksPtr != splitfileBlocks)