01: /*
02: * ========================================================================
03: *
04: * Copyright 2001-2003 The Apache Software Foundation.
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: *
18: * ========================================================================
19: */
20: package org.apache.cactus.sample.servlet.util;
21:
22: import java.io.DataOutputStream;
23: import java.io.IOException;
24: import java.io.OutputStream;
25:
26: import javax.servlet.ServletOutputStream;
27:
28: /**
29: * Helper class to help write filters that manipulates the output stream. This
30: * is because normally, the <code>ServletOutputStream</code> cannot be
31: * modified after a resource has committed it.
32: *
33: * Note: This code was adapted from the Filter tutorial found
34: * {@link <a href="http://www.orionserver.com/tutorials/filters/lesson3/">
35: * here</a>}
36: *
37: * @version $Id: FilterServletOutputStream.java 238816 2004-02-29 16:36:46Z vmassol $
38: *
39: * @see GenericResponseWrapper
40: */
41: public class FilterServletOutputStream extends ServletOutputStream {
42: /**
43: * The stream where all the data will get written to
44: */
45: private DataOutputStream stream;
46:
47: /**
48: * Constructor.
49: *
50: * @param theOutput the output stream that we wrap in a
51: * <code>DataOutputStream</code> in order to hold the data
52: */
53: public FilterServletOutputStream(OutputStream theOutput) {
54: stream = new DataOutputStream(theOutput);
55: }
56:
57: // Overriden methods from ServletOutputStream ----------------------------
58:
59: /**
60: * @see ServletOutputStream#write(int)
61: */
62: public void write(int theData) throws IOException {
63: stream.write(theData);
64: }
65:
66: /**
67: * @see ServletOutputStream#write(byte[])
68: */
69: public void write(byte[] theData) throws IOException {
70: stream.write(theData);
71: }
72:
73: /**
74: * @see ServletOutputStream#write(byte[], int, int)
75: */
76: public void write(byte[] theData, int theOffset, int theLength)
77: throws IOException {
78: stream.write(theData, theOffset, theLength);
79: }
80: }
|