What do you suggest instead? The extra allocation of a zero-size buffer is not that bad.
I think it's best to optimize for files with correct metadata, while tolerating ones with buggy metadata. On Thu, Jul 28, 2016 at 1:13 PM, Fabian Lange <lange.fab...@gmail.com> wrote: > Hi, > I just noticed that when one uses Files.readAllBytes() to read for > example from the Linux proc file system, where file size is claimed to > be 0, Files.read() will allocate a buffer of size 0 before then > adjusting in a second loop (arraycopying the zero size buffer) > > In my opinion an initial size of 0 should not be used. > I admit this might be a regression for files which are really empty > and return an empty byte array, but I think it is actually more common > to read from files which incorrectly report to be zero sized. > > Fabian >