});
}
private void innerEncode(MemoryLimitedChunk chunk) {
RAFLock lock = null;
try {
synchronized(this) {
if(cancelled) return;
}
lock = parent.lockRAF();
if(logMINOR) Logger.minor(this, "Encoding "+this+" for "+parent);
byte[][] dataBlocks = readDataAndCrossCheckBlocks();
generateKeys(dataBlocks, 0);
byte[][] checkBlocks = new byte[checkBlockCount][];
for(int i=0;i<checkBlocks.length;i++)
checkBlocks[i] = new byte[CHKBlock.DATA_LENGTH];
if(dataBlocks == null || checkBlocks == null) return; // Failed with disk error.
parent.codec.encode(dataBlocks, checkBlocks, new boolean[checkBlocks.length], CHKBlock.DATA_LENGTH);
for(int i=0;i<checkBlocks.length;i++)
writeCheckBlock(i, checkBlocks[i]);
generateKeys(checkBlocks, dataBlockCount + crossCheckBlockCount);
synchronized(this) {
encoded = true;
}
if(logMINOR) Logger.minor(this, "Encoded "+this+" for "+parent);
} catch (IOException e) {
parent.failOnDiskError(e);
} catch (Throwable t) {
Logger.error(this, "Failed: "+t, t);
parent.fail(new InsertException(InsertExceptionMode.INTERNAL_ERROR, t, null));
} finally {
if(lock != null) lock.unlock();
}
}