1 28 29 package com.caucho.vfs; 30 31 import java.io.PrintWriter ; 32 import java.io.StringWriter ; 33 import java.io.Writer ; 34 35 38 public abstract class AbstractPrintWriter extends PrintWriter { 39 private static final char []_trueChars = "true".toCharArray(); 40 private static final char []_falseChars = "false".toCharArray(); 41 private static final char []_nullChars = "null".toCharArray(); 42 43 private static final Writer _dummyWriter = new StringWriter(); 44 45 private final char []_tempCharBuffer = new char[64]; 46 47 50 protected AbstractPrintWriter() 51 { 52 super(_dummyWriter); 53 } 54 55 62 abstract public void write(char []buf, int offset, int length); 63 64 69 abstract public void write(int ch); 70 71 74 abstract public void write(String s, int off, int len); 75 76 81 final public void write(char []buf) 82 { 83 write(buf, 0, buf.length); 84 } 85 86 89 final public void write(String s) 90 { 91 write(s, 0, s.length()); 92 } 93 94 97 public void newLine() 98 { 99 write('\n'); 100 } 101 102 105 final public void print(boolean b) 106 { 107 write(b ? _trueChars : _falseChars); 108 } 109 110 113 public void print(char ch) 114 { 115 write(ch); 116 } 117 118 121 public void print(int i) 122 { 123 if (i == 0x80000000) { 124 print("-2147483648"); 125 return; 126 } 127 128 if (i < 0) { 129 write('-'); 130 i = -i; 131 } else if (i < 9) { 132 write('0' + i); 133 return; 134 } 135 136 int length = 0; 137 int exp = 10; 138 139 if (i >= 1000000000) 140 length = 9; 141 else { 142 for (; i >= exp; length++) 143 exp = 10 * exp; 144 } 145 146 int j = 31; 147 148 while (i > 0) { 149 _tempCharBuffer[--j] = (char) ((i % 10) + '0'); 150 i /= 10; 151 } 152 153 write(_tempCharBuffer, j, 31 - j); 154 } 155 156 159 public void print(long v) 160 { 161 if (v == 0x8000000000000000L) { 162 print("-9223372036854775808"); 163 return; 164 } 165 166 if (v < 0) { 167 write('-'); 168 v = -v; 169 } else if (v == 0) { 170 write('0'); 171 return; 172 } 173 174 int j = 31; 175 176 while (v > 0) { 177 _tempCharBuffer[--j] = (char) ((v % 10) + '0'); 178 v /= 10; 179 } 180 181 write(_tempCharBuffer, j, 31 - j); 182 } 183 184 final public void print(float f) 185 { 186 write(String.valueOf(f)); 187 } 188 189 final public void print(double d) 190 { 191 write(String.valueOf(d)); 192 } 193 194 197 final public void print(char []s) 198 { 199 write(s, 0, s.length); 200 } 201 202 205 final public void print(String s) 206 { 207 if (s == null) 208 write(_nullChars, 0, _nullChars.length); 209 else 210 write(s, 0, s.length()); 211 } 212 213 216 final public void print(Object v) 217 { 218 if (v == null) 219 write(_nullChars, 0, _nullChars.length); 220 else { 221 String s = v.toString(); 222 223 write(s, 0, s.length()); 224 } 225 } 226 227 230 public void println() 231 { 232 write('\n'); 233 } 234 235 240 final public void println(boolean v) 241 { 242 print(v); 243 println(); 244 } 245 246 251 final public void println(char v) 252 { 253 print(v); 254 println(); 255 } 256 257 262 final public void println(int v) 263 { 264 print(v); 265 println(); 266 } 267 268 273 final public void println(long v) 274 { 275 print(v); 276 println(); 277 } 278 279 284 final public void println(float v) 285 { 286 String s = String.valueOf(v); 287 288 write(s, 0, s.length()); 289 println(); 290 } 291 292 293 298 final public void println(double v) 299 { 300 String s = String.valueOf(v); 301 302 write(s, 0, s.length()); 303 304 println(); 305 } 306 307 310 final public void println(char []s) 311 { 312 write(s, 0, s.length); 313 println(); 314 } 315 316 319 final public void println(String s) 320 { 321 if (s == null) 322 write(_nullChars, 0, _nullChars.length); 323 else 324 write(s, 0, s.length()); 325 326 println(); 327 } 328 329 332 final public void println(Object v) 333 { 334 if (v == null) 335 write(_nullChars, 0, _nullChars.length); 336 else { 337 String s = v.toString(); 338 339 write(s, 0, s.length()); 340 } 341 342 println(); 343 } 344 } 345 | Popular Tags |