public boolean fillIfLive ( long timeout ) throws IOException { StreamImpl source = _source ; byte [ ] readBuffer = _readBuffer ; if ( readBuffer == null || source == null ) { _readOffset = 0 ; _readLength = 0 ; return false ; } if ( _readOffset > 0 ) { System . arraycopy ( readBuffer , _readOffset , readBuffer , 0 , _readLength - _readOffset ) ; _readLength -= _readOffset ; _readOffset = 0 ; } if ( _readLength == readBuffer . length ) return true ; int readLength = source . readTimeout ( _readBuffer , _readLength , _readBuffer . length - _readLength , timeout ) ; if ( readLength >= 0 ) { _readLength += readLength ; _position += readLength ; if ( _isEnableReadTime ) _readTime = CurrentTime . currentTime ( ) ; return true ; } else if ( readLength == READ_TIMEOUT ) { // timeout return true ; } else { // return false on end of file return false ; } }
Fills the buffer with a timed read testing for the end of file . Used for cases like comet to test if the read stream has closed .