com.opensymphony.module.sitemesh.filter
Class PageOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by javax.servlet.ServletOutputStream
          extended by com.opensymphony.module.sitemesh.filter.PageOutputStream
All Implemented Interfaces:
OutputBuffer, Closeable, Flushable

public class PageOutputStream
extends ServletOutputStream
implements OutputBuffer

Implementation of ServletOutputStream that stores all data written to it in a temporary buffer accessible from getBuffer(java.lang.String) .

Version:
$Revision: 1.4 $
Author:
Scott Farquhar, Hani Suleiman

Field Summary
private  ByteArrayOutputStream buffer
           
private static String DEFAULT_ENCODING
           
private static boolean JDK14
           
private  ServletResponse response
          The reason we use a response, rather than just getting the outputstream directly is that under Tomcat, when serving static resources, we need to avoid calling getOutputStream() if we are going to use a decorator.
private  OutputStream target
           
 
Constructor Summary
PageOutputStream(ServletResponse response)
          Construct an OutputStream that will buffer the content written to it.
 
Method Summary
 void discardBuffer()
           
 void flush()
           
 char[] get14Buffer(String encoding)
           
 char[] getBuffer(String encoding)
           
private static char[] trim(char[] ca, int len)
           
 void write(int b)
           
 
Methods inherited from class javax.servlet.ServletOutputStream
print, print, print, print, print, print, print, println, println, println, println, println, println, println, println
 
Methods inherited from class java.io.OutputStream
close, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buffer

private ByteArrayOutputStream buffer

target

private OutputStream target

DEFAULT_ENCODING

private static final String DEFAULT_ENCODING

JDK14

private static final boolean JDK14

response

private final ServletResponse response
The reason we use a response, rather than just getting the outputstream directly is that under Tomcat, when serving static resources, we need to avoid calling getOutputStream() if we are going to use a decorator.

More information: http://marc.theaimsgroup.com/?l=tomcat-user&m=107569601410973&w=2, SIM-74, SIM-82

Constructor Detail

PageOutputStream

public PageOutputStream(ServletResponse response)
Construct an OutputStream that will buffer the content written to it.

Method Detail

write

public void write(int b)
           throws IOException
Specified by:
write in class OutputStream
Throws:
IOException

discardBuffer

public void discardBuffer()
Specified by:
discardBuffer in interface OutputBuffer

get14Buffer

public char[] get14Buffer(String encoding)

trim

private static char[] trim(char[] ca,
                           int len)

getBuffer

public char[] getBuffer(String encoding)
Specified by:
getBuffer in interface OutputBuffer
Parameters:
encoding - The encoding to use for decoding the buffer

flush

public void flush()
Specified by:
flush in interface OutputBuffer
Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream

www.opensymphony.com/sitemesh/