8297632: InputStream.transferTo() method should specify what the return value should be when the number of bytes transfered is larger than Long.MAX_VALUE

Reviewed-by: alanb, lancea
This commit is contained in:
Brian Burkhalter 2023-02-14 16:30:52 +00:00
parent f7dee77d73
commit 5b2d430131
7 changed files with 52 additions and 13 deletions

View file

@ -614,7 +614,11 @@ public class BufferedInputStream extends FilterInputStream {
out.write(buffer);
pos = count;
}
return avail + getInIfOpen().transferTo(out);
try {
return Math.addExact(avail, getInIfOpen().transferTo(out));
} catch (ArithmeticException ignore) {
return Long.MAX_VALUE;
}
} else {
return super.transferTo(out);
}