public int getMaxAvailableFrame ( ) { if ( maxAvailableFrame == - 1 ) { int firstPoint = 0 ; for ( int i = MAX_MAX ; i > 0 ; i /= 2 ) { if ( new File ( String . format ( namePattern , i ) ) . exists ( ) ) { firstPoint = i ; break ; } } int pos = firstPoint ; for ( int interv = firstPoint / 2 ; interv > 1 ; interv /= 2 ) { if ( new File ( String . format ( namePattern , pos + interv ) ) . exists ( ) ) { pos += interv ; } } maxAvailableFrame = pos ; Logger . info ( "Max frame found: " + maxAvailableFrame ) ; } return Math . min ( maxAvailableFrame , maxFrames ) ; }
Finds maximum frame of a sequence by bisecting the range .