-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessStreamRedict.java
More file actions
42 lines (38 loc) · 1.19 KB
/
Copy pathProcessStreamRedict.java
File metadata and controls
42 lines (38 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package cn.edu.ustc.aaron.common;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
class ProcessStreamRedirect extends Thread {
InputStream is;
String type;
OutputStream os;
ProcessStreamRedirect(InputStream is, String type) {
this(is, type, null);
}
ProcessStreamRedirect(InputStream is, String type, OutputStream redirect) {
this.is = is;
this.type = type;
this.os = redirect;
}
public void run() {
try {
PrintWriter pw = null;
if (os != null)
pw = new PrintWriter(os);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = null;
while ((line = br.readLine()) != null) {
if (pw != null)
pw.println(line);
//System.out.println(type + ">" + line);
}
if (pw != null)
pw.flush();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}