forked from pquiring/javaforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRelayStream.java
More file actions
43 lines (38 loc) · 888 Bytes
/
Copy pathRelayStream.java
File metadata and controls
43 lines (38 loc) · 888 Bytes
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
43
package javaforce;
import java.io.*;
/** Relay Stream.
*
* Continuously reads data from input stream and writes to output stream.
*
* @author pquiring
*/
public class RelayStream extends Thread {
private InputStream in;
private OutputStream out;
private Condition connected;
public static boolean debug = false;
public RelayStream(InputStream in, OutputStream out, Condition connected) {
this.in = in;
this.out = out;
this.connected = connected;
}
public void run() {
byte[] data = new byte[1024];
try {
while (connected.check()) {
int read = in.read(data);
if (read == -1) break;
if (read > 0) {
out.write(data, 0, read);
} else {
JF.sleep(10);
}
}
} catch (Exception e) {
//JFLog.log(e);
}
if (debug) {
JFLog.log("RelayStream done");
}
}
}