Two issues in Files
Colin Decker
cgdecker at google.com
Thu Sep 12 16:37:48 PDT 2013
On Thu, Sep 12, 2013 at 10:17 AM, Alan Bateman <Alan.Bateman at oracle.com>wrote:
> As I see it, if something like that is needed, it seems like the
>> OutputStream implementation should be doing the slicing. Giving the whole
>> array to the OutputStream gives it the best opportunity to do what works
>> best for the implementation.
>>
> Maybe but it brings up again the issue that OutputStream.write may fail
> after having successfully written some bytes. That's not a concern for
> Files.write of course as it covers this case but this may require
> re-visiting the OutputStream spec and of course implementation changes to
> consume less resources when writing big arrays.
As for OutputStream.write failing after successfully writing some bytes:
that's going to be true regardless of whether you're passing an array to
write in slices or all at once, right? It could still fail at any point in
that process.
And if some OutputStream implementations do work better (creating less
memory overhead) when written in slices of array rather than when given a
big array up front, that definitely seems like something that might be good
to fix in those implementations, given that they can always implement
write(byte[]) to do the looping and writing slices itself. And while
Files.write doesn't pass the whole byte array to the OutputStream, users
can do that directly. Anyway, it's not that big a deal as the performance
difference is probably pretty minimal, it just seemed odd.
- Colin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20130912/62b36ca0/attachment.html
More information about the nio-dev
mailing list