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