KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > core > util > SplitServletOutputStream


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package org.apache.roller.ui.core.util;
6
7 import java.io.IOException JavaDoc;
8 import java.io.OutputStream JavaDoc;
9
10 import javax.servlet.ServletOutputStream JavaDoc;
11
12 /**
13  * Extends the base <code>ServletOutputStream</code> class so that
14  * the stream can be captured as it gets written. This is achieved
15  * by overriding the <code>write()</code> methods and outputting
16  * the data to two streams - the original stream and a secondary stream
17  * that is designed to capture the written data.
18  *
19  * @version $Revision: 1.1 $
20  * @author <a HREF="mailto:sergek@lokitech.com">Serge Knystautas</a>
21  */

22 public class SplitServletOutputStream extends ServletOutputStream JavaDoc {
23     OutputStream JavaDoc captureStream = null;
24     OutputStream JavaDoc passThroughStream = null;
25
26     /**
27      * Constructs a split output stream that both captures and passes through
28      * the servlet response.
29      *
30      * @param captureStream The stream that will be used to capture the data.
31      * @param passThroughStream The pass-through <code>ServletOutputStream</code>
32      * that will write the response to the client as originally intended.
33      */

34     public SplitServletOutputStream(OutputStream JavaDoc captureStream, OutputStream JavaDoc passThroughStream) {
35         this.captureStream = captureStream;
36         this.passThroughStream = passThroughStream;
37     }
38
39     /**
40      * Writes the incoming data to both the output streams.
41      *
42      * @param value The int data to write.
43      * @throws IOException
44      */

45     public void write(int value) throws IOException JavaDoc {
46         captureStream.write(value);
47         passThroughStream.write(value);
48     }
49
50     /**
51      * Writes the incoming data to both the output streams.
52      *
53      * @param value The bytes to write to the streams.
54      * @throws IOException
55      */

56     public void write(byte[] value) throws IOException JavaDoc {
57         captureStream.write(value);
58         passThroughStream.write(value);
59     }
60
61     /**
62      * Writes the incoming data to both the output streams.
63      *
64      * @param b The bytes to write out to the streams.
65      * @param off The offset into the byte data where writing should begin.
66      * @param len The number of bytes to write.
67      * @throws IOException
68      */

69     public void write(byte[] b, int off, int len) throws IOException JavaDoc {
70         captureStream.write(b, off, len);
71         passThroughStream.write(b, off, len);
72     }
73 }
74
Popular Tags