[ https://issues.apache.org/jira/browse/IO-697?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Bruno P. Kinoshita resolved IO-697. ----------------------------------- Resolution: Fixed > 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 > Assignee: Bruno P. Kinoshita > Priority: Major > Fix For: 2.12.0 > > > 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.20.1#820001)