You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "scottyg (Jira)" <ji...@apache.org> on 2021/01/05 00:01:00 UTC
[jira] [Commented] (IO-697) IOUtils.toByteArray size validation
does not match documenation.
[ https://issues.apache.org/jira/browse/IO-697?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17258590#comment-17258590 ]
scottyg commented on IO-697:
----------------------------
p/r https://github.cerner.com/mp-doc-results/ce-blob-reactor/pull/146
> IOUtils.toByteArray size validation does not match documenation.
> ----------------------------------------------------------------
>
> Key: IO-697
> URL: https://issues.apache.org/jira/browse/IO-697
> Project: Commons IO
> Issue Type: Bug
> Affects Versions: 2.8.0
> Reporter: scottyg
> Priority: Major
>
> According to the javadoc, "throws IOException ... or InputStream size differ from parameter size.
> I read that as the passed in parameter size must exactly match the length of data represented by the InputStream. However, the current implementation will:
> * Throw an exception if size parameter is larger than the InputStream
> * Work as expected if size parameter matches size of InputStream
> * *Return a byte array only containing up-to size parameter when InputStream is larger than size parameter. No exception is thrown*.
> What is the actual intention of the method? What the javadoc says, or what the implementation is currently doing?
>
> {code:java}
> /**
> * Gets the contents of an <code>InputStream</code> as a <code>byte[]</code>.
> * Use this method instead of <code>toByteArray(InputStream)</code>
> * when <code>InputStream</code> size is known
> *
> * @param input the <code>InputStream</code> to read from
> * @param size the size of <code>InputStream</code>
> * @return the requested byte array
> * @throws IOException if an I/O error occurs or <code>InputStream</code> size differ from parameter
> * size
> * @throws IllegalArgumentException if size is less than zero
> * @since 2.1
> */
> public static byte[] toByteArray(final InputStream input, final int size) throws IOException {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)