View Javadoc
1   /*
2    * ReadOutputLog.java
3    *
4    * Created on November 19, 2001, 10:37 AM
5    */
6   
7   package emissary.util.shell;
8   
9   import java.io.BufferedReader;
10  import java.io.IOException;
11  import java.io.InputStream;
12  import java.io.InputStreamReader;
13  
14  public class ReadOutputLogger extends ProcessReader {
15  
16      public BufferedReader bufferedReader;
17      public InputStreamReader inputReader;
18      public boolean finished = false;
19      public String name;
20  
21      public ReadOutputLogger(final String name, final InputStream in) {
22          this.inputReader = new InputStreamReader(in);
23          this.bufferedReader = new BufferedReader(this.inputReader);
24          this.finished = false;
25          this.name = name;
26          if (this.name == null) {
27              this.name = "";
28          }
29      }
30  
31      @Override
32      void runImpl() {
33          this.finished = false;
34          try {
35              String aLine;
36              do {
37                  aLine = this.bufferedReader.readLine();
38                  if ((aLine != null) && !aLine.isEmpty()) {
39                      // logger.info("{}:{}", this.name, aLine.replace('\n', '~'));
40                  }
41              } while (aLine != null && !this.finished);
42          } catch (IOException iox) {
43              // ignore
44          }
45          try {
46              this.inputReader.close();
47              this.bufferedReader.close();
48          } catch (IOException iox) {
49              // ignore
50          }
51      }
52  
53      @Override
54      @SuppressWarnings("Interruption")
55      public void finish() {
56          this.finished = true;
57          this.interrupt();
58      }
59  }