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

Brian Burkhalter brian.burkhalter at oracle.com
Wed Mar 14 17:50:40 UTC 2018


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/

Thanks,

Brian


More information about the core-libs-dev mailing list