- int length = buffer.getInt();
-
- // If the length is non-zero, read the entry.
- while (0 < length && length <= maxEntrySize && (index == 0 || nextIndex <= index)) {
-
- // Read the checksum of the entry.
- final long checksum = buffer.getInt() & 0xFFFFFFFFL;
-
- // Compute the checksum for the entry bytes.
- final CRC32 crc32 = new CRC32();
- ByteBuffer slice = buffer.slice();
- slice.limit(length);
- crc32.update(slice);
-
- // If the stored checksum equals the computed checksum, return the entry.
- if (checksum == crc32.getValue()) {
- slice.rewind();
- final E entry = namespace.deserialize(slice);
- lastEntry = new Indexed<>(nextIndex, entry, length);
- this.index.index(nextIndex, position);
- nextIndex++;
- } else {
- break;
- }
-
- // Update the current position for indexing.
- position = buffer.position() + length;
- buffer.position(position);
-
- buffer.mark();
- length = buffer.getInt();
- }
-
- // Reset the buffer to the previous mark.
- buffer.reset();
- } catch (BufferUnderflowException e) {
- buffer.reset();
+ return channel.map(FileChannel.MapMode.READ_WRITE, 0, maxSegmentSize);
+ } catch (IOException e) {
+ throw new StorageException(e);