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

Alan Bateman Alan.Bateman at oracle.com
Fri May 24 10:49:35 PDT 2013


This is a trivial one, a performance bug in the private method used by 
Files.readAllBytes to read the file contents.

The bug is that when the byte[] is sized correctly that it will be 
"expanded" in order to read the EOF, then copied a new byte[] of the 
original size. Easily fixed by just bailing when everything is read. 
Technically something could be expanding the file at the time but this 
is inherently racey/unsafe so it's not a concern. The webrev with the 
proposed change is here:

http://cr.openjdk.java.net/~alanb/8014928/webrev/

Thanks,
Alan.


More information about the nio-dev mailing list