01: /*
02: * MCS Media Computer Software Copyright (c) 2005 by MCS
03: * -------------------------------------- Created on 16.01.2004 by w.klaas
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
06: * use this file except in compliance with the License. You may obtain a copy of
07: * the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14: * License for the specific language governing permissions and limitations under
15: * the License.
16: */
17: package de.mcs.utils;
18:
19: import java.io.IOException;
20: import java.io.InputStream;
21: import java.io.InputStreamReader;
22: import java.io.OutputStream;
23:
24: /**
25: * A threaded stream reader needed for starting external processes.
26: *
27: * @author w.klaas
28: */
29: public class StreamReaderThread extends Thread {
30: /** where to put the results to. */
31: private OutputStream mOut;
32:
33: /** where to get the result from. */
34: private InputStreamReader mIn;
35:
36: /**
37: * constructor with in and out Streams.
38: *
39: * @param in
40: * inputstream
41: * @param out
42: * Printstream for output
43: */
44: public StreamReaderThread(final InputStream in,
45: final OutputStream out) {
46: mOut = out;
47: mIn = new InputStreamReader(in);
48: }
49:
50: /**
51: * Threaded run. Now all data will be copied from in to out.
52: */
53: public final void run() {
54: int ch;
55: try {
56: while (-1 != (ch = mIn.read())) {
57: mOut.write((char) ch);
58: }
59: } catch (Exception e) {
60: try {
61: mOut.write(("\nRead error:" + e.getMessage())
62: .getBytes());
63: } catch (IOException e1) {
64: }
65: }
66: }
67: }
|