You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2005/07/29 00:43:33 UTC

svn commit: r226272 - /cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/AbstractEnvironment.java

Author: vgritsenko
Date: Thu Jul 28 15:43:30 2005
New Revision: 226272

URL: http://svn.apache.org/viewcvs?rev=226272&view=rev
Log:
fix bug in output stream handling.
exposed by r179249, could be seen in errorhandler samples.

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/AbstractEnvironment.java

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/AbstractEnvironment.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/AbstractEnvironment.java?rev=226272&r1=226271&r2=226272&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/AbstractEnvironment.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/AbstractEnvironment.java Thu Jul 28 15:43:30 2005
@@ -450,7 +450,7 @@
     public void setAttribute(String name, Object value) {
         this.attributes.put(name, value);
     }
-    
+
     protected boolean hasAttribute(String name) {
         return this.attributes.containsKey(name);
     }
@@ -479,18 +479,29 @@
      * The returned stream is buffered by the environment. If the
      * buffer size is -1 then the complete output is buffered.
      * If the buffer size is 0, no buffering takes place.
-     * This method replaces {@link #getOutputStream()}.
+     *
+     * <br>This method replaces {@link #getOutputStream()}.
      */
     public OutputStream getOutputStream(int bufferSize)
     throws IOException {
+
+        // This method could be called several times during request processing
+        // with differing values of bufferSize and should handle this situation
+        // correctly.
+
         if (bufferSize == -1) {
             if (this.secureOutputStream == null) {
                 this.secureOutputStream = new BufferedOutputStream(this.outputStream);
             }
             return this.secureOutputStream;
         } else if (bufferSize == 0) {
+            // Discard secure output stream if it was created before.
+            if (this.secureOutputStream != null) {
+                this.secureOutputStream = null;
+            }
             return this.outputStream;
         } else {
+            // FIXME Triple buffering, anyone?
             this.outputStream = new java.io.BufferedOutputStream(this.outputStream, bufferSize);
             return this.outputStream;
         }