RFR 8139206: Add InputStream readNBytes(int len)
weijun.wang at oracle.com
Mon Jan 22 15:05:11 UTC 2018
> On Jan 22, 2018, at 10:16 PM, Roger Riggs <Roger.Riggs at oracle.com> wrote:
> Hi Max,
> Both methods that throw and not throw have been proposed. But adding two methods
> seems like to too much clutter in the API and the methods appear too similar.
Sorry I wasn't aware of earlier discussions on this. My feeling is that readNBytesFully() is more useful than readNBytesAtMost().
> The (at most) readNBytes method provides the needed functionality of allocating/reallocating
> the array and performing well.
Sure, this is a good enhancement. I understand it's easy to add a check to readNBytesAtMost() to get the function of readNBytesFully(), and the reverse is not possible.
> For the cases where reading less than N is significant, the caller should be checking the
> return length to validate it got the input it expected.
I've checked some of the codes I wrote and each time readNBytes() can be used I only want the return value to be of exactly N bytes.
> $.02, Roger
> On 1/22/2018 5:42 AM, Weijun Wang wrote:
>>> On Jan 22, 2018, at 5:01 PM, Weijun Wang <weijun.wang at oracle.com> wrote:
>>> I wonder when readNBytes(n) will be useful if the return value has less than n bytes.
>> I mean I have seen protocols saying reading rest of the content, or reading N bytes, but never reading at most N bytes. I would rather the method throwing an EOFException if there are less than N bytes. This is also what DataInput::readFully is doing.
>>>> On Jan 22, 2018, at 4:52 PM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
>>>> On 17/01/2018 16:24, Brian Burkhalter wrote:
>>>>> A negative value of ‘len’ will now cause an IllegalArgumentException instead of an IndexOutOfBoundsException. Also some verbiage has been improved.
>>>> The updated version looks good. I just wonde about the "For example ..." in the @throws OOME description. The API can't be called with a len > Integer.MAX_VALUE so this example could be confusing - I think just drop that sentence.
>>>> Minor formatting in passing. At L128 and L339 it would be easier to read if the "throws IOException" were on the previous line. Also L355 might be a bit clear if the Math.min was indented (have to look twice to see that it's not in the while body).
More information about the core-libs-dev