You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by ov...@apache.org on 2002/09/24 10:46:35 UTC
cvs commit: xml-cocoon2/src/java/org/apache/cocoon/environment/wrapper EnvironmentWrapper.java
ovidiu 2002/09/24 01:46:35
Modified: src/java/org/apache/cocoon/environment/wrapper
EnvironmentWrapper.java
Log:
Implement getOutputStream(int), tryResetResponse() and
commitResponse() to make things work correctly in the presence of
control flow.
Revision Changes Path
1.21 +44 -2 xml-cocoon2/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java
Index: EnvironmentWrapper.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- EnvironmentWrapper.java 8 Aug 2002 02:10:40 -0000 1.20
+++ EnvironmentWrapper.java 24 Sep 2002 08:46:35 -0000 1.21
@@ -60,6 +60,7 @@
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.util.BufferedOutputStream;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import java.io.IOException;
@@ -215,15 +216,56 @@
*/
public OutputStream getOutputStream()
throws IOException {
- return (this.outputStream == null) ? this.environment.getOutputStream() : this.outputStream;
+ return this.outputStream == null
+ ? this.environment.getOutputStream()
+ : this.outputStream;
}
+ public OutputStream getOutputStream(int bufferSize)
+ throws IOException
+ {
+ return this.outputStream == null
+ ? this.environment.getOutputStream()
+ : this.outputStream;
+ }
+
/**
* Set the output stream for this environment. It hides the one of the
* wrapped environment.
*/
public void setOutputStream(OutputStream stream) {
this.outputStream = stream;
+ }
+
+ /**
+ * Reset the response if possible. This allows error handlers to have
+ * a higher chance to produce clean output if the pipeline that raised
+ * the error has already output some data.
+ *
+ * @return true if the response was successfully reset
+ */
+ public boolean tryResetResponse()
+ throws IOException {
+ if (getOutputStream() != null
+ && getOutputStream() instanceof BufferedOutputStream) {
+ ((BufferedOutputStream)getOutputStream()).clearBuffer();
+ return true;
+ }
+ else
+ return super.tryResetResponse();
+ }
+
+ /**
+ * Commit the response
+ */
+ public void commitResponse()
+ throws IOException {
+ if (getOutputStream() != null
+ && getOutputStream() instanceof BufferedOutputStream) {
+ ((BufferedOutputStream)getOutputStream()).realFlush();
+ }
+ else
+ super.commitResponse();
}
/**
----------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org