1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.chukwa.inputtools.mdl;
19
20
21 import java.io.InputStream;
22 import java.io.InputStreamReader;
23 import java.io.BufferedReader;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27 public class ErStreamHandler extends Thread {
28 InputStream inpStr;
29 String command;
30 boolean record;
31
32 private static Log log = LogFactory.getLog(ErStreamHandler.class);
33
34 public ErStreamHandler(InputStream inpStr, String command, boolean record) {
35 this.inpStr = inpStr;
36 this.command = command;
37 this.record = record;
38
39 }
40
41 public void run() {
42 try {
43 InputStreamReader inpStrd = new InputStreamReader(inpStr);
44 BufferedReader buffRd = new BufferedReader(inpStrd);
45 String line = null;
46 StringBuffer sb = new StringBuffer();
47 while ((line = buffRd.readLine()) != null) {
48 sb.append(line);
49 }
50 buffRd.close();
51
52 if (record && sb.length() > 0) {
53 log.error(command + " execution error:" + sb.toString());
54 }
55
56 } catch (Exception e) {
57 log.error(command + " error:" + e.getMessage());
58 }
59 }
60
61 }