code: protected synchronized int available() throws IOException {
          if (isClosedOrPending()) {
              throw new IOException("Stream closed.");
          }
  
          /*
           * If connection has been reset then return 0 to indicate
           * there are no buffered bytes.
           */
          if (isConnectionReset()) {
              return 0;
          }
  
          /*
           * If no bytes available and we were previously notified
           * of a connection reset then we move to the reset state.
           *
           * If are notified of a connection reset then check
           * again if there are bytes buffered on the socket.
           */
          int n = 0;
          try {
              n = socketAvailable();
              if (n == 0 && isConnectionResetPending()) {
                  setConnectionReset();
              }
          } catch (ConnectionResetException exc1) {
              setConnectionResetPending();
              try {
                  n = socketAvailable();
                  if (n == 0) {
                      setConnectionReset();
                  }
              } catch (ConnectionResetException exc2) {
              }
          }
          return n;
      }
docs: Returns the number of bytes that can be read without blocking.