writeElement(element, key);
}
private void writeElement(Element element, Serializable key) throws IOException {
try {
MemoryEfficientByteArrayOutputStream buffer = serializeElement(element);
if (buffer == null) {
return;
}
int bufferLength = buffer.size();
try {
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;