public static boolean moveToMarker ( InputStream is , int markerToFind ) throws IOException { Preconditions . checkNotNull ( is ) ; // ISO/IEC 10918-1:1993(E) while ( StreamProcessor . readPackedInt ( is , 1 , false ) == MARKER_FIRST_BYTE ) { int marker = MARKER_FIRST_BYTE ; while ( marker == MARKER_FIRST_BYTE ) { marker = StreamProcessor . readPackedInt ( is , 1 , false ) ; } if ( markerToFind == MARKER_SOFn && isSOFn ( marker ) ) { return true ; } if ( marker == markerToFind ) { return true ; } // Check if the marker is SOI or TEM. These two don't have length field, so we skip it. if ( marker == MARKER_SOI || marker == MARKER_TEM ) { continue ; } // Check if the marker is EOI or SOS. We will stop reading since metadata markers don't // come after these two markers. if ( marker == MARKER_EOI || marker == MARKER_SOS ) { return false ; } // read block length // subtract 2 as length contain SIZE field we just read int length = StreamProcessor . readPackedInt ( is , 2 , false ) - 2 ; // Skip other markers. is . skip ( length ) ; } return false ; }
Reads the content of the input stream until specified marker is found . Marker will be consumed and the input stream will be positioned after the specified marker .