- // Compute the checksum for the entry.
- final Checksum crc32 = new CRC32();
- crc32.update(memory.array(), Integer.BYTES + Integer.BYTES, memory.limit() - (Integer.BYTES + Integer.BYTES));
- final long checksum = crc32.getValue();
-
- // Create a single byte[] in memory for the entire entry and write it as a batch to the underlying buffer.
- memory.putInt(0, length);
- memory.putInt(Integer.BYTES, (int) checksum);
- channel.write(memory);
-
- // Update the last entry with the correct index/term/length.
- Indexed<E> indexedEntry = new Indexed<>(index, entry, length);
- this.lastEntry = indexedEntry;
- this.index.index(index, (int) position);
- return (Indexed<T>) indexedEntry;
+ // Create a single byte[] in memory for the entire entry and write it as a batch to the underlying buffer.
+ memory.putInt(0, length).putInt(Integer.BYTES, (int) checksum);
+ try {
+ channel.write(memory, currentPosition);