// Read more bytes from the segment if necessary.
if (memory.remaining() < maxEntrySize) {
long position = currentPosition + memory.position();
- memory.clear();
- channel.read(memory, position);
+ channel.read(memory.clear(), position);
currentPosition = position;
memory.flip();
}
try {
// Clear memory buffer and read fist chunk
- memory.clear();
- channel.read(memory, JournalSegmentDescriptor.BYTES);
+ channel.read(memory.clear(), JournalSegmentDescriptor.BYTES);
memory.flip();
// Read the entry length.
// Read more bytes from the segment if necessary.
if (memory.remaining() < maxEntrySize) {
- memory.compact();
- channel.read(memory);
+ channel.read(memory.compact());
memory.flip();
}
final long index = getNextIndex();
// Serialize the entry.
- memory.clear();
- memory.position(Integer.BYTES + Integer.BYTES);
try {
- namespace.serialize(entry, memory);
+ namespace.serialize(entry, memory.clear().position(Integer.BYTES + Integer.BYTES));
} catch (KryoException e) {
throw new StorageException.TooLarge("Entry size exceeds maximum allowed bytes (" + maxEntrySize + ")");
}
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);
+ memory.putInt(0, length).putInt(Integer.BYTES, (int) checksum);
try {
channel.write(memory, currentPosition);
} catch (IOException e) {