FileDocCategorySizeDatePackage
CacheResponseWrapper.javaAPI DocExample3006Sun Nov 23 17:43:50 GMT 2003cfexample.controller

CacheResponseWrapper

public class CacheResponseWrapper extends HttpServletResponseWrapper
A class to wrap a normal ServletResponse so that the result can be cached.

Fields Summary
private CacheOutputStream
outStream
the caching stream
private ServletOutputStream
stream
the replacement output stream and writer
private PrintWriter
writer
Constructors Summary
public CacheResponseWrapper(HttpServletResponse original)
Constructor

        super(original);
    
Methods Summary
protected javax.servlet.ServletOutputStreamcreateOutputStream()
Create an instance of a CacheOutputStream to use

        outStream = new CacheOutputStream();
        return outStream;
    
protected byte[]getBytes()
Get the cached data from this stream

        if (outStream != null) {
            return outStream.getBytes();
        }
        
        return null;
    
public javax.servlet.ServletOutputStreamgetOutputStream()
Get the replacement output stream

        if (stream != null) {
            return stream;
        }
        
        // make sure writer has not already been initialized
        if (writer != null) {
            throw new IOException("Writer already in use");
        }
        
        stream = createOutputStream();
        return stream;
    
public java.io.PrintWritergetWriter()
Get the replacement writer

        if (writer != null) {
            return writer;
        }
        
        // make sure output stream has not already been initialized
        if (stream != null) {
            throw new IOException("OutputStream already in use");
        }
        
        writer = new PrintWriter(new OutputStreamWriter(createOutputStream()));
        return writer;