RFR: 8316156: (ch) Channels.newOutputStream(ch).write(bigByteArray) allocates a lot of direct memory [v5]
Paul Wagland
duke at openjdk.org
Tue Sep 19 13:02:41 UTC 2023
On Tue, 19 Sep 2023 10:11:50 GMT, Alan Bateman <alanb at openjdk.org> wrote:
> As regards Files.copy(InputStream, Path). It uses the input stream's transferTo method to transfer the bytes to the target file. It could be changed to write in chunks or the input streams that have all bytes in the heap could write in chunks. One or both is okay and doesn't have compatibility concerns.
Thanks for this answer. The challenge is that we are very dependent on the specific implementation of the input streams `transferTo` method. Specifically, the default implementation is perfectly fine, the one in (the old) BAIS caused us issues.
If I understand correctly though, after this PR you can just wrap _any_ InputStream into a BIS, and it would be safe, right? Maybe this is something that could be put into `Files.copy`? Then `Files.copy` would always work, and you aren't changing the short read/write characteristics?
-------------
PR Comment: https://git.openjdk.org/jdk/pull/15733#issuecomment-1725466941
More information about the nio-dev
mailing list