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