docs: @SuppressWarnings("unchecked")
    private void readNext() {
      // Compute the index of the next entry in the segment.
      final long index = getNextIndex();
  
      try {
        // Read more bytes from the segment if necessary.
        if (memory.remaining() < maxEntrySize) {
          long position = channel.position() + memory.position();
          channel.position(position);
          memory.clear();
          channel.read(memory);
          channel.position(position);
          memory.flip();
        }
  
        // Mark the buffer so it can be reset if necessary.
        memory.mark();
  
        try {
          // Read the length of the entry.
          final int length = memory.getInt();
  
          // If the buffer length is zero then return.
          if (length <= 0 || length > maxEntrySize) {
            memory.reset().limit(memory.position());
            nextEntry = null;
            return;
          }
  
          // Read the checksum of the entry.
          long checksum = memory.getInt() & 0xFFFFFFFFL;
  
          // Compute the checksum for the entry bytes.
          final Checksum crc32 = new CRC32();
          crc32.update(memory.array(), memory.position(), length);
  
          // If the stored checksum equals the computed checksum, return the entry.
          if (checksum == crc32.getValue()) {
            int limit = memory.limit();
            memory.limit(memory.position() + length);
            E entry = namespace.deserialize(memory);
            memory.limit(limit);
            nextEntry = new Indexed<>(index, entry, length);
          } else {
            memory.reset().limit(memory.position());
            nextEntry = null;
          }
        } catch (BufferUnderflowException e) {
          memory.reset().limit(memory.position());
          nextEntry = null;
        }
      } catch (IOException e) {
        throw new StorageException(e);
      }
    }