mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8294696: BufferedInputStream.transferTo should drain buffer when mark set
Reviewed-by: bpb, alanb
This commit is contained in:
parent
d8573b2c5b
commit
581133a0c8
1 changed files with 10 additions and 3 deletions
|
@ -25,6 +25,7 @@
|
|||
|
||||
package java.io;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import jdk.internal.misc.InternalLock;
|
||||
|
@ -605,9 +606,15 @@ public class BufferedInputStream extends FilterInputStream {
|
|||
}
|
||||
|
||||
private long implTransferTo(OutputStream out) throws IOException {
|
||||
if (getClass() == BufferedInputStream.class
|
||||
&& ((count - pos) <= 0) && (markpos == -1)) {
|
||||
return getInIfOpen().transferTo(out);
|
||||
if (getClass() == BufferedInputStream.class && markpos == -1) {
|
||||
int avail = count - pos;
|
||||
if (avail > 0) {
|
||||
// Prevent poisoning and leaking of buf
|
||||
byte[] buffer = Arrays.copyOfRange(getBufIfOpen(), pos, count);
|
||||
out.write(buffer);
|
||||
pos = count;
|
||||
}
|
||||
return avail + getInIfOpen().transferTo(out);
|
||||
} else {
|
||||
return super.transferTo(out);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue