RFR of 8180451: ByteArrayInputStream should override readAllBytes, readNBytes, and transferTo

Brian Burkhalter brian.burkhalter at oracle.com
Wed Mar 21 18:01:33 UTC 2018


This is still in need of final approval, assuming it is OK.

Thanks,

Brian

On Mar 14, 2018, at 10:50 AM, Brian Burkhalter <brian.burkhalter at oracle.com> wrote:

> On Mar 14, 2018, at 9:27 AM, David Lloyd <david.lloyd at redhat.com> wrote:
> 
>> @@ -196,14 +194,32 @@
>>         return len;
>>     }
>> 
>> +    public synchronized byte[] readAllBytes() {
>> +        byte[] result = Arrays.copyOfRange(buf, pos, count);
>> +        pos = count;
>> +        return result;
>> +    }
>> +
>> +    public synchronized int readNBytes(byte[] b, int off, int len) {
>> +        int n = read(b, off, len);
>> +        return n == -1 ? 0 : n;
>> +    }
>> 
>> This probably doesn't need to be synchronized, though I imagine the
>> difference would be minimal.
> 
> You are correct, it does not.
> 
>> +    public synchronized long transferTo(OutputStream out) throws IOException {
>> +        int len = count - pos
>> +        out.write(but, pos, len);
>> 
>> s/but/buf/ I guess?
> 
> Webrevs corrected in place:
> 
> http://cr.openjdk.java.net/~bpb/8180451/webrev.00-01/
> http://cr.openjdk.java.net/~bpb/8180451/webrev.01/



More information about the core-libs-dev mailing list