1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.shared.release.exec;
20
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.io.OutputStream;
24
25
26
27
28 public class RawStreamPumper extends Thread {
29 private final InputStream in;
30
31 private final OutputStream out;
32
33 boolean done;
34
35 boolean poll;
36
37 byte[] buffer = new byte[256];
38
39
40
41
42
43
44
45
46 public RawStreamPumper(InputStream in, OutputStream out, boolean poll) {
47 this.in = in;
48 this.out = out;
49 this.poll = poll;
50 }
51
52
53
54
55
56
57
58 public RawStreamPumper(InputStream in, OutputStream out) {
59 this.in = in;
60 this.out = out;
61 this.poll = false;
62 }
63
64
65
66
67 public void setDone() {
68 done = true;
69 }
70
71
72
73
74
75
76 public void closeInput() throws IOException {
77 in.close();
78 }
79
80
81
82
83
84
85 public void closeOutput() throws IOException {
86 out.close();
87 }
88
89 @Override
90 public void run() {
91 try {
92 if (poll) {
93 while (!done) {
94 if (in.available() > 0) {
95 int i = in.read(buffer);
96 if (i != -1) {
97 out.write(buffer, 0, i);
98 out.flush();
99 } else {
100 done = true;
101 }
102 } else {
103 Thread.sleep(1);
104 }
105 }
106 } else {
107 int i = in.read(buffer);
108 while (i != -1 && !done) {
109 if (i != -1) {
110 out.write(buffer, 0, i);
111 out.flush();
112 } else {
113 done = true;
114 }
115 i = in.read(buffer);
116 }
117 }
118 } catch (Throwable e) {
119
120 } finally {
121 done = true;
122 }
123 }
124 }