001: package com.quadcap.http.server22;
002:
003: /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
004: *
005: * This software is distributed under the Quadcap Free Software License.
006: * This software may be used or modified for any purpose, personal or
007: * commercial. Open Source redistributions are permitted. Commercial
008: * redistribution of larger works derived from, or works which bundle
009: * this software requires a "Commercial Redistribution License"; see
010: * http://www.quadcap.com/purchase.
011: *
012: * Redistributions qualify as "Open Source" under one of the following terms:
013: *
014: * Redistributions are made at no charge beyond the reasonable cost of
015: * materials and delivery.
016: *
017: * Redistributions are accompanied by a copy of the Source Code or by an
018: * irrevocable offer to provide a copy of the Source Code for up to three
019: * years at the cost of materials and delivery. Such redistributions
020: * must allow further use, modification, and redistribution of the Source
021: * Code under substantially the same terms as this license.
022: *
023: * Redistributions of source code must retain the copyright notices as they
024: * appear in each source code file, these license terms, and the
025: * disclaimer/limitation of liability set forth as paragraph 6 below.
026: *
027: * Redistributions in binary form must reproduce this Copyright Notice,
028: * these license terms, and the disclaimer/limitation of liability set
029: * forth as paragraph 6 below, in the documentation and/or other materials
030: * provided with the distribution.
031: *
032: * The Software is provided on an "AS IS" basis. No warranty is
033: * provided that the Software is free of defects, or fit for a
034: * particular purpose.
035: *
036: * Limitation of Liability. Quadcap Software shall not be liable
037: * for any damages suffered by the Licensee or any third party resulting
038: * from use of the Software.
039: */
040:
041: import java.io.IOException;
042:
043: import com.quadcap.io.IO;
044:
045: /**
046: * A simple implementation of JspWriter that uses the
047: * <code>HttpOutputStream</code>
048: * class to do most of the work.
049: *
050: * @author Stan Bailes
051: */
052: public class JspWriter extends javax.servlet.jsp.JspWriter {
053: HttpOutputStream out;
054: boolean closed = false;
055: byte[] buf = null;
056: static String lineSep = System.getProperty("line.separator");
057:
058: public JspWriter(int bufferSize, boolean autoFlush) {
059: super (bufferSize, autoFlush);
060: }
061:
062: final void setHttpOutputStream(HttpOutputStream out) {
063: this .out = out;
064: }
065:
066: public final void newLine() throws IOException {
067: print(lineSep);
068: }
069:
070: public final void print(boolean b) throws IOException {
071: print(b ? "true" : "false");
072: }
073:
074: public final void print(char c) throws IOException {
075: print(String.valueOf(c));
076: }
077:
078: public final void print(int i) throws IOException {
079: print(String.valueOf(i));
080: }
081:
082: public final void print(long l) throws IOException {
083: print(String.valueOf(l));
084: }
085:
086: public final void print(float f) throws IOException {
087: print(String.valueOf(f));
088: }
089:
090: public final void print(double d) throws IOException {
091: print(String.valueOf(d));
092: }
093:
094: public final void print(char[] ch) throws IOException {
095: write(ch, 0, ch.length);
096: }
097:
098: public final void print(String s) throws IOException {
099: final int len = s.length();
100: if (buf == null || buf.length < len) {
101: buf = new byte[len];
102: }
103: for (int i = 0; i < len; i++) {
104: buf[i] = (byte) (s.charAt(i) & 0xff);
105: }
106: out.write(buf, 0, len);
107: }
108:
109: public final void write(String s) throws IOException {
110: IO.write(out, s);
111: }
112:
113: public final void write(String s, int off, int len)
114: throws IOException {
115: for (int i = 0; i < len; i++) {
116: out.write(s.charAt(off + i) & 0xff);
117: }
118: }
119:
120: public final void print(Object obj) throws IOException {
121: print(obj.toString());
122: }
123:
124: public final void println() throws IOException {
125: print(lineSep);
126: }
127:
128: public final void println(boolean b) throws IOException {
129: print(b);
130: println();
131: }
132:
133: public final void println(char c) throws IOException {
134: print(c);
135: println();
136: }
137:
138: public final void println(int i) throws IOException {
139: print(i);
140: println();
141: }
142:
143: public final void println(long l) throws IOException {
144: print(l);
145: println();
146: }
147:
148: public final void println(float f) throws IOException {
149: print(f);
150: println();
151: }
152:
153: public final void println(double d) throws IOException {
154: print(d);
155: println();
156: }
157:
158: public final void println(char[] ch) throws IOException {
159: print(ch);
160: println();
161: }
162:
163: public final void println(String s) throws IOException {
164: print(s);
165: println();
166: }
167:
168: public final void println(Object obj) throws IOException {
169: print(obj);
170: println();
171: }
172:
173: public final void write(char[] ch, int off, int len)
174: throws IOException {
175: if (closed)
176: throw new IOException("JspWriter closed");
177: for (int i = 0; i < len; i++) {
178: out.write(ch[off + i]);
179: }
180: }
181:
182: public final void clear() throws IOException {
183: try {
184: out.reset();
185: } catch (IllegalStateException e) {
186: throw new IOException(e.toString());
187: }
188: }
189:
190: public final void clearBuffer() throws IOException {
191: try {
192: out.reset();
193: } catch (IllegalStateException e) {
194: }
195: }
196:
197: public final void flush() throws IOException {
198: out.flush();
199: }
200:
201: public final void close() throws IOException {
202: if (!closed) {
203: out.close();
204: closed = true;
205: }
206: }
207:
208: public final int getRemaining() {
209: return out.getRemaining();
210: }
211:
212: public final void setBufferSize(int bufferSize) {
213: out.setBufferSize(bufferSize);
214: }
215:
216: public final void setAutoFlush(boolean autoFlush) {
217: out.setAutoFlush(autoFlush);
218: }
219: }
|