Quadcap Embeddable Server

com/quadcap/http/server22/JspWriter.java

Go to the documentation of this file.
00001 package com.quadcap.http.server22; 00002 00003 /* Copyright 1999 - 2003 Quadcap Software. All rights reserved. 00004 * 00005 * This software is distributed under the Quadcap Free Software License. 00006 * This software may be used or modified for any purpose, personal or 00007 * commercial. Open Source redistributions are permitted. Commercial 00008 * redistribution of larger works derived from, or works which bundle 00009 * this software requires a "Commercial Redistribution License"; see 00010 * http://www.quadcap.com/purchase. 00011 * 00012 * Redistributions qualify as "Open Source" under one of the following terms: 00013 * 00014 * Redistributions are made at no charge beyond the reasonable cost of 00015 * materials and delivery. 00016 * 00017 * Redistributions are accompanied by a copy of the Source Code or by an 00018 * irrevocable offer to provide a copy of the Source Code for up to three 00019 * years at the cost of materials and delivery. Such redistributions 00020 * must allow further use, modification, and redistribution of the Source 00021 * Code under substantially the same terms as this license. 00022 * 00023 * Redistributions of source code must retain the copyright notices as they 00024 * appear in each source code file, these license terms, and the 00025 * disclaimer/limitation of liability set forth as paragraph 6 below. 00026 * 00027 * Redistributions in binary form must reproduce this Copyright Notice, 00028 * these license terms, and the disclaimer/limitation of liability set 00029 * forth as paragraph 6 below, in the documentation and/or other materials 00030 * provided with the distribution. 00031 * 00032 * The Software is provided on an "AS IS" basis. No warranty is 00033 * provided that the Software is free of defects, or fit for a 00034 * particular purpose. 00035 * 00036 * Limitation of Liability. Quadcap Software shall not be liable 00037 * for any damages suffered by the Licensee or any third party resulting 00038 * from use of the Software. 00039 */ 00040 00041 import java.io.IOException; 00042 00043 import com.quadcap.io.IO; 00044 00045 /** 00046 * A simple implementation of JspWriter that uses the 00047 * <code>HttpOutputStream</code> 00048 * class to do most of the work. 00049 * 00050 * @author Stan Bailes 00051 */ 00052 public class JspWriter extends javax.servlet.jsp.JspWriter { 00053 HttpOutputStream out; 00054 boolean closed = false; 00055 byte[] buf = null; 00056 static String lineSep = System.getProperty("line.separator"); 00057 00058 public JspWriter(int bufferSize, boolean autoFlush) { 00059 super(bufferSize, autoFlush); 00060 } 00061 00062 final void setHttpOutputStream(HttpOutputStream out) { 00063 this.out = out; 00064 } 00065 00066 public final void newLine() throws IOException { 00067 print(lineSep); 00068 } 00069 00070 public final void print(boolean b) throws IOException { 00071 print(b ? "true" : "false"); 00072 } 00073 00074 public final void print(char c) throws IOException { 00075 print(String.valueOf(c)); 00076 } 00077 00078 public final void print(int i) throws IOException { 00079 print(String.valueOf(i)); 00080 } 00081 00082 public final void print(long l) throws IOException { 00083 print(String.valueOf(l)); 00084 } 00085 00086 public final void print(float f) throws IOException { 00087 print(String.valueOf(f)); 00088 } 00089 00090 public final void print(double d) throws IOException { 00091 print(String.valueOf(d)); 00092 } 00093 00094 public final void print(char[] ch) throws IOException { 00095 write(ch, 0, ch.length); 00096 } 00097 00098 public final void print(String s) throws IOException { 00099 final int len = s.length(); 00100 if (buf == null || buf.length < len) { 00101 buf = new byte[len]; 00102 } 00103 for (int i = 0; i < len; i++) { 00104 buf[i] = (byte)(s.charAt(i) & 0xff); 00105 } 00106 out.write(buf, 0, len); 00107 } 00108 00109 public final void write(String s) throws IOException { 00110 IO.write(out, s); 00111 } 00112 00113 public final void write(String s, int off, int len) throws IOException { 00114 for (int i = 0; i < len; i++) { 00115 out.write(s.charAt(off + i) & 0xff); 00116 } 00117 } 00118 00119 public final void print(Object obj) throws IOException { 00120 print(obj.toString()); 00121 } 00122 00123 public final void println() throws IOException { 00124 print(lineSep); 00125 } 00126 00127 public final void println(boolean b) throws IOException { 00128 print(b); 00129 println(); 00130 } 00131 00132 public final void println(char c) throws IOException { 00133 print(c); 00134 println(); 00135 } 00136 00137 public final void println(int i) throws IOException { 00138 print(i); 00139 println(); 00140 } 00141 00142 public final void println(long l) throws IOException { 00143 print(l); 00144 println(); 00145 } 00146 00147 public final void println(float f) throws IOException { 00148 print(f); 00149 println(); 00150 } 00151 00152 public final void println(double d) throws IOException { 00153 print(d); 00154 println(); 00155 } 00156 00157 public final void println(char[] ch) throws IOException { 00158 print(ch); 00159 println(); 00160 } 00161 00162 public final void println(String s) throws IOException { 00163 print(s); 00164 println(); 00165 } 00166 00167 public final void println(Object obj) throws IOException { 00168 print(obj); 00169 println(); 00170 } 00171 00172 public final void write(char[] ch, int off, int len) throws IOException { 00173 if (closed) throw new IOException("JspWriter closed"); 00174 for (int i = 0; i < len; i++) { 00175 out.write(ch[off + i]); 00176 } 00177 } 00178 00179 public final void clear() throws IOException { 00180 try { 00181 out.reset(); 00182 } catch (IllegalStateException e) { 00183 throw new IOException(e.toString()); 00184 } 00185 } 00186 00187 public final void clearBuffer() throws IOException { 00188 try { 00189 out.reset(); 00190 } catch (IllegalStateException e) {} 00191 } 00192 00193 public final void flush() throws IOException { 00194 out.flush(); 00195 } 00196 00197 public final void close() throws IOException { 00198 if (!closed) { 00199 out.close(); 00200 closed = true; 00201 } 00202 } 00203 00204 public final int getRemaining() { 00205 return out.getRemaining(); 00206 } 00207 00208 public final void setBufferSize(int bufferSize) { 00209 out.setBufferSize(bufferSize); 00210 } 00211 00212 public final void setAutoFlush(boolean autoFlush) { 00213 out.setAutoFlush(autoFlush); 00214 } 00215 } 00216