1 package com.quadcap.http.servlets.jsp; 2 3 40 41 import java.io.CharArrayWriter ; 42 import java.io.IOException ; 43 import java.io.PrintWriter ; 44 import java.io.Writer ; 45 46 52 public class JspWriter extends javax.servlet.jsp.JspWriter { 53 CharArrayWriter w; 54 Writer out; 55 int written = 0; 56 boolean flushed = false; 57 boolean closed = false; 58 static String lineSep = System.getProperty("line.separator"); 59 60 public JspWriter(Writer out, int bufferSize, boolean autoFlush) { 61 super(bufferSize, autoFlush); 62 this.out = out; 63 w = new CharArrayWriter (); 64 } 65 66 public void newLine() throws IOException { 67 print(lineSep); 68 } 69 70 public void print(boolean b) throws IOException { 71 print(b ? "true" : "false"); 72 } 73 74 public void print(char c) throws IOException { 75 print(String.valueOf(c)); 76 } 77 78 public void print(int i) throws IOException { 79 print(String.valueOf(i)); 80 } 81 82 public void print(long l) throws IOException { 83 print(String.valueOf(l)); 84 } 85 86 public void print(float f) throws IOException { 87 print(String.valueOf(f)); 88 } 89 90 public void print(double d) throws IOException { 91 print(String.valueOf(d)); 92 } 93 94 public void print(char[] ch) throws IOException { 95 write(ch, 0, ch.length); 96 } 97 98 public void print(String s) throws IOException { 99 w.write(s, 0, s.length()); 100 } 101 102 public void print(Object obj) throws IOException { 103 print(obj.toString()); 104 } 105 106 public void println() throws IOException { 107 print(lineSep); 108 } 109 110 public void println(boolean b) throws IOException { 111 print(b); 112 println(); 113 } 114 115 public void println(char c) throws IOException { 116 print(c); 117 println(); 118 } 119 120 public void println(int i) throws IOException { 121 print(i); 122 println(); 123 } 124 125 public void println(long l) throws IOException { 126 print(l); 127 println(); 128 } 129 130 public void println(float f) throws IOException { 131 print(f); 132 println(); 133 } 134 135 public void println(double d) throws IOException { 136 print(d); 137 println(); 138 } 139 140 public void println(char[] ch) throws IOException { 141 print(ch); 142 println(); 143 } 144 145 public void println(String s) throws IOException { 146 print(s); 147 println(); 148 } 149 150 public void println(Object obj) throws IOException { 151 print(obj); 152 println(); 153 } 154 155 public void write(char[] ch, int off, int len) throws IOException { 156 if (closed) throw new IOException ("JspWriter closed"); 157 if (written + len > getBufferSize()) { 158 if (autoFlush) { 159 flush(); 160 w.reset(); 161 flushed = true; 162 } else { 163 throw new IOException ("JspWriter: buffer full"); 164 } 165 } 166 w.write(ch, off, len); 167 } 168 169 public void clear() throws IOException { 170 w.reset(); 171 } 172 173 public void clearBuffer() throws IOException { 174 if (flushed) throw new IOException ("JspWriter already flushed"); 175 w.reset(); 176 } 177 178 public void flush() throws IOException { 179 w.writeTo(out); 180 } 181 182 public void close() throws IOException { 183 if (!closed) { 184 flush(); 185 closed = true; 186 } 187 } 188 189 public int getRemaining() { 190 if (flushed) return 0; 191 return getBufferSize() - w.size(); 192 } 193 } 194 195 | Popular Tags |