RFR [8020669] java.nio.file.Files.readAllBytes() does not read any data when Files.size() is 0
Ivan Gerasimov
ivan.gerasimov at oracle.com
Fri Jul 19 17:15:02 UTC 2013
Hello everybody!
Would you please review a fix for the problem with
j.n.f.Files.readAllBytes() function?
The current implementation relies on FileChannel.size() to preallocate a
buffer for the whole file's content.
However, some special filesystems can report a wrong size.
An example is procfs under Linux, which reports many files under /proc
to be zero sized.
Thus it is proposed not to rely on the size() and instead continuously
read until EOF.
The downside is reallocation and copying file content between buffers.
But taking into account that the doc says: "It is not intended for
reading in large files." it should not be a big problem.
http://bugs.sun.com/view_bug.do?bug_id=8020669
http://cr.openjdk.java.net/~igerasim/8020669/0/webrev/
The fix is for JDK8. If it is approved, it can be applied to JDK7 as well.
Sincerely yours,
Ivan Gerasimov
More information about the core-libs-dev
mailing list