Code example for InputStream

Methods: available, mark

0
        if (! (socket.isClosed() || socket.isInputShutdown()
                        || socket.isOutputShutdown())) {
            // the socket is open, but could still have been closed from the other end 
            isStale = false;
            try { 
                if (inputStream.available() <= 0) {
                    int soTimeout = socket.getSoTimeout();
                    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(soTimeout);
                    }