static JpegInputStream[] splitByRstMarkers(final int[] scanPayload) {
        final List<Integer> intervalStarts = getIntervalStartPositions(scanPayload);
        // get number of intervals in payload to init an array of appropriate length
        final int intervalCount = intervalStarts.size();
        final JpegInputStream[] streams = Allocator.array(intervalCount, JpegInputStream[]::new, JpegInputStream.SHALLOW_SIZE);
        for (int i = 0; i < intervalCount; i++) {
            final int from = intervalStarts.get(i);
            final int to;
            if (i < intervalCount - 1) {
                // because each restart marker needs two bytes the end of
                // this interval is two bytes before the next interval starts
                to = intervalStarts.get(i + 1) - 2;
            } else { // the last interval ends with the array
                to = scanPayload.length;
            }
            final int[] interval = Arrays.copyOfRange(scanPayload, from, to);
            streams[i] = new JpegInputStream(interval);
        }
        return streams;
    }
Returns an array of JpegInputStream where each field contains the JpegInputStream for one interval.

@param scanPayload array to read intervals from
@return JpegInputStreams for all intervals, at least one stream is always provided
src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java