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 public void run()
74 {
75 try
76 {
77 if ( poll )
78 {
79 while ( !done )
80 {
81 if ( in.available() > 0 )
82 {
83 int i = in.read( buffer );
84 if ( i != -1 )
85 {
86 out.write( buffer, 0, i );
87 out.flush();
88 }
89 else
90 {
91 done = true;
92 }
93 }
94 else
95 {
96 Thread.sleep( 1 );
97 }
98 }
99 }
100 else
101 {
102 int i = in.read( buffer );
103 while ( i != -1 && !done )
104 {
105 if ( i != -1 )
106 {
107 out.write( buffer, 0, i );
108 out.flush();
109 }
110 else
111 {
112 done = true;
113 }
114 i = in.read( buffer );
115 }
116 }
117 }
118 catch ( Throwable e )
119 {
120
121 }
122 finally
123 {
124 done = true;
125 }
126 }
127 }