diff --git a/core/src/main/java/hudson/Proc.java b/core/src/main/java/hudson/Proc.java index 4a215a1e0e7ee728f7e1813a3840ccf8f8ffaf8f..eee3cf0f7302477519038f4773a34445faab63aa 100644 --- a/core/src/main/java/hudson/Proc.java +++ b/core/src/main/java/hudson/Proc.java @@ -306,7 +306,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(); } @@ -315,7 +315,7 @@ public abstract class Proc { out.close(); } } catch (IOException e) { - // TODO: what to do? + throw new RuntimeException(e); } } } @@ -331,7 +331,7 @@ public abstract class Proc { } /** - * Retemoly launched process via {@link Channel}. + * Remotely launched process via {@link hudson.remoting.Channel}. */ public static final class RemoteProc extends Proc { private final Future process; diff --git a/core/src/main/java/hudson/Util.java b/core/src/main/java/hudson/Util.java index 412ab84d92ff207334562169f5f2157b201e8150..1fd489ce50205ed20d9bd8ed49013be875cf04ca 100644 --- a/core/src/main/java/hudson/Util.java +++ b/core/src/main/java/hudson/Util.java @@ -422,14 +422,14 @@ 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); } public static void copyStream(Reader in, Writer out) throws IOException { char[] buf = new char[8192]; int len; - while((len=in.read(buf))>0) + while((len=in.read(buf))>=0) out.write(buf,0,len); } @@ -519,7 +519,7 @@ public class Util { DigestInputStream in =new DigestInputStream(source,md5); try { - while(in.read(garbage)>0) + while(in.read(garbage)>=0) ; // simply discard the input } finally { in.close(); diff --git a/core/src/main/java/hudson/model/LargeText.java b/core/src/main/java/hudson/model/LargeText.java index c7606d90ab5315bf90963999a496317f844a2cb0..739db31a6cc8ed4acd2127763dc71520ed65e4a1 100644 --- a/core/src/main/java/hudson/model/LargeText.java +++ b/core/src/main/java/hudson/model/LargeText.java @@ -365,7 +365,7 @@ public class LargeText { return in.read(buf); } - public int read(byte[] buf, int offset, int length) throws IOException { + public int read(byte[] buf, int offset, int length) throws IOException { // FIXME-CHECK-CALLERS return in.read(buf,offset,length); } } diff --git a/core/src/main/java/hudson/org/apache/tools/tar/TarInputStream.java b/core/src/main/java/hudson/org/apache/tools/tar/TarInputStream.java index f2d10c1c39960b09cb7ee9fd89505ba8fc9cb79a..c9bff3332c71448779c1f82825317d58eb31c27f 100644 --- a/core/src/main/java/hudson/org/apache/tools/tar/TarInputStream.java +++ b/core/src/main/java/hudson/org/apache/tools/tar/TarInputStream.java @@ -291,7 +291,7 @@ public class TarInputStream extends FilterInputStream { * @throws IOException on error */ public int read() throws IOException { - int num = this.read(this.oneBuf, 0, 1); + int num = this.read(this.oneBuf, 0, 1); // FIXME check if read() guarantees to return at least 1 character, otherwise bug lurking return num == -1 ? -1 : ((int) this.oneBuf[0]) & 0xFF; } diff --git a/core/src/main/java/hudson/util/ChunkedInputStream.java b/core/src/main/java/hudson/util/ChunkedInputStream.java index 5691eeb80de8d02117e227a5d80644dc5ea14bc7..e8bfb00a1e65eba203fa1b99e3f7209492f9f090 100644 --- a/core/src/main/java/hudson/util/ChunkedInputStream.java +++ b/core/src/main/java/hudson/util/ChunkedInputStream.java @@ -138,7 +138,7 @@ public class ChunkedInputStream extends InputStream { * @throws IOException if an IO problem occurs. */ @Override - public int read (byte[] b, int off, int len) throws IOException { + public int read (byte[] b, int off, int len) throws IOException { // FIXME-CHECK-CALLERS if (closed) { throw new IOException("Attempted read from closed stream."); @@ -168,7 +168,7 @@ public class ChunkedInputStream extends InputStream { * @throws IOException if an IO problem occurs. */ @Override - public int read (byte[] b) throws IOException { + public int read (byte[] b) throws IOException { // FIXME-CHECK-CALLERS return read(b, 0, b.length); } diff --git a/core/src/main/java/hudson/util/HeadBufferingStream.java b/core/src/main/java/hudson/util/HeadBufferingStream.java index 64240c784006410827a8eecb3be0bb5debc2e92d..e3afe6087e3d36e3bb8a5e76e968a6fb948ec08e 100644 --- a/core/src/main/java/hudson/util/HeadBufferingStream.java +++ b/core/src/main/java/hudson/util/HeadBufferingStream.java @@ -57,7 +57,7 @@ public class HeadBufferingStream extends FilterInputStream { } @Override - public int read(byte b[], int off, int len) throws IOException { + public int read(byte b[], int off, int len) throws IOException { // FIXME-CHECK-CALLERS int r = in.read(b, off, len); if(r>0) { int sp = space(); diff --git a/core/src/main/java/hudson/util/StreamCopyThread.java b/core/src/main/java/hudson/util/StreamCopyThread.java index 80bdeb1e35fe804da9808a351d4eaf8ff0c2c346..23bddac99469941bd7dd09495d7cd0979ecfc122 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, @@ -67,7 +67,7 @@ public class StreamCopyThread extends Thread { out.close(); } } catch (IOException e) { - // TODO: what to do? + throw new RuntimeException(e); } } } diff --git a/core/src/main/java/hudson/util/io/ZipArchiver.java b/core/src/main/java/hudson/util/io/ZipArchiver.java index 19e9b678fcb008ce2bb5b788e3cba063aac2378a..5899c1919a64ffc1df51ad644237e2426c602129 100644 --- a/core/src/main/java/hudson/util/io/ZipArchiver.java +++ b/core/src/main/java/hudson/util/io/ZipArchiver.java @@ -57,10 +57,13 @@ final class ZipArchiver extends Archiver { } else { zip.putNextEntry(new ZipEntry(relativePath)); FileInputStream in = new FileInputStream(f); - int len; - while((len=in.read(buf))>0) - zip.write(buf,0,len); - in.close(); + try { + int len; + while((len=in.read(buf))>=0) + zip.write(buf,0,len); + } finally { + in.close(); + } zip.closeEntry(); } entriesWritten++; diff --git a/maven-agent/src/test/java/hudson/maven/agent/LaunchTest.java b/maven-agent/src/test/java/hudson/maven/agent/LaunchTest.java index 62a974dc50fd930c958614470a9169c086c0fd6c..3245a4c58c00874ae1eeff44ddda74cb1872acd4 100644 --- a/maven-agent/src/test/java/hudson/maven/agent/LaunchTest.java +++ b/maven-agent/src/test/java/hudson/maven/agent/LaunchTest.java @@ -90,7 +90,7 @@ public class LaunchTest extends TestCase { 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); } } diff --git a/remoting/src/main/java/hudson/remoting/BinarySafeStream.java b/remoting/src/main/java/hudson/remoting/BinarySafeStream.java index c777e91bdc51cb6457fe53f1ca136a6720891fdf..c725c0e7e8d8091f83f5f83bfae290478fe65abb 100644 --- a/remoting/src/main/java/hudson/remoting/BinarySafeStream.java +++ b/remoting/src/main/java/hudson/remoting/BinarySafeStream.java @@ -186,7 +186,10 @@ public final class BinarySafeStream { int avail = super.available(); if(avail >0) { byte[] buf = new byte[avail]; - baos.write(buf,0,super.read(buf)); + int len2 = super.read(buf); + if (len2 > 0) { + baos.write(buf,0,len2); + } } StringBuilder buf = new StringBuilder("Invalid encoded sequence encountered:"); for (byte ch : baos.toByteArray()) diff --git a/remoting/src/main/java/hudson/remoting/FastPipedInputStream.java b/remoting/src/main/java/hudson/remoting/FastPipedInputStream.java index 9d55c7efe0885a66d7d9e8fcb29d54bc62d06050..a6f4430a35fd843f46350e2e04cd09e6a91bc13f 100644 --- a/remoting/src/main/java/hudson/remoting/FastPipedInputStream.java +++ b/remoting/src/main/java/hudson/remoting/FastPipedInputStream.java @@ -143,11 +143,11 @@ public class FastPipedInputStream extends InputStream { public int read() throws IOException { byte[] b = new byte[1]; - return read(b, 0, b.length) == -1 ? -1 : (255 & b[0]); + return read(b, 0, b.length) == -1 ? -1 : (255 & b[0]); // FIXME check if read() guarantees to return at least 1 character, otherwise bug lurking } @Override - public int read(byte[] b) throws IOException { + public int read(byte[] b) throws IOException { // FIXME-CHECK-CALLERS return read(b, 0, b.length); } diff --git a/remoting/src/main/java/hudson/remoting/RemoteClassLoader.java b/remoting/src/main/java/hudson/remoting/RemoteClassLoader.java index 84271f370da97e583502d181dc71a6bba403be8f..1cbe32bdcbf50dfca66aaa2c6d4ee00d7978b230 100644 --- a/remoting/src/main/java/hudson/remoting/RemoteClassLoader.java +++ b/remoting/src/main/java/hudson/remoting/RemoteClassLoader.java @@ -453,9 +453,12 @@ final class RemoteClassLoader extends URLClassLoader { byte[] buf = new byte[8192]; int len; - while((len=in.read(buf))>0) - baos.write(buf,0,len); - in.close(); + try { + while((len=in.read(buf))>=0) + baos.write(buf,0,len); + } finally { + in.close(); + } return baos.toByteArray(); } diff --git a/remoting/src/main/java/hudson/remoting/RemoteInputStream.java b/remoting/src/main/java/hudson/remoting/RemoteInputStream.java index 26bb3250c940f9d430b7dc3dbc3e713634f0f272..41a583b3387424916a1f004a507026466d6964fa 100644 --- a/remoting/src/main/java/hudson/remoting/RemoteInputStream.java +++ b/remoting/src/main/java/hudson/remoting/RemoteInputStream.java @@ -68,11 +68,11 @@ public class RemoteInputStream extends InputStream implements Serializable { return core.read(); } - public int read(byte[] b) throws IOException { + public int read(byte[] b) throws IOException { // FIXME-CHECK-CALLERS return core.read(b); } - public int read(byte[] b, int off, int len) throws IOException { + public int read(byte[] b, int off, int len) throws IOException { // FIXME-CHECK-CALLERS return core.read(b, off, len); } diff --git a/remoting/src/main/java/hudson/remoting/forward/CopyThread.java b/remoting/src/main/java/hudson/remoting/forward/CopyThread.java index 08e04001bf6eb27289057b168f11bcdaad7350f9..7bc49e2617c8d3a870e0904a9612da794d24ac1f 100644 --- a/remoting/src/main/java/hudson/remoting/forward/CopyThread.java +++ b/remoting/src/main/java/hudson/remoting/forward/CopyThread.java @@ -24,14 +24,14 @@ final class CopyThread 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 { in.close(); out.close(); } } catch (IOException e) { - // TODO: what to do? + throw new RuntimeException(e); } } } diff --git a/remoting/src/test/java/hudson/remoting/CopyThread.java b/remoting/src/test/java/hudson/remoting/CopyThread.java index db934ec452cb1ae97483d3965aa5170564254e5f..fcf13e9388ec195418c387b327f20fc78fc7ed48 100644 --- a/remoting/src/test/java/hudson/remoting/CopyThread.java +++ b/remoting/src/test/java/hudson/remoting/CopyThread.java @@ -46,11 +46,14 @@ class Copier extends Thread { try { byte[] buf = new byte[8192]; int len; - while((len=in.read(buf))>0) - out.write(buf,0,len); - in.close(); + try { + while((len=in.read(buf))>=0) + out.write(buf,0,len); + } finally { + in.close(); + } } catch (IOException e) { - // TODO: what to do? + throw new RuntimeException(e); } } } diff --git a/remoting/src/test/java/hudson/remoting/TestCallable.java b/remoting/src/test/java/hudson/remoting/TestCallable.java index 6f0f50516af06aca0cb73fc8f5aba6dc18cc804a..22050d74c3130302cf891ad8e2e21c9d694b5a04 100644 --- a/remoting/src/test/java/hudson/remoting/TestCallable.java +++ b/remoting/src/test/java/hudson/remoting/TestCallable.java @@ -45,9 +45,12 @@ public class TestCallable implements Callable { byte[] buf = new byte[8192]; int len; - while((len=in.read(buf))>0) - baos.write(buf,0,len); - in.close(); + try { + while((len=in.read(buf))>=0) + baos.write(buf,0,len); + } finally { + in.close(); + } r[1] = baos.toByteArray();