From: remm Date: Mon, 30 Apr 2007 23:36:10 +0000 (+0000) Subject: - New read loop (much more conventional using the more accurate InputStream.available... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=2911d66a61adbaaf67a6e059b57fdf2e847271fd;p=tomcat7.0 - New read loop (much more conventional using the more accurate InputStream.available() method). git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@533881 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/webapps/examples/WEB-INF/classes/chat/ChatServlet.java b/webapps/examples/WEB-INF/classes/chat/ChatServlet.java index f27c3c074..a306beda3 100644 --- a/webapps/examples/WEB-INF/classes/chat/ChatServlet.java +++ b/webapps/examples/WEB-INF/classes/chat/ChatServlet.java @@ -149,16 +149,18 @@ public class ChatServlet throws IOException, ServletException { InputStream is = request.getInputStream(); byte[] buf = new byte[512]; - do { + while (is.available() > 0) { + log("Available: " + is.available()); int n = is.read(buf); if (n > 0) { log("Read " + n + " bytes: " + new String(buf, 0, n) + " for session: " + request.getSession(true).getId()); } else if (n < 0) { - error(event, request, response); + log("End of file: " + n); + end(event, request, response); return; } - } while (is.available() > 0); + } } protected void service(HttpServletRequest request, HttpServletResponse response)