Lines 85-107
Link Here
|
85 |
this.os = os; |
84 |
this.os = os; |
86 |
} |
85 |
} |
87 |
|
86 |
|
88 |
|
87 |
/** |
|
|
88 |
* read method with possibility to be interrupted, when blocking is set to false |
89 |
*/ |
90 |
public int read(InputStream is, byte[] buf, boolean blocking) throws InterruptedException, IOException { |
91 |
if (!blocking) { |
92 |
while (is.available()==0) { |
93 |
if (Thread.interrupted()) { |
94 |
throw new InterruptedException(); |
95 |
} |
96 |
Thread.sleep(SLEEP); |
97 |
} |
98 |
} |
99 |
return is.read(buf); |
100 |
} |
101 |
|
89 |
/** |
102 |
/** |
90 |
* Copies data from the input stream to the output stream. |
103 |
* Copies data from the input stream to the output stream. |
91 |
* |
104 |
* |
92 |
* Terminates as soon as the input stream is closed or an error occurs. |
105 |
* Terminates as soon as the input stream is closed or an error occurs (or interrupted on Windows). |
93 |
*/ |
106 |
*/ |
94 |
public void run() { |
107 |
public void run() { |
95 |
final byte[] buf = new byte[SIZE]; |
108 |
final byte[] buf = new byte[SIZE]; |
96 |
|
109 |
// nonblocking read only for Windows solving Ant bug #5003 |
|
|
110 |
boolean blocking = System.getProperty("os.name").toLowerCase().indexOf("windows")<0; |
111 |
// for other systems use blocking read, because on OS/2 systems with IBM JDK 1.3.x is bug in InputStream.isAvailable() |
97 |
int length; |
112 |
int length; |
98 |
try { |
113 |
try { |
99 |
while ((length = is.read(buf)) > 0) { |
114 |
while ((!Thread.interrupted())&&((length = read(is, buf, blocking)) > 0)) { |
100 |
os.write(buf, 0, length); |
115 |
os.write(buf, 0, length); |
101 |
try { |
116 |
Thread.sleep(SLEEP); |
102 |
Thread.sleep(SLEEP); |
|
|
103 |
} catch (InterruptedException e) {} |
104 |
} |
117 |
} |
105 |
} catch(IOException e) {} |
118 |
} catch(IOException e) { |
|
|
119 |
} catch (InterruptedException e) {} |
106 |
} |
120 |
} |
107 |
} |
121 |
} |