public static List<JPEGSegment> readSegments(final ImageInputStream stream, final Map<Integer, List<String>> segmentIdentifiers) throws IOException {
        readSOI(notNull(stream, "stream"));

        List<JPEGSegment> segments = Collections.emptyList();

        JPEGSegment segment;
        try {
            do {
                segment = readSegment(stream, segmentIdentifiers);
//                System.err.println("segment: " + segment);

                if (isRequested(segment, segmentIdentifiers)) {
                    if (segments == Collections.EMPTY_LIST) {
                        segments = new ArrayList<>();
                    }

                    segments.add(segment);
                }
            }
            while (!isImageDone(segment));
        }
        catch (EOFException ignore) {
            // Just end here, in case of malformed stream
        }

        // TODO: Should probably skip until EOI, so that multiple invocations succeeds for multiple image streams.

        return segments;
    }
public static List < JPEGSegment > readSegments ( final ImageInputStream stream , final Map < Integer , List < String > > segmentIdentifiers ) throws IOException { readSOI ( notNull ( stream , "stream" ) ) ; List < JPEGSegment > segments = Collections . emptyList ( ) ; JPEGSegment segment ; try { do { segment = readSegment ( stream , segmentIdentifiers ) ; if ( isRequested ( segment , segmentIdentifiers ) ) { if ( segments == Collections . EMPTY_LIST ) { segments = new ArrayList < > ( ) ; } segments . add ( segment ) ; } } while ( ! isImageDone ( segment ) ) ; } catch ( EOFException ignore ) { } return segments ; }
Reads the requested JPEG segments from the stream.
The stream position must be directly before the SOI marker, and only segments for the current image is read.

@param stream the stream to read from.
@param segmentIdentifiers the segment identifiers
@return a list of segments with the given app markers and optional identifiers. If no segments are found, an
empty list is returned.
@throws IIOException if a JPEG format exception occurs during reading
@throws IOException if an I/O exception occurs during reading

@see #ALL_SEGMENTS
@see #APP_SEGMENTS
@see #ALL_IDS