if (newLength > fileChannel.size()) {
// truncate can't lengthen files, so we save position, seek/write, and go back
long position = fileChannel.position();
int difference = (int)(newLength - fileChannel.size());
fileChannel.position(fileChannel.size());
// FIXME: This worries me a bit, since it could allocate a lot with a large newLength
fileChannel.write(ByteBuffer.allocate(difference));
fileChannel.position(position);
} else {
fileChannel.truncate(newLength);