If length == MAX_BLOCK_SIZE, I think this breaks.
totalBlocks = 1;
chunkSize = 0, but it should be MAX_BLOCK_SIZE.

I'll file a bug on JIRA :)