1 26 27 package org.objectweb.openccm.task; 28 29 import java.io.BufferedReader ; 31 import java.io.InputStream ; 32 import java.io.InputStreamReader ; 33 34 41 public class Redirector 42 { 43 49 50 private Process process_; 51 52 58 63 public Redirector(Process process) 64 { 65 process_ = process; 66 } 67 68 74 77 private class OutputRedirectorThread 78 implements Runnable 79 { 80 81 private InputStream inputstream_; 82 83 88 public 89 OutputRedirectorThread(InputStream inputstream) 90 { 91 inputstream_ = inputstream; 92 } 93 94 97 public void 98 run() 99 { 100 BufferedReader bufferedreader = null; 101 String line = null; 102 103 try 104 { 105 bufferedreader = 107 new BufferedReader ( new InputStreamReader (inputstream_) ); 108 109 while ( (line = bufferedreader.readLine()) != null) 111 { 112 System.out.println(line); 113 } 114 }catch(java.io.IOException e){ 115 e.printStackTrace(); 116 } 117 } 118 } 119 120 123 private class ErrorRedirectorThread 124 implements Runnable 125 { 126 127 private InputStream inputstream_; 128 129 134 public 135 ErrorRedirectorThread(InputStream inputstream) 136 { 137 inputstream_ = inputstream; 138 } 139 140 143 public void 144 run() 145 { 146 BufferedReader bufferedreader = null; 147 String line = null; 148 149 try 150 { 151 bufferedreader = 153 new BufferedReader ( new InputStreamReader (inputstream_) ); 154 155 while ( (line = bufferedreader.readLine()) != null) 157 { 158 System.err.println(line); 159 } 160 }catch(java.io.IOException e){ 161 e.printStackTrace(); 162 } 163 } 164 } 165 166 172 178 182 public void 183 redirectOutput() 184 { 185 Thread t1 = null, 186 t2 = null; 187 OutputRedirectorThread outThread = null; 188 ErrorRedirectorThread errThread = null; 189 190 191 try 193 { 194 outThread = new OutputRedirectorThread(process_.getInputStream()); 195 errThread = new ErrorRedirectorThread(process_.getErrorStream()); 196 197 t1 = new Thread ( outThread ); 198 t2 = new Thread ( errThread ); 199 200 t1.start(); 201 t2.start(); 202 }catch (Exception e){ 203 e.printStackTrace(); 204 } 205 } 206 207 } 208 | Popular Tags |