RFR [8020669] java.nio.file.Files.readAllBytes() does not read any data when Files.size() is 0

Christos Zoulas christos at zoulas.com
Tue Jul 23 17:21:08 UTC 2013


On Jul 23, 10:43am, david.lloyd at redhat.com ("David M. Lloyd") wrote:
-- Subject: Re: RFR [8020669] java.nio.file.Files.readAllBytes() does not rea

| > 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).

I guess one can always use a multiple of:

           blksize_t   st_blksize   preferred I/O block size (fs-specific)

And if 0/unavailable, a multiple of page size. Letting the array grow too
big will end up hurting performance anyway.

christos



More information about the core-libs-dev mailing list