static Pair readPrimaryIndex()

in cassandra-four-zero/src/main/java/org/apache/cassandra/spark/reader/ReaderUtils.java [436:478]


    static Pair<ByteBuffer, ByteBuffer> readPrimaryIndex(@NotNull InputStream primaryIndex,
                                                         boolean readFirstLastKey,
                                                         @NotNull List<PartitionKeyFilter> filters) throws IOException
    {
        ByteBuffer firstKey = null;
        ByteBuffer lastKey = null;
        try (DataInputStream dis = new DataInputStream(primaryIndex))
        {
            byte[] last = null;
            try
            {
                while (true)
                {
                    int length = dis.readUnsignedShort();
                    byte[] buffer = new byte[length];
                    dis.readFully(buffer);
                    if (firstKey == null)
                    {
                        firstKey = ByteBuffer.wrap(buffer);
                    }
                    last = buffer;
                    ByteBuffer key = ByteBuffer.wrap(last);
                    if (!readFirstLastKey && filters.stream().anyMatch(filter -> filter.filter(key)))
                    {
                        return Pair.create(null, null);
                    }

                    // Read position and skip promoted index
                    skipRowIndexEntry(dis);
                }
            }
            catch (EOFException ignored)
            {
            }

            if (last != null)
            {
                lastKey = ByteBuffer.wrap(last);
            }
        }

        return Pair.create(firstKey, lastKey);
    }