blob: 5205be0ba7f2758bb3bbe97578b9e51644f91ad4 (
plain) (
blame)
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
|
package mill.main.client;
import java.io.InputStream;
import java.io.OutputStream;
public class InputPumper implements Runnable{
private InputStream src;
private OutputStream dest;
private Boolean checkAvailable;
public InputPumper(InputStream src,
OutputStream dest,
Boolean checkAvailable){
this.src = src;
this.dest = dest;
this.checkAvailable = checkAvailable;
}
boolean running = true;
public void run() {
byte[] buffer = new byte[1024];
try{
while(running){
if (checkAvailable && src.available() == 0) Thread.sleep(2);
else {
int n = src.read(buffer);
if (n == -1) running = false;
else {
dest.write(buffer, 0, n);
dest.flush();
}
}
}
}catch(Exception e){
throw new RuntimeException(e);
}
}
}
|