From dc94b7d0633c0a6e5375bdf1bec2b9dede461da3 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 2 Apr 2013 09:58:20 -0700 Subject: [PATCH] [FIXED JENKINS-8686] As I mentioned in the comment, I doubt if this makes any behaviour change, but this seems like a sensible defensive measure that wouldn't hurt. --- cli/src/main/java/hudson/cli/CLI.java | 4 ++-- core/src/main/java/hudson/Proc.java | 2 +- core/src/main/java/hudson/Util.java | 4 ++-- core/src/main/java/hudson/util/StreamCopyThread.java | 2 +- core/src/main/java/hudson/util/io/ZipArchiver.java | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cli/src/main/java/hudson/cli/CLI.java b/cli/src/main/java/hudson/cli/CLI.java index a343662beb..03004f30f9 100644 --- a/cli/src/main/java/hudson/cli/CLI.java +++ b/cli/src/main/java/hudson/cli/CLI.java @@ -300,14 +300,14 @@ public class CLI { byte[] buf = new byte[1024]; try { InputStream is = conn.getInputStream(); - while (is.read(buf) > 0) { + while (is.read(buf) >= 0) { // Ignore } is.close(); } catch (IOException e) { try { InputStream es = ((HttpURLConnection)conn).getErrorStream(); - while (es.read(buf) > 0) { + while (es.read(buf) >= 0) { // Ignore } es.close(); diff --git a/core/src/main/java/hudson/Proc.java b/core/src/main/java/hudson/Proc.java index 8f1d4ab37c..ca1f4a6767 100644 --- a/core/src/main/java/hudson/Proc.java +++ b/core/src/main/java/hudson/Proc.java @@ -399,7 +399,7 @@ public abstract class Proc { try { byte[] buf = new byte[8192]; int len; - while ((len = in.read(buf)) > 0) { + while ((len = in.read(buf)) >= 0) { out.write(buf, 0, len); out.flush(); } diff --git a/core/src/main/java/hudson/Util.java b/core/src/main/java/hudson/Util.java index a2e2bb3373..64b6374cc4 100644 --- a/core/src/main/java/hudson/Util.java +++ b/core/src/main/java/hudson/Util.java @@ -451,7 +451,7 @@ public class Util { public static void copyStream(InputStream in,OutputStream out) throws IOException { byte[] buf = new byte[8192]; int len; - while((len=in.read(buf))>0) + while((len=in.read(buf))>=0) out.write(buf,0,len); } @@ -562,7 +562,7 @@ public class Util { byte[] buffer = new byte[1024]; DigestInputStream in =new DigestInputStream(source,md5); try { - while(in.read(buffer)>0) + while(in.read(buffer)>=0) ; // simply discard the input } finally { in.close(); diff --git a/core/src/main/java/hudson/util/StreamCopyThread.java b/core/src/main/java/hudson/util/StreamCopyThread.java index 80bdeb1e35..e494afa9b9 100644 --- a/core/src/main/java/hudson/util/StreamCopyThread.java +++ b/core/src/main/java/hudson/util/StreamCopyThread.java @@ -57,7 +57,7 @@ public class StreamCopyThread extends Thread { try { byte[] buf = new byte[8192]; int len; - while ((len = in.read(buf)) > 0) + 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, diff --git a/core/src/main/java/hudson/util/io/ZipArchiver.java b/core/src/main/java/hudson/util/io/ZipArchiver.java index e5dd0648a9..e0c68cc38f 100644 --- a/core/src/main/java/hudson/util/io/ZipArchiver.java +++ b/core/src/main/java/hudson/util/io/ZipArchiver.java @@ -71,7 +71,7 @@ final class ZipArchiver extends Archiver { zip.putNextEntry(fileZipEntry); FileInputStream in = new FileInputStream(f); int len; - while((len=in.read(buf))>0) + while((len=in.read(buf))>=0) zip.write(buf,0,len); in.close(); zip.closeEntry();