mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8316156: ByteArrayInputStream.transferTo causes MaxDirectMemorySize overflow
Reviewed-by: alanb
This commit is contained in:
parent
3461c7b165
commit
5cacf212f0
2 changed files with 83 additions and 2 deletions
|
@ -44,6 +44,7 @@ import java.util.Objects;
|
|||
* @since 1.0
|
||||
*/
|
||||
public class ByteArrayInputStream extends InputStream {
|
||||
private static final int MAX_TRANSFER_SIZE = 128*1024;
|
||||
|
||||
/**
|
||||
* An array of bytes that was provided
|
||||
|
@ -205,8 +206,16 @@ public class ByteArrayInputStream extends InputStream {
|
|||
@Override
|
||||
public synchronized long transferTo(OutputStream out) throws IOException {
|
||||
int len = count - pos;
|
||||
out.write(buf, pos, len);
|
||||
pos = count;
|
||||
if (len > 0) {
|
||||
int nwritten = 0;
|
||||
while (nwritten < len) {
|
||||
int nbyte = Integer.min(len - nwritten, MAX_TRANSFER_SIZE);
|
||||
out.write(buf, pos, nbyte);
|
||||
pos += nbyte;
|
||||
nwritten += nbyte;
|
||||
}
|
||||
assert pos == count;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue