protected boolean isStale ( ) throws IOException { boolean isStale = true ; if ( isOpen ) { // the connection is open, but now we have to see if we can read it // assume the connection is not stale. isStale = false ; try { if ( inputStream . available ( ) <= 0 ) { try { socket . setSoTimeout ( 1 ) ; inputStream . mark ( 1 ) ; int byteRead = inputStream . read ( ) ; if ( byteRead == - 1 ) { // again - if the socket is reporting all data read, // probably stale isStale = true ; } else { inputStream . reset ( ) ; } } finally { socket . setSoTimeout ( this . params . getSoTimeout ( ) ) ; } } } catch ( InterruptedIOException e ) { if ( ! ExceptionUtil . isSocketTimeoutException ( e ) ) { throw e ; } // aha - the connection is NOT stale - continue on! } catch ( IOException e ) { // oops - the connection is stale, the read or soTimeout failed. LOG . debug ( "An error occurred while reading from the socket, is appears to be stale" , e ) ; isStale = true ; } } return isStale ; }
Determines whether this connection is stale which is to say that either it is no longer open or an attempt to read the connection would fail .