Commits

chri...@81dbac14-341a-0410-aa85-cbcd92e6f43e  committed 10daaff

Fix for [CACHE-52], supplied by Wolfgang Schr�der

  • Participants
  • Parent commits 97a3593

Comments (0)

Files changed (1)

File src/core/java/com/opensymphony/oscache/web/filter/CacheHttpServletResponseWrapper.java

  */
 public class CacheHttpServletResponseWrapper extends HttpServletResponseWrapper {
     private final Log log = LogFactory.getLog(this.getClass());
+
+    /**
+     * We cache the printWriter so we can maintain a single instance
+     * of it no matter how many times it is requested.
+     */
+    private PrintWriter cachedWriter;
     private ResponseContent result = null;
     private SplitServletOutputStream cacheOut = null;
     private int status = SC_OK;
      * @throws IOException
      */
     public ServletOutputStream getOutputStream() throws IOException {
-        //Pass this faked servlet output stream that captures what is sent
+        // Pass this faked servlet output stream that captures what is sent
         if (cacheOut == null) {
             cacheOut = new SplitServletOutputStream(result.getOutputStream(), super.getOutputStream());
         }
      * @throws IOException
      */
     public PrintWriter getWriter() throws IOException {
-        return new PrintWriter(getOutputStream());
+        if (cachedWriter == null) {
+            cachedWriter = new PrintWriter(getOutputStream());
+        }
+
+        return cachedWriter;
+    }
+
+    public void flushBuffer() throws IOException {
+        super.flushBuffer();
+
+        if (cacheOut != null) {
+            cacheOut.flush();
+        }
+
+        if (cachedWriter != null) {
+            cachedWriter.flush();
+        }
     }
 }