public void onNext()

in src/main/java/software/amazon/encryption/s3/legacy/internal/AdjustedRangeSubscriber.java [57:89]


    public void onNext(ByteBuffer byteBuffer) {
        if (virtualAvailable <= 0) {
            wrappedSubscriber.onComplete();
        }

        if (numBytesToSkip != 0) {
            byte[] buf = byteBuffer.array();
            if (numBytesToSkip > buf.length) {
                // If we need to skip past the available data,
                // we are returning nothing, so signal completion
                numBytesToSkip -= buf.length;
                wrappedSubscriber.onComplete();
            } else {
                outputBuffer = Arrays.copyOfRange(buf, numBytesToSkip, buf.length);
                numBytesToSkip = 0;
            }
        } else {
            outputBuffer = byteBuffer.array();
        }

        if (virtualAvailable > 0) {
            long bytesToRead = Math.min(virtualAvailable, outputBuffer.length);
            virtualAvailable -= bytesToRead;
            wrappedSubscriber.onNext(ByteBuffer.wrap(outputBuffer, 0, Math.toIntExact(bytesToRead)));
        }

        // Since we are skipping some bytes, we may need to signal onComplete
        // from within onNext to prevent the subscriber from waiting for more
        // data indefinitely
        if (virtualAvailable <= 0) {
            wrappedSubscriber.onComplete();
        }
    }