KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jsp > StreamJspWriter


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jsp;
30
31 import javax.servlet.jsp.JspWriter JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.io.PrintWriter JavaDoc;
34 import java.io.Writer JavaDoc;
35
36 /**
37  * A JSP writer encapsulating a Writer.
38  */

39 class StreamJspWriter extends AbstractBodyContent {
40   // the underlying writer
41
private Writer JavaDoc _writer;
42   
43   private JspPrintWriter _printWriter;
44
45   private JspWriter JavaDoc _parent;
46   
47   // the page context
48
private PageContextImpl _pageContext;
49
50   private boolean _isClosed;
51   
52   /**
53    * Creates a new StreamJspWriter
54    */

55   StreamJspWriter()
56   {
57   }
58
59   /**
60    * Initialize the JSP writer
61    *
62    * @param os the underlying stream
63    */

64   void init(JspWriter JavaDoc parent, Writer JavaDoc writer)
65   {
66     _parent = parent;
67     _writer = writer;
68     _isClosed = false;
69   }
70
71   /**
72    * Returns the print writer.
73    */

74   public PrintWriter JavaDoc getWriter()
75   {
76     if (_printWriter == null)
77       _printWriter = new JspPrintWriter(this);
78
79     _printWriter.init(this);
80
81     return _printWriter;
82   }
83
84   /**
85    * Writes a character array to the writer.
86    *
87    * @param buf the buffer to write.
88    * @param off the offset into the buffer
89    * @param len the number of characters to write
90    */

91   final public void write(char []buf, int offset, int length)
92     throws IOException JavaDoc
93   {
94     if (_isClosed)
95       return;
96
97     _writer.write(buf, offset, length);
98   }
99   
100   /**
101    * Writes a character to the output.
102    *
103    * @param buf the buffer to write.
104    */

105   final public void write(int ch) throws IOException JavaDoc
106   {
107     if (_isClosed)
108       return;
109
110     _writer.write(ch);
111   }
112
113   /**
114    * Writes the newline character.
115    */

116   final public void newLine() throws IOException JavaDoc
117   {
118     if (_isClosed)
119       return;
120
121     _writer.write('\n');
122   }
123
124   /**
125    * Prints a character.
126    */

127   final public void print(char ch) throws IOException JavaDoc
128   {
129     if (_isClosed)
130       return;
131
132     _writer.write(ch);
133   }
134
135   /**
136    * Prints the newline.
137    */

138   final public void println() throws IOException JavaDoc
139   {
140     _writer.write('\n');
141   }
142
143   public void clear() throws IOException JavaDoc
144   {
145     clearBuffer();
146   }
147
148   public void clearBuffer() throws IOException JavaDoc
149   {
150   }
151
152   public void flushBuffer()
153     throws IOException JavaDoc
154   {
155     if (_isClosed)
156       return;
157     
158     _writer.flush();
159   }
160
161   public void flush() throws IOException JavaDoc
162   {
163     _writer.flush();
164   }
165
166   final public void close() throws IOException JavaDoc
167   {
168     _isClosed = true;
169   }
170
171   public int getBufferSize()
172   {
173     return 0;
174   }
175
176   public int getRemaining()
177   {
178     return 0;
179   }
180
181   AbstractJspWriter popWriter()
182   {
183     AbstractJspWriter parent = super.popWriter();
184
185     return parent;
186   }
187 }
188
Popular Tags