01: /* Copyright 2004 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.channels.portlet;
07:
08: import java.io.IOException;
09: import java.io.PrintWriter;
10:
11: import javax.servlet.http.HttpServletResponse;
12: import javax.servlet.http.HttpServletResponseWrapper;
13:
14: /**
15: * The portlet needs to be able to use a {@link javax.servlet.http.HttpServletResponse}
16: * that just uses the {@link javax.servlet.ServletOutputStream} as the backing
17: * for the {@link java.io.PrintWriter}.
18: * <br>
19: * When this class is constructed a {@link java.io.PrintWriter} is created
20: * and stored in a member variable and returned via {@link #getWriter()}
21: * calls. {@link #flushBuffer()} flushes the {@link java.io.PrintWriter}
22: * then calls the super {@link #flushBuffer()}.
23: *
24: * @author Eric Dalquist <a href="mailto:edalquist@unicon.net">edalquist@unicon.net</a>
25: * @version $Revision: 35320 $
26: */
27: public class OutputStreamResponseWrapper extends
28: HttpServletResponseWrapper {
29: final PrintWriter pw;
30:
31: /**
32: * Create a new wrapper for a {@link HttpServletResponse}, over-ridding
33: * the {@link PrintWriter}.
34: *
35: * @param response The {@link HttpServletResponse} to wrap.
36: * @throws IOException Possible from calling {@link HttpServletResponse#getOutputStream()}
37: */
38: public OutputStreamResponseWrapper(
39: final HttpServletResponse response) throws IOException {
40: super (response);
41: this .pw = new PrintWriter(this .getOutputStream());
42: }
43:
44: /**
45: * Flushes the local {@link java.io.PrintStream}, then calls the same
46: * method on the wrapped {@link HttpServletResponse}.
47: *
48: * @see javax.servlet.ServletResponse#flushBuffer()
49: */
50: public void flushBuffer() throws IOException {
51: this .pw.flush();
52: super .flushBuffer();
53: }
54:
55: /**
56: * Gets the {@link PrintWriter} that wraps the {@link javax.servlet.ServletOutputStream}
57: * for the wrapped {@link HttpServletResponse}.
58: *
59: * @see javax.servlet.ServletResponse#getWriter()
60: */
61: public PrintWriter getWriter() throws IOException {
62: return this.pw;
63: }
64: }
|