JENKINS-8686 IO stream copies are not done properly.

First pass at making sure we don't stop copying when the reader reads 0 characters.

I will now also review the callers for our internal code, and check if we can use IOUtils methods instead.
This commit is contained in:
Jerome Lacoste committed 2011-02-04 15:34:07 +01:00
1 parent 2332b114a3
commit bfbaf2c9d9
16 files changed
+50 -35

No files matched your search

+3 -3
View File
@@ -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<Integer> process;
+3 -3
View File
@@ -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();
@@ -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);
}
}
@@ -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;
}
@@ -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);
}
@@ -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();
@@ -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);
}
}
}
@@ -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++;