KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > jsp > JSPEngineServletOutputStream


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.components.jsp;
17
18 import java.io.ByteArrayOutputStream JavaDoc;
19 import java.io.IOException JavaDoc;
20 import java.io.OutputStreamWriter JavaDoc;
21 import java.io.PrintWriter JavaDoc;
22 import java.io.UnsupportedEncodingException JavaDoc;
23
24 import javax.servlet.ServletOutputStream JavaDoc;
25
26 /**
27  * Stub implementation of ServletOutputStream.
28  */

29 public final class JSPEngineServletOutputStream extends ServletOutputStream JavaDoc {
30
31     private final ByteArrayOutputStream JavaDoc output;
32     private final PrintWriter JavaDoc writer;
33
34     public JSPEngineServletOutputStream() throws UnsupportedEncodingException JavaDoc {
35         this.output = new ByteArrayOutputStream JavaDoc();
36         this.writer = new PrintWriter JavaDoc(new OutputStreamWriter JavaDoc(output, "UTF-8"));
37     }
38     
39     final PrintWriter JavaDoc getWriter() {
40         return this.writer;
41     }
42     
43     public void write(int b) throws IOException JavaDoc {
44         this.output.write(b);
45     }
46     
47     final byte[] toByteArray() {
48         this.writer.flush();
49         byte[] bytes = output.toByteArray();
50         return bytes;
51     }
52     
53 }
54
Popular Tags