8014928: (fs) Files.readAllBytes() copies content to new array when content completely read

Alan Bateman Alan.Bateman at oracle.com
Sat May 25 04:23:14 PDT 2013


On 24/05/2013 19:40, Martin Buchholz wrote:
> Looks good.
>
> ObMartin:
>
> s/Read/Reads/
>
> Array creations of size MAX_VALUE - 8 are much more likely to succeed 
> than MAX_VALUE
>
For byte[] then it's more like MAX_VALUE-2 but it might be better if we 
just remove this because it's never used. Originally this private read 
method was used for something else where the expected size wasn't known 
so this is why it expands the buffer. For the only usage now then we 
know the size in advance and we just need to handle the case that the 
file is truncated or replaced (which in both cases you're on your own).

I've updated the webrev to eliminate this method and just put the simple 
read loop into readAllBytes.

-Alan



More information about the nio-dev mailing list