01: /*
02: * MeshCMS - A simple CMS based on SiteMesh
03: * Copyright (C) 2004-2007 Luciano Vernaschi
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * as published by the Free Software Foundation; either version 2
08: * of the License, or (at your option) any later version.
09: *
10: * This program is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: * GNU General Public License for more details.
14: *
15: * You should have received a copy of the GNU General Public License
16: * along with this program; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18: *
19: * You can contact the author at http://www.cromoteca.com
20: * and at info@cromoteca.com
21: */
22:
23: package org.meshcms.core;
24:
25: import java.io.*;
26: import javax.servlet.*;
27: import javax.servlet.http.*;
28:
29: /**
30: * Writes the page to both the browser and the cache.
31: *
32: * @see CacheResponseWrapper
33: */
34: public class CacheResponseStream extends ServletOutputStream {
35: ServletOutputStream output;
36: OutputStream cacheOutput;
37:
38: /**
39: * Creates a new Stream to write to the original output stream of the response
40: * and to the passed output stream.
41: *
42: * @param response the original response
43: * @param cacheOutput the output for the cache
44: *
45: * @throws IOException if an input or output exception occurred
46: */
47: public CacheResponseStream(HttpServletResponse response,
48: OutputStream cacheOutput) throws IOException {
49: super ();
50: this .cacheOutput = cacheOutput;
51: output = response.getOutputStream();
52: }
53:
54: /**
55: * Writes to both streams.
56: *
57: * @param b the byte to write
58: * @throws IOException if an I/O error occurs
59: */
60: public void write(int b) throws IOException {
61: output.write(b);
62:
63: try {
64: cacheOutput.write(b);
65: } catch (IOException ex) {
66: }
67: }
68:
69: /**
70: * Flushes both streams.
71: *
72: * @throws IOException if an I/O error occurs
73: */
74: public void flush() throws IOException {
75: output.flush();
76:
77: try {
78: cacheOutput.flush();
79: } catch (IOException ex) {
80: }
81: }
82:
83: /**
84: * Closes both streams.
85: *
86: * @throws IOException if an I/O error occurs
87: */
88: public void close() throws IOException {
89: output.close();
90:
91: try {
92: cacheOutput.close();
93: } catch (IOException ex) {
94: }
95: }
96: }
|