KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > filters > cache > CacheResponseStream


1 /*
2  * $$Id: CacheResponseStream.java,v 1.3 2005/06/07 12:32:31 bel70 Exp $$
3  *
4  * ***** BEGIN LICENSE BLOCK ***** The contents of this file are subject to the
5  * Mozilla Public License Version 1.1 (the "License"); you may not use this file
6  * except in compliance with the License. You may obtain a copy of the License
7  * at http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
11  * the specific language governing rights and limitations under the License.
12  *
13  * The Original Code is JGossip forum code.
14  *
15  * The Initial Developer of the Original Code is the JResearch, Org. Portions
16  * created by the Initial Developer are Copyright (C) 2004 the Initial
17  * Developer. All Rights Reserved.
18  *
19  * Contributor(s): Dmitry Belov <bel@jresearch.org>, Jayson Falkner
20  * <jayson@jspinsider.com>
21  *
22  * ***** END LICENSE BLOCK *****
23  */

24 package org.jresearch.gossip.filters.cache;
25
26 import java.io.IOException JavaDoc;
27 import java.io.OutputStream JavaDoc;
28
29 import javax.servlet.ServletOutputStream JavaDoc;
30 import javax.servlet.http.HttpServletResponse JavaDoc;
31
32 public class CacheResponseStream extends ServletOutputStream JavaDoc {
33
34     protected boolean closed = false;
35
36     protected HttpServletResponse JavaDoc response = null;
37
38     protected ServletOutputStream JavaDoc output = null;
39
40     protected OutputStream JavaDoc cache = null;
41
42     public CacheResponseStream(HttpServletResponse JavaDoc response, OutputStream JavaDoc cache)
43             throws IOException JavaDoc {
44         super();
45         closed = false;
46         this.response = response;
47         this.cache = cache;
48     }
49
50     public void close() throws IOException JavaDoc {
51         if (closed) {
52             throw new IOException JavaDoc("This output stream has already been closed");
53         }
54         cache.close();
55         closed = true;
56     }
57
58     public void flush() throws IOException JavaDoc {
59         if (closed) {
60             throw new IOException JavaDoc("Cannot flush a closed output stream");
61         }
62         cache.flush();
63     }
64
65     public void write(int b) throws IOException JavaDoc {
66         if (closed) {
67             throw new IOException JavaDoc("Cannot write to a closed output stream");
68         }
69         cache.write((byte) b);
70     }
71
72     public void write(byte b[]) throws IOException JavaDoc {
73         write(b, 0, b.length);
74     }
75
76     public void write(byte b[], int off, int len) throws IOException JavaDoc {
77         if (closed) {
78             throw new IOException JavaDoc("Cannot write to a closed output stream");
79         }
80         cache.write(b, off, len);
81     }
82
83     public boolean closed() {
84         return (this.closed);
85     }
86
87     public void reset() {
88         // noop
89
}
90 }
Popular Tags