public boolean isResponseAvailable ( int timeout ) throws IOException { LOG . trace ( "enter HttpConnection.isResponseAvailable(int)" ) ; if ( ! this . isOpen ) { return false ; } boolean result = false ; if ( this . inputStream . available ( ) > 0 ) { result = true ; } else { try { this . socket . setSoTimeout ( timeout ) ; inputStream . mark ( 1 ) ; int byteRead = inputStream . read ( ) ; if ( byteRead != - 1 ) { inputStream . reset ( ) ; LOG . debug ( "Input data available" ) ; result = true ; } else { LOG . debug ( "Input data not available" ) ; } } catch ( InterruptedIOException e ) { if ( ! ExceptionUtil . isSocketTimeoutException ( e ) ) { throw e ; } if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Input data not available after " + timeout + " ms" ) ; } } finally { try { socket . setSoTimeout ( this . params . getSoTimeout ( ) ) ; } catch ( IOException ioe ) { LOG . debug ( "An error ocurred while resetting soTimeout, we will assume that" + " no response is available." , ioe ) ; result = false ; } } } return result ; }
Tests if input data becomes available within the given period time in milliseconds .