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

Peter Levart peter.levart at gmail.com
Wed Dec 20 16:04:18 UTC 2017

On 12/20/2017 03:09 PM, Alan Bateman wrote:
> On 20/12/2017 12:40, Peter Levart wrote:
>> Hi Brian,
>> I 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.

Regards, Peter

More information about the core-libs-dev mailing list