Merge "Don't copy more than the object size"

This commit is contained in:
Chris Aniszczyk 2010-08-25 19:52:36 -04:00 committed by Code Review
commit f74d474f3c
1 changed files with 3 additions and 3 deletions

View File

@ -169,14 +169,14 @@ public void copyTo(OutputStream out) throws MissingObjectException,
final long sz = in.getSize();
byte[] tmp = new byte[1024];
long copied = 0;
for (;;) {
while (copied < sz) {
int n = in.read(tmp);
if (n < 0)
break;
throw new EOFException();
out.write(tmp, 0, n);
copied += n;
}
if (copied != sz)
if (0 <= in.read())
throw new EOFException();
} finally {
in.close();