public int read ( char [ ] buf , int off , int len ) throws IOException { // do not claim if len == 0 if ( len == 0 ) { return 0 ; } // init lookahead, but do not block !! if ( lookaheadChar == UNDEFINED ) { if ( ready ( ) ) { lookaheadChar = super . read ( ) ; } else { return - 1 ; } } // 'first read of underlying stream' if ( lookaheadChar == - 1 ) { return - 1 ; } // continue until the lookaheadChar would block int cOff = off ; while ( len > 0 && ready ( ) ) { if ( lookaheadChar == - 1 ) { // eof stream reached, do not continue return cOff - off ; } else { buf [ cOff ++ ] = ( char ) lookaheadChar ; if ( lookaheadChar == ' ' ) { lineCounter ++ ; } lastChar = lookaheadChar ; lookaheadChar = super . read ( ) ; len -- ; } } return cOff - off ; }
Non - blocking reading of len chars into buffer buf starting at bufferposition off .