DiskElement diskElement = checkForFreeBlock(bufferLength);
// Write the record
RandomAccessFile randomAccessFile = selectRandomAccessFile(key);
synchronized (randomAccessFile) {
randomAccessFile.seek(diskElement.position);
randomAccessFile.write(buffer.toByteArray(), 0, bufferLength);
}
buffer = null;
// Add to index, update stats
diskElement.payloadSize = bufferLength;
diskElement.key = key;