[
https://issues.apache.org/jira/browse/IO-251?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16071630#comment-16071630
]
ASF GitHub Bot commented on IO-251:
-----------------------------------
GitHub user ilmarmors opened a pull request:
https://github.com/apache/commons-io/pull/38
FileUtils.readFileToByteArray - optimize reading of files with known size
IO-251 added optimization for reading files with known size as byte arrays,
but it was reverted in IO-453 due to regression, because File.length() method
may return 0 for path files denoting system-dependent entities such as devices
or pipes
More optimal solution is to treat 0 as unknown size, but if size is known
(> 0) use more efficient approach and read content into pre-allocated byte
array with exact size.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/ilmarmors/commons-io master
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/commons-io/pull/38.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #38
----
commit 3ce13884f3b2d78c6ca6cbf9a85c240c6b6532c3
Author: Ilmars Poikans <[email protected]>
Date: 2017-07-02T13:01:23Z
FileUtils.readFileToByteArray - optimize reading of files with known size
----
> Add new read method "toByteArray" to handle InputStream with known size
> -----------------------------------------------------------------------
>
> Key: IO-251
> URL: https://issues.apache.org/jira/browse/IO-251
> Project: Commons IO
> Issue Type: Improvement
> Components: Utilities
> Affects Versions: 1.4
> Reporter: Marco Albini
> Priority: Minor
> Fix For: 2.1
>
> Attachments: IO-251_toByteArray.patch
>
>
> I suggest adding a new method toByteArray(InputStream input, int size) to
> IoUtils to handle known size InputStream (e.g. files).
> Current implementation based on copy method consumes more memory than
> necessary (at least the double) to transform a InputStream into a byte array.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)