diff options
Diffstat (limited to 'main/client/src/InputPumper.java')
-rw-r--r-- | main/client/src/InputPumper.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/main/client/src/InputPumper.java b/main/client/src/InputPumper.java new file mode 100644 index 00000000..5205be0b --- /dev/null +++ b/main/client/src/InputPumper.java @@ -0,0 +1,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); + } + } +}
\ No newline at end of file |