mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
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:
parent
f7dee77d73
commit
5b2d430131
7 changed files with 52 additions and 13 deletions
|
@ -240,12 +240,18 @@ public class SequenceInputStream extends InputStream {
|
|||
public long transferTo(OutputStream out) throws IOException {
|
||||
Objects.requireNonNull(out, "out");
|
||||
if (getClass() == SequenceInputStream.class) {
|
||||
long c = 0;
|
||||
long transferred = 0;
|
||||
while (in != null) {
|
||||
c += in.transferTo(out);
|
||||
if (transferred < Long.MAX_VALUE) {
|
||||
try {
|
||||
transferred = Math.addExact(transferred, in.transferTo(out));
|
||||
} catch (ArithmeticException ignore) {
|
||||
return Long.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
nextStream();
|
||||
}
|
||||
return c;
|
||||
return transferred;
|
||||
} else {
|
||||
return super.transferTo(out);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue