Buffer[] buffers = new Buffer[k];
// The data blocks are already in the correct positions in dataBlocks.
for(int i=0;i<dataBlocks.length;i++) {
if(dataBlocks[i].length != blockLength) throw new IllegalArgumentException();
if(!dataBlocksPresent[i]) continue;
buffers[i] = new Buffer(dataBlocks[i], 0, blockLength);
blockNumbers[i] = i;
}
int target = 0;
// Fill in the gaps with the check blocks.
for(int i=0;i<checkBlocks.length;i++) {
if(!checkBlocksPresent[i]) continue;
if(checkBlocks[i].length != blockLength) throw new IllegalArgumentException();
while(target < dataBlocks.length && buffers[target] != null) target++; // Scan for slot.
if(target >= dataBlocks.length) continue;
// Decode into the slot for the relevant data block.
buffers[target] = new Buffer(dataBlocks[target]);
// Provide the data from the check block.
blockNumbers[target] = i + dataBlocks.length;
System.arraycopy(checkBlocks[i], 0, dataBlocks[target], 0, blockLength);
}