KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > servlet > DecoratedServletOutputStream


1 /*
2  * Created on Jan 25, 2006
3  */

4 package com.openedit.servlet;
5
6 import java.io.IOException JavaDoc;
7 import java.io.OutputStream JavaDoc;
8 import java.io.PrintWriter JavaDoc;
9
10 import javax.servlet.ServletOutputStream JavaDoc;
11
12 public class DecoratedServletOutputStream extends ServletOutputStream JavaDoc
13 {
14         PrintWriter JavaDoc writer;
15         OutputStream JavaDoc out;
16         public DecoratedServletOutputStream(PrintWriter JavaDoc inWriter)
17         {
18             this.writer = inWriter;
19         }
20         public DecoratedServletOutputStream(OutputStream JavaDoc inOut)
21         {
22             out = inOut;
23         }
24         public void write(int b) throws java.io.IOException JavaDoc
25         {
26             // This method is not used but have to be implemented
27
if ( writer != null )
28             {
29                 this.writer.write(b);
30             }
31             else
32             {
33                 out.write(b);
34             }
35         }
36         public void write(byte[] inB) throws IOException JavaDoc
37         {
38             out.write(inB);
39         }
40         public void write(byte[] inB, int inOff, int inLen) throws IOException JavaDoc
41         {
42             //super.write(inB, inOff, inLen);
43
out.write(inB,inOff,inLen);
44         }
45         public void flush() throws IOException JavaDoc
46         {
47             if( writer != null)
48             {
49                 writer.flush();
50             }
51             else
52             {
53                 out.flush();
54             }
55         }
56         
57         public PrintWriter JavaDoc getWriter()
58         {
59             return writer;
60         }
61     
62 }
63
Free Books   Free Magazines  
Popular Tags