diff options
author | Shawn Pearce <sop@google.com> | 2012-06-15 01:27:43 -0400 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2012-06-15 01:27:43 -0400 |
commit | c25ea295e07f393ecc0ff5b98e45f62022651d87 (patch) | |
tree | 69bcb2af2adbf0d2b4a772eb69464ebf2456dd37 /org.eclipse.jgit | |
parent | b3dbf1981b8a0937253ef197d32921a4bc254bb2 (diff) | |
parent | 590e8f44e624a97ad0180db7f309eb9a448bf60d (diff) | |
download | jgit-c25ea295e07f393ecc0ff5b98e45f62022651d87.tar.gz jgit-c25ea295e07f393ecc0ff5b98e45f62022651d87.zip |
Merge "Fix UnionInputStream.read to be more Java-like"
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/io/UnionInputStream.java | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/UnionInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/UnionInputStream.java index 0df3775f11..20dcd4659e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/UnionInputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/UnionInputStream.java @@ -138,23 +138,18 @@ public class UnionInputStream extends InputStream { @Override public int read(byte[] b, int off, int len) throws IOException { - int cnt = 0; - while (0 < len) { + if (len == 0) + return 0; + for (;;) { final InputStream in = head(); final int n = in.read(b, off, len); - if (0 < n) { - cnt += n; - off += n; - len -= n; - } else if (in == EOF) - return 0 < cnt ? cnt : -1; - else { + if (0 < n) + return n; + else if (in == EOF) + return -1; + else pop(); - if (0 < cnt) - break; - } } - return cnt; } @Override |