RFR  java.nio.file.Files.readAllBytes() does not read any data when Files.size() is 0
David M. Lloyd
david.lloyd at redhat.com
Tue Jul 23 15:43:33 UTC 2013
On 07/23/2013 10:31 AM, Christos Zoulas wrote:
> On Jul 22, 11:58am, martinrb at google.com (Martin Buchholz) wrote:
> -- Subject: Re: RFR  java.nio.file.Files.readAllBytes() does not rea
> | It's the OS/filesystem implementer deciding to return a bogus number.
> | More accurate would be to count by reading all the bytes, but that is
> | impractical and/or impossible (e.g. don't try reading "all the bytes" from
> | /dev/null)
> | A middle ground would be to mistrust specifically file sizes of zero,
> | testing via
> | int c = read()
> | but then what? Check for /proc bug on Linux?
> The only sure way to read all the data from a file in Unix is to attempt
> to read(2) until it returns 0 (or -1 on error). If you think you can trust
> the size stat(2) returns what does it return for /dev/zero? :-)
Indeed, that's a good point. It would probably be a good idea to
provide a variant that specifies a hard maximum number of bytes
(something less than 2GB anyway - the only thing worse than failing to
allocate such a large array is *succeeding* in allocating such a large
array when you don't want it).
More information about the core-libs-dev