Hi,

for whatever reason the flush method in
org.apache.tomcat.core.BufferedServletOutput verifies whether
the boolean variable usingWriter is set. If not, it calls
reallyFlush, which actually works. If the variable is set,
however, nothing happens.

In other words: The flush method is completely useless in
conjunction with a Writer. The problem can be demonstrated
with the following simple servlet.

I don't know the reason for the usingWriter variable. However,
if noone else gives me a reason, I would strongly recommend
to change

    public void flush() throws IOException {
        if (this.usingWriter == false)
            reallyFlush();
    }

to

    public void flush() throws IOException {
        reallyFlush();
    }

Thanks,

Jochen




public class FlushServlet extends javax.servlet.http.HttpServlet {
  public FlushServlet() {
  }

  public void doGet(javax.servlet.http.HttpServletRequest pReq,
                    javax.servlet.http.HttpServletResponse pRes)
      throws java.io.IOException, javax.servlet.ServletException {
    String mode = pReq.getParameter("mode");
    pRes.setContentType("text/plain");
    java.io.PrintWriter w = pRes.getWriter();
    for (int i = 0;  i < 6;  i++) {
      w.println("Line " + i);
      w.flush();
      try {
        Thread.sleep(10*1000);
      } catch (InterruptedException e) {
      }
    }
    w.println("Line " + 6);
  }
}

Reply via email to