On Fri, 1 Jul 2022 09:13:52 GMT, Daniel Fuchs <dfu...@openjdk.org> wrote:

>> In case we read all bytes from an `InputStream` we don't need wrapping with 
>> `BufferedInputStream` as the bytes are not written into internal buffer. 
>> With removal of redundant buffer we save 8 kB of allocated memory.
>
>> In case we read all bytes from an InputStream we don't need wrapping with 
>> BufferedInputStream as the bytes are not written into internal buffer. With 
>> removal of redundant buffer we save 8 kB of allocated memory.
> 
> I believe that in that case the bytes might get double buffered, depending on 
> whether the buffer used by `readAllBytes` is bigger than the buffer used by  
> `BufferedInputStream`, since IIAMNM `readAllBytes()` will call `read(byte[], 
> off, len)` - but I otherwise agree that regardless of that wrapping in a 
> `BufferedInputStream` is always wasteful in this case. Good find!

@dfuch as of current implementation of `InputStream.readNBytes()` it relies on 
`InputStream.DEFAULT_BUFFER_SIZE` which is 8192 and equals to 
`DEFAULT_BUFFER_SIZE` in `BufferedInputStream`.

-------------

PR: https://git.openjdk.org/jdk/pull/9343

Reply via email to