1 19 20 package org.netbeans.core.execution; 21 22 import java.io.IOException ; 23 import java.io.PrintStream ; 24 import java.io.OutputStream ; 25 26 final class WriterPrintStream extends PrintStream { 27 28 private boolean stdOut; 29 30 37 public WriterPrintStream(OutputStream out, boolean stdOut) { 38 super(out, true); 39 40 this.stdOut = stdOut; 41 } 42 43 44 public void close() { 45 } 46 47 public void flush() { 48 try { 49 if (stdOut) { 50 ExecutionEngine.getTaskIOs().getOut().flush(); 51 } else { 52 ExecutionEngine.getTaskIOs().getErr().flush(); 53 } 54 } catch (IOException e) { 55 setError(); 56 } 57 } 58 59 private void write(String s) { 60 try { 61 if (stdOut) { 62 ExecutionEngine.getTaskIOs().getOut().write(s); 63 } else { 64 ExecutionEngine.getTaskIOs().getErr().write(s); 65 } 66 } catch (IOException e) { 67 setError(); 68 } 69 } 70 71 80 public void print(boolean b) { 81 write(b ? "true" : "false"); } 83 84 92 public void print(char c) { 93 try { 94 if (stdOut) { 95 ExecutionEngine.getTaskIOs().getOut().write(c); 96 } else { 97 ExecutionEngine.getTaskIOs().getErr().write(c); 98 } 99 } catch (IOException e) { 100 setError(); 101 } 102 } 103 104 114 public void print(int i) { 115 write(String.valueOf(i)); 116 } 117 118 128 public void print(long l) { 129 write(String.valueOf(l)); 130 } 131 132 142 public void print(float f) { 143 write(String.valueOf(f)); 144 } 145 146 156 public void print(double d) { 157 write(String.valueOf(d)); 158 } 159 160 170 public void print(char s[]) { 171 try { 172 if (stdOut) { 173 ExecutionEngine.getTaskIOs().getOut().write(s); 174 } else { 175 ExecutionEngine.getTaskIOs().getErr().write(s); 176 } 177 } catch (IOException e) { 178 setError(); 179 } 180 } 181 182 191 public void print(String s) { 192 if (s == null) { 193 s = "null"; } 195 write(s); 196 } 197 198 208 public void print(Object obj) { 209 write(String.valueOf(obj)); 210 } 211 212 213 214 215 221 public void println() { 222 print(getNewLine()); 223 } 224 225 232 public void println(boolean x) { 233 String out = (x ? "true" : "false"); write(out.concat(getNewLine())); 235 } 236 237 244 public void println(char x) { 245 String nline = getNewLine(); 246 int nlinelen = nline.length(); 247 char[] tmp = new char[nlinelen + 1]; 248 tmp[0] = x; 249 for (int i = 0; i < nlinelen; i++) { 250 tmp[i + 1] = nline.charAt(i); 251 } 252 try { 253 if (stdOut) { 254 ExecutionEngine.getTaskIOs().getOut().write(tmp); 255 } else { 256 ExecutionEngine.getTaskIOs().getErr().write(tmp); 257 } 258 } catch (IOException e) { 259 setError(); 260 } 261 } 262 263 270 public void println(int x) { 271 write(String.valueOf(x).concat(getNewLine())); 272 } 273 274 281 public void println(long x) { 282 write(String.valueOf(x).concat(getNewLine())); 283 } 284 285 292 public void println(float x) { 293 write(String.valueOf(x).concat(getNewLine())); 294 } 295 296 303 public void println(double x) { 304 write(String.valueOf(x).concat(getNewLine())); 305 } 306 307 314 public void println(char x[]) { 315 String nline = getNewLine(); 316 int nlinelen = nline.length(); 317 char[] tmp = new char[x.length + nlinelen]; 318 System.arraycopy(x, 0, tmp, 0, x.length); 319 for (int i = 0; i < nlinelen; i++) { 320 tmp[x.length + i] = nline.charAt(i); 321 } 322 x = null; 323 try { 324 if (stdOut) { 325 ExecutionEngine.getTaskIOs().getOut().write(tmp); 326 } else { 327 ExecutionEngine.getTaskIOs().getErr().write(tmp); 328 } 329 } catch (IOException e) { 330 setError(); 331 } 332 } 333 334 341 public void println(String x) { 342 if (x == null) { 343 x = "null"; } 345 print(x.concat(getNewLine())); 346 } 347 348 355 public void println(Object x) { 356 if (x == null) { 357 print("null".concat(getNewLine())); } else { 359 String s = x.toString(); 360 if(s == null) { 361 print("<null>".concat(getNewLine())); } else { 363 print(s.concat(getNewLine())); 364 } 365 } 366 } 367 368 private static String newLine; 369 private static String getNewLine() { 370 if (newLine == null) { 371 newLine = System.getProperty("line.separator"); 372 } 373 return newLine; 374 } 375 } 376 | Popular Tags |