boolean spinUntilBytesAvailable ( long waitTimeMicroSec ) { long start = System . nanoTime ( ) ; while ( availableBytes ( ) < 1 ) { long delta = System . nanoTime ( ) - start ; if ( delta > waitTimeMicroSec * 1000 ) { return false ; } } return true ; }
Spins until the timeout or the condition is met . This method will repeatedly poll the available bytes so it should not have any side effects .