1 4 package com.tc.util; 5 6 import java.io.BufferedReader ; 7 import java.io.IOException ; 8 import java.io.InputStream ; 9 import java.io.InputStreamReader ; 10 import java.io.PrintStream ; 11 12 public class ExternalProcessStreamWriter { 13 14 private volatile IOException exception; 15 16 public void printSys(final InputStream in) { 17 print(System.out, in); 18 } 19 20 public void printErr(final InputStream in) { 21 print(System.err, in); 22 } 23 24 public boolean hasException() { 25 return (exception != null); 26 } 27 28 public IOException getException() { 29 return exception; 30 } 31 32 private void print(final PrintStream stream, final InputStream in) { 33 Thread writer = new Thread () { 34 BufferedReader reader = new BufferedReader (new InputStreamReader (in)); 35 public void run() { 36 try { 37 String line; 38 while ((line = reader.readLine()) != null) { 39 stream.println(line); 40 } 41 } catch (IOException e) { 42 } finally { 44 try { 45 reader.close(); 46 } catch (IOException e) { 47 exception = e; 48 } 49 } 50 } 51 }; 52 writer.start(); 53 } 54 } 55 | Popular Tags |