8294696: BufferedInputStream.transferTo should drain buffer when mark set
Reviewed-by: bpb, alanb
This commit is contained in:
parent
d8573b2c5b
commit
581133a0c8
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
package java.io;
|
package java.io;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import jdk.internal.misc.InternalLock;
|
import jdk.internal.misc.InternalLock;
|
||||||
@ -605,9 +606,15 @@ public class BufferedInputStream extends FilterInputStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private long implTransferTo(OutputStream out) throws IOException {
|
private long implTransferTo(OutputStream out) throws IOException {
|
||||||
if (getClass() == BufferedInputStream.class
|
if (getClass() == BufferedInputStream.class && markpos == -1) {
|
||||||
&& ((count - pos) <= 0) && (markpos == -1)) {
|
int avail = count - pos;
|
||||||
return getInIfOpen().transferTo(out);
|
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 {
|
} else {
|
||||||
return super.transferTo(out);
|
return super.transferTo(out);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user