KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > connection > AbstractResponseStream


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.server.connection;
30
31 import com.caucho.log.Log;
32 import com.caucho.util.L10N;
33 import com.caucho.vfs.OutputStreamWithBuffer;
34 import com.caucho.vfs.Path;
35
36 import java.io.IOException JavaDoc;
37 import java.io.OutputStream JavaDoc;
38 import java.io.UnsupportedEncodingException JavaDoc;
39 import java.io.Writer JavaDoc;
40 import java.util.Locale JavaDoc;
41 import java.util.logging.Logger JavaDoc;
42
43 /**
44  * API for handling the PrintWriter/ServletOutputStream
45  */

46 public abstract class AbstractResponseStream extends OutputStreamWithBuffer {
47   private static final Logger JavaDoc log = Log.open(AbstractResponseStream.class);
48   private static final L10N L = new L10N(AbstractResponseStream.class);
49
50   /**
51    * Starts the response stream.
52    */

53   public void start()
54   {
55   }
56
57   /**
58    * Returns true for a Caucho response stream.
59    */

60   abstract public boolean isCauchoResponseStream();
61   
62   /**
63    * Sets the encoding.
64    */

65   public void setEncoding(String JavaDoc encoding)
66     throws UnsupportedEncodingException JavaDoc
67   {
68   }
69
70   /**
71    * Sets the locale.
72    */

73   public void setLocale(Locale JavaDoc locale)
74     throws UnsupportedEncodingException JavaDoc
75   {
76   }
77
78   /**
79    * Sets the buffer size.
80    */

81   abstract public void setBufferSize(int size);
82
83   /**
84    * Gets the buffer size.
85    */

86   abstract public int getBufferSize();
87
88   /**
89    * Sets the auto-flush
90    */

91   public void setAutoFlush(boolean isAutoFlush)
92   {
93   }
94
95   /**
96    * Return the auto-flush.
97    */

98   public boolean isAutoFlush()
99   {
100     return true;
101   }
102
103   /**
104    * Returns the remaining buffer entries.
105    */

106   abstract public int getRemaining();
107
108   /**
109    * Returns the char buffer.
110    */

111   abstract public char []getCharBuffer()
112     throws IOException JavaDoc;
113
114   /**
115    * Returns the char buffer offset.
116    */

117   abstract public int getCharOffset()
118     throws IOException JavaDoc;
119
120   /**
121    * Sets the char buffer offset.
122    */

123   abstract public void setCharOffset(int offset)
124     throws IOException JavaDoc;
125
126   /**
127    * Returns the next char buffer.
128    */

129   abstract public char []nextCharBuffer(int offset)
130     throws IOException JavaDoc;
131
132   /**
133    * Returns true if the response is committed.
134    */

135   public boolean isCommitted()
136   {
137     return false;
138   }
139
140   /**
141    * Set true for HEAD requests.
142    */

143   public void setHead()
144   {
145   }
146
147   /**
148    * Set true for HEAD requests.
149    */

150   public boolean isHead()
151   {
152     return false;
153   }
154
155   /**
156    * Sets a byte cache stream.
157    */

158   public void setByteCacheStream(OutputStream JavaDoc cacheStream)
159   {
160     throw new UnsupportedOperationException JavaDoc(getClass().getName());
161   }
162
163   /**
164    * Sets a char cache stream.
165    */

166   public void setCharCacheStream(Writer JavaDoc cacheStream)
167   {
168     throw new UnsupportedOperationException JavaDoc(getClass().getName());
169   }
170
171   /**
172    * Returns the written content length
173    */

174   public int getContentLength()
175   {
176     return 0;
177   }
178   
179   /**
180    * Writes a byte to the output.
181    */

182   abstract public void write(int v)
183     throws IOException JavaDoc;
184
185   /**
186    * Writes a byte array to the output.
187    */

188   abstract public void write(byte []buffer, int offset, int length)
189     throws IOException JavaDoc;
190
191   /**
192    * Writes a character to the output.
193    */

194   abstract public void print(int ch)
195     throws IOException JavaDoc;
196
197   /**
198    * Writes a char array to the output.
199    */

200   abstract public void print(char []buffer, int offset, int length)
201     throws IOException JavaDoc;
202
203   /**
204    * Clears the output buffer, including headers if possible.
205    */

206   public void clear()
207     throws IOException JavaDoc
208   {
209     clearBuffer();
210   }
211
212   /**
213    * Clears the output buffer.
214    */

215   abstract public void clearBuffer();
216
217   /**
218    * Flushes the output buffer.
219    */

220   abstract public void flushBuffer()
221     throws IOException JavaDoc;
222
223   /**
224    * Flushes the output.
225    */

226   public void flushByte()
227     throws IOException JavaDoc
228   {
229     flushBuffer();
230   }
231
232   /**
233    * Flushes the output.
234    */

235   public void flushChar()
236     throws IOException JavaDoc
237   {
238     flushBuffer();
239   }
240
241   /**
242    * Sends a file.
243    *
244    * @param path the path to the file
245    * @param length the length of the file (-1 if unknown)
246    */

247   public void sendFile(Path path, long length)
248     throws IOException JavaDoc
249   {
250     path.writeToStream(this);
251   }
252
253   /**
254    * Flushes the output.
255    */

256   public void flush()
257     throws IOException JavaDoc
258   {
259     flushByte();
260   }
261
262   /**
263    * Finishes the response stream
264    */

265   public void finish()
266     throws IOException JavaDoc
267   {
268     flushBuffer();
269   }
270
271   /**
272    * Closes the response stream
273    */

274   public void close()
275     throws IOException JavaDoc
276   {
277     finish();
278   }
279
280   /**
281    * Clears the close
282    */

283   public void clearClosed()
284     throws IOException JavaDoc
285   {
286   }
287 }
288
Popular Tags