private int search ( int startLine , boolean backward ) throws IOException { search = search . toLowerCase ( ) ; try ( Stream < String > stream = Files . lines ( path ) ) { if ( backward ) { int idx = - 1 ; if ( startLine > 0 ) idx = searchTo ( startLine - 1 , true ) ; if ( idx < 0 ) idx = searchFrom ( startLine , true ) ; return idx ; } else { int idx = searchFrom ( startLine ) ; if ( idx < 0 ) { // wrap search idx = searchTo ( startLine - 1 ) ; } return idx ; } } catch ( UncheckedIOException ex ) { throw ex . getCause ( ) ; } }
Search pass locates line index of first match .