From d6677bcb1cf8420bec275e2d5de8cd60bfabc598 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Sat, 4 Jul 2009 01:49:18 +0000 Subject: [PATCH] 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 --- core/src/main/java/hudson/util/StreamCopyThread.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/util/StreamCopyThread.java b/core/src/main/java/hudson/util/StreamCopyThread.java index ea3ce7cc41..4d5b667349 100644 --- a/core/src/main/java/hudson/util/StreamCopyThread.java +++ b/core/src/main/java/hudson/util/StreamCopyThread.java @@ -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?