1 29 30 package com.caucho.jsp; 31 32 import java.io.IOException ; 33 import java.io.Reader ; 34 import java.io.Writer ; 35 36 39 abstract class AbstractBodyContent extends AbstractJspWriter { 40 private static final char []_trueChars = "true".toCharArray(); 41 private static final char []_falseChars = "false".toCharArray(); 42 private static final char []_nullChars = "null".toCharArray(); 43 44 private final char []_tempCharBuffer = new char[256]; 45 46 private boolean _isPrintNullAsBlank; 47 48 public void setPrintNullAsBlank(boolean enable) 49 { 50 _isPrintNullAsBlank = enable; 51 } 52 53 60 abstract public void write(char []buf, int offset, int length) 61 throws IOException ; 62 63 68 abstract public void write(int ch) throws IOException ; 69 70 75 final public void write(char []buf) throws IOException 76 { 77 write(buf, 0, buf.length); 78 } 79 80 83 final public void write(String s) throws IOException 84 { 85 write(s, 0, s.length()); 86 } 87 88 91 public void write(String s, int off, int len) throws IOException 92 { 93 while (len > 0) { 94 int sublen = _tempCharBuffer.length; 95 96 if (len < sublen) 97 sublen = len; 98 99 s.getChars(off, off + sublen, _tempCharBuffer, 0); 100 101 write(_tempCharBuffer, 0, sublen); 102 103 len -= sublen; 104 off += sublen; 105 } 106 } 107 108 111 public void newLine() throws IOException 112 { 113 write('\n'); 114 } 115 116 119 final public void print(boolean b) throws IOException 120 { 121 write(b ? _trueChars : _falseChars); 122 } 123 124 127 public void print(char ch) throws IOException 128 { 129 write(ch); 130 } 131 132 public void print(int i) throws IOException 133 { 134 if (i == 0x80000000) { 135 print("-2147483648"); 136 return; 137 } 138 139 if (i < 0) { 140 write('-'); 141 i = -i; 142 } else if (i < 9) { 143 write('0' + i); 144 return; 145 } 146 147 int length = 0; 148 int exp = 10; 149 150 if (i >= 1000000000) 151 length = 9; 152 else { 153 for (; i >= exp; length++) 154 exp = 10 * exp; 155 } 156 157 int j = 31; 158 159 while (i > 0) { 160 _tempCharBuffer[--j] = (char) ((i % 10) + '0'); 161 i /= 10; 162 } 163 164 write(_tempCharBuffer, j, 31 - j); 165 } 166 167 public void print(long v) throws IOException 168 { 169 if (v == 0x8000000000000000L) { 170 print("-9223372036854775808"); 171 return; 172 } 173 174 if (v < 0) { 175 write('-'); 176 v = -v; 177 } else if (v == 0) { 178 write('0'); 179 return; 180 } 181 182 int j = 31; 183 184 while (v > 0) { 185 _tempCharBuffer[--j] = (char) ((v % 10) + '0'); 186 v /= 10; 187 } 188 189 write(_tempCharBuffer, j, 31 - j); 190 } 191 192 final public void print(float f) throws IOException 193 { 194 write(String.valueOf(f)); 195 } 196 197 final public void print(double d) throws IOException 198 { 199 write(String.valueOf(d)); 200 } 201 202 205 final public void print(char []s) throws IOException 206 { 207 write(s, 0, s.length); 208 } 209 210 213 final public void print(String s) throws IOException 214 { 215 if (s != null) 216 write(s, 0, s.length()); 217 else if (_isPrintNullAsBlank) { 218 } 219 else 220 write(_nullChars, 0, _nullChars.length); 221 } 222 223 226 final public void print(Object v) throws IOException 227 { 228 if (v != null) { 229 String s = v.toString(); 230 231 write(s, 0, s.length()); 232 } 233 else if (_isPrintNullAsBlank) { 234 } 235 else 236 write(_nullChars, 0, _nullChars.length); 237 } 238 239 242 public void println() throws IOException 243 { 244 write('\n'); 245 } 246 247 252 final public void println(boolean v) throws IOException 253 { 254 print(v); 255 println(); 256 } 257 258 263 final public void println(char v) throws IOException 264 { 265 print(v); 266 println(); 267 } 268 269 274 final public void println(int v) throws IOException 275 { 276 print(v); 277 println(); 278 } 279 280 285 final public void println(long v) throws IOException 286 { 287 print(v); 288 println(); 289 } 290 291 296 final public void println(float v) throws IOException 297 { 298 String s = String.valueOf(v); 299 300 write(s, 0, s.length()); 301 println(); 302 } 303 304 305 310 final public void println(double v) throws IOException 311 { 312 String s = String.valueOf(v); 313 314 write(s, 0, s.length()); 315 316 println(); 317 } 318 319 322 final public void println(char []s) throws IOException 323 { 324 write(s, 0, s.length); 325 println(); 326 } 327 328 331 final public void println(String s) throws IOException 332 { 333 if (s != null) 334 write(s, 0, s.length()); 335 else if (_isPrintNullAsBlank) { 336 } 337 else 338 write(_nullChars, 0, _nullChars.length); 339 340 println(); 341 } 342 343 346 final public void println(Object v) throws IOException 347 { 348 if (v != null) { 349 String s = String.valueOf(v); 350 351 write(s, 0, s.length()); 352 } 353 else if (_isPrintNullAsBlank) { 354 } 355 else 356 write(_nullChars, 0, _nullChars.length); 357 358 println(); 359 } 360 361 abstract public void clear() throws IOException ; 362 363 abstract public void clearBuffer() throws IOException ; 364 365 abstract public void flushBuffer() 366 throws IOException ; 367 368 abstract public void flush() throws IOException ; 369 370 abstract public void close() throws IOException ; 371 372 abstract public int getBufferSize(); 373 374 abstract public int getRemaining(); 375 376 public void writeOut(Writer writer) throws IOException 377 { 378 throw new UnsupportedOperationException (); 379 } 380 381 public String getString() 382 { 383 throw new UnsupportedOperationException (); 384 } 385 386 public Reader getReader() 387 { 388 throw new UnsupportedOperationException (); 389 } 390 391 public void clearBody() 392 { 393 throw new UnsupportedOperationException (); 394 } 395 } 396 | Popular Tags |