View Javadoc

1   /**
2      This file is part of GoldenGate Project (named also GoldenGate or GG).
3   
4      Copyright 2009, Frederic Bregier, and individual contributors by the @author
5      tags. See the COPYRIGHT.txt in the distribution for a full listing of
6      individual contributors.
7   
8      All GoldenGate Project is free software: you can redistribute it and/or 
9      modify it under the terms of the GNU General Public License as published 
10     by the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12  
13     GoldenGate is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17  
18     You should have received a copy of the GNU General Public License
19     along with GoldenGate .  If not, see <http://www.gnu.org/licenses/>.
20   */
21  package openr66.context.task;
22  
23  import java.io.BufferedReader;
24  import java.io.IOException;
25  import java.io.InputStreamReader;
26  import java.io.PipedInputStream;
27  
28  /**
29   * This class is used with external process in order to get the All echo
30   * from the stdout of the process.
31   * @author Frederic Bregier
32   *
33   */
34  class AllLineReader implements Runnable {
35      private final BufferedReader reader;
36      /**
37       * This will be the result at the end
38       */
39      public StringBuilder lastLine = new StringBuilder();
40  
41      public AllLineReader(PipedInputStream inputStream) {
42          reader = new BufferedReader(new InputStreamReader(inputStream));
43      }
44  
45      /*
46       * (non-Javadoc)
47       *
48       * @see java.lang.Runnable#run()
49       */
50      @Override
51      public void run() {
52          String line;
53          try {
54              while ((line = reader.readLine()) != null) {
55                  line = line.trim();
56                  if (line.length() > 0) {
57                      lastLine.append(line).append('\n');
58                  }
59              }
60          } catch (IOException e) {
61              // Could be a "Write end dead", which means the end of the thread
62              // writer is found
63              // before the thread closes the write pipe
64          }
65          try {
66              reader.close();
67          } catch (IOException e) {
68          }
69      }
70  
71  }