RFR 8193832: Performance of InputStream.readAllBytes() could be improved

Brian Burkhalter brian.burkhalter at oracle.com
Wed Dec 20 16:14:50 UTC 2017


Hi Peter,

On Dec 20, 2017, at 8:04 AM, Peter Levart <peter.levart at gmail.com> wrote:

>>>  found another improvement. If you are reading from files, there's no difference. But if you read from say socket(s), there may be short reads (read() returning 0).
>> InputStreams are blocking so if someone creates an InputStream over a socket configured non-blocking then they have to emulate blocking behavior. So assuming a non-zero byte array, then read should return a positive value or -1.
>> 
>> -Alan.
> 
> You are right Alan. I don't know why I assumed that 0 is a valid return value (for non-empty array). So my last suggestion is unnecessary. Each buf will be filled to the top before inner loop exits or the stream will be at EOF.

Thanks for the suggestions. I’ll take a look at the first two later today.

Brian


More information about the core-libs-dev mailing list