added an option to close OutputStream at the end

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@19392 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2009-07-04 01:49:18 +00:00
1 parent 007517c54b
commit d6677bcb1c
1 file changed
+11 -1
@@ -35,11 +35,17 @@ import java.io.OutputStream;
public class StreamCopyThread extends Thread {
private final InputStream in;
private final OutputStream out;
private final boolean closeOut;
public StreamCopyThread(String threadName, InputStream in, OutputStream out) {
public StreamCopyThread(String threadName, InputStream in, OutputStream out, boolean closeOut) {
super(threadName);
this.in = in;
this.out = out;
this.closeOut = closeOut;
}
public StreamCopyThread(String threadName, InputStream in, OutputStream out) {
this(threadName,in,out,false);
}
public void run() {
@@ -50,7 +56,11 @@ public class StreamCopyThread extends Thread {
while ((len = in.read(buf)) > 0)
out.write(buf, 0, len);
} finally {
// it doesn't make sense not to close InputStream that's already EOF-ed,
// so there's no 'closeIn' flag.
in.close();
if(closeOut)
out.close();
}
} catch (IOException e) {
// TODO: what to do?