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