public long skip()

in cassandra-four-zero/src/main/java/org/apache/cassandra/spark/reader/CompressedRawInputStream.java [231:285]


    public long skip(long count) throws IOException
    {
        long precheck = maybeStandardSkip(count);
        if (precheck >= 0)
        {
            return precheck;
        }

        // Skip any buffered bytes
        long remaining = count - skipBuffered();

        // We can efficiently skip ahead by 0 or more whole compressed chunks by passing down to the source InputStream
        long totalCompressedBytes = 0L;
        long totalDecompressedBytes = 0L;
        long startCurrent = current;
        long startCompressed = currentCompressed;
        long startBufferOffset = bufferOffset;
        while (totalDecompressedBytes + buffer.length < remaining)  // We can only skip whole chunks
        {
            AbstractCompressionMetadata.Chunk chunk = metadata.chunkAtPosition(current);
            if (chunk.length < 0)
            {
                // For the last chunk we don't know the length so reset positions & skip as normal
                current = startCurrent;
                currentCompressed = startCompressed;
                bufferOffset = startBufferOffset;
                return standardSkip(remaining);
            }

            assertChunkPos(chunk);

            // Sum total compressed & decompressed bytes we can skip
            int chunkLength = chunk.length + checksumBytes.length;
            totalCompressedBytes += (int) (chunk.offset - currentCompressed);
            currentCompressed = chunk.offset;
            totalCompressedBytes += chunkLength;
            currentCompressed += chunkLength;
            totalDecompressedBytes += buffer.length;

            alignBufferOffset();
            current += buffer.length;
        }

        // Skip compressed chunks at the source
        long skipped = source.skip(totalCompressedBytes);
        assert skipped == totalCompressedBytes : "Bytes skipped should equal compressed length";
        remaining -= totalDecompressedBytes;  // Decrement decompressed bytes we have skipped

        // Skip any remaining bytes as normal
        remaining -= standardSkip(remaining);

        long total = count - remaining;
        stats.skippedBytes(total);
        return total;
    }