public boolean hasNext() throws IOException {
        if (nextEntrySize >= 0) {
            return true;
        }
        if (done || fileOffset >= fileSize) {
            return false;
        }
        int entrySize;
        if (buffer.remaining() <= 4) {
            buffer.clear();
            int toRead = (int) Math.min(fileSize - fileOffset, buffer.capacity());
            if (toRead < 4) {
                // File corruption.
                done = true;
                return false;
            }
            buffer.limit(toRead);
            IOUtil.readFully(file, fileOffset, buffer);
            buffer.flip();
        }
        entrySize = buffer.getInt();
        if (entrySize > buffer.remaining()) {
            if (entrySize + 4 > buffer.capacity()) {
                // buffer too small.
                ByteBufferUtil.free(buffer);
                buffer = ByteBufferUtil.allocateDirect(entrySize << 1);
            } else {
                buffer.clear();
            }
            int toRead = (int) Math.min(fileSize - fileOffset, buffer.capacity());
            if (toRead < entrySize + 4) {
                // File corruption.
                done = true;
                return false;
            }
            buffer.limit(toRead);
            IOUtil.readFully(file, fileOffset, buffer);
            buffer.flip();

            // move 4 bytes forward.
            int es = buffer.getInt();
            assert entrySize == es;
        }

        fileOffset += 4 + entrySize;
        nextEntrySize = entrySize;
        return true;
    }
Load data from file which stored in format: [size][data][size][data]....
indexr-common/src/main/java/io/indexr/util/ObjectLoader.java