@ Override protected int require ( int required ) throws KryoException { if ( required > capacity ) { throw new KryoException ( "Buffer too small: capacity: " + capacity + ", " + "required: " + required ) ; } position = 0 ; int bytesRead = 0 ; int count ; while ( true ) { count = fill ( buffer , bytesRead , required - bytesRead ) ; if ( count == - 1 ) { throw new KryoException ( new EOFException ( "No more bytes left." ) ) ; } bytesRead += count ; if ( bytesRead == required ) { break ; } } limit = required ; return required ; }
Require makes sure that at least required number of bytes are kept in the buffer . If not then it will load exactly the difference between required and currently available number of bytes . Thus it will only load the data which is required and never prefetch data .