1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.scala_tools.maven;
17
18 import java.io.InputStream;
19 import java.io.OutputStream;
20
21 import org.codehaus.plexus.util.IOUtil;
22
23 public class StreamPiper extends Thread {
24
25 private InputStream in_;
26 private OutputStream out_;
27
28 public StreamPiper(InputStream in, OutputStream out) {
29 in_ = in;
30 out_ = out;
31 }
32
33 @Override
34 public void run() {
35 try {
36 byte[] buffer = new byte[512];
37 int bytes_read;
38 while (true) {
39 bytes_read = in_.read(buffer);
40 if (bytes_read != -1) {
41 out_.write(buffer, 0, bytes_read);
42 out_.flush();
43 }
44
45 if (bytes_read < 1) {
46 yield();
47 sleep(500l);
48 }
49 }
50 } catch (InterruptedException exc) {
51 System.err.print("stop by interrupt");
52 return;
53 } catch (Exception exc) {
54 System.err.print("!!!! exc !!!");
55 exc.printStackTrace();
56 throw new RuntimeException("wrap: " + exc.getMessage(), exc);
57 } finally {
58 IOUtil.close(in_);
59 IOUtil.close(out_);
60 }
61 }
62 }