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