What’s the difference between calling :
res.flushBuffer();
versus
res.getOutputStream().flush();
Do these methods flush the same buffer ?
If so, can you give me a clue on how this buffer is managed by the servlet container?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
They would flush the same buffer if you have been using
getOutputStreamto write to the body. The other alternative isgetWriterfor non-binary data. If you had been using that, then callingres.getOutputStream().flush();probably wouldn’t work.The way the buffer is managed is implementation-specific but take one of the Tomcat implementations for example. You can see that there are some fields like this:
Calling
getOutputStream()creates aCoyoteOutputStreamthat uses theoutputBufferfield that is shown there and likewise forgetWriter(). So they both would use thatoutputBufferdepending on which you use.flushBuffersimply does this: