Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ServletResponse#flushBuffer() cover?

If I call ServletResponse.flushBuffer(),

do I need to call ServletResponse.getOutputStream().close()

and/or ServletResponse.getOutputStream().flush()

(same for ServletResponse.getWriter().close()

and/or ServletResponse.getWriter().flush()) ?

like image 455
sp00m Avatar asked Mar 04 '13 16:03

sp00m


1 Answers

Both flush() and close() are completely different methods:

flush() ...

The flush() method is used to flush the buffered response to the client. It will also lead to commit the response headers.

By default Server container will automatically call this if the internal buffer is reached.

You should call explicitly if you want to send the response in custom chunks.

close() ...

The close() method is used to close the response stream such that no more data can be written.

By default Server container will automatically call this at the end of Servlet life cycle.

You should call explicitly if you do not want to allow writing response beyond any point. Attempting to do so will throw an IOException.

like image 119
Ramesh PVK Avatar answered Sep 27 '22 23:09

Ramesh PVK