garydgregory commented on code in PR #785:
URL: https://github.com/apache/commons-io/pull/785#discussion_r2368447608
##########
src/main/java/org/apache/commons/io/IOUtils.java:
##########
@@ -2680,15 +2680,14 @@ public static BufferedReader toBufferedReader(final
Reader reader, final int siz
*
* @param inputStream The {@link InputStream} to read; must not be {@code
null}.
* @return A new byte array.
- * @throws IllegalArgumentException If the size of the stream is greater
than the maximum array size.
- * @throws IOException If an I/O error occurs while reading.
+ * @throws IOException If an I/O error occurs while reading
or if the maximum array size is exceeded.
* @throws NullPointerException If {@code inputStream} is {@code null}.
*/
public static byte[] toByteArray(final InputStream inputStream) throws
IOException {
// Using SOFT_MAX_ARRAY_LENGTH guarantees that size() will not overflow
final UnsynchronizedByteArrayOutputStream output =
copyToOutputStream(inputStream, SOFT_MAX_ARRAY_LENGTH + 1, DEFAULT_BUFFER_SIZE);
if (output.size() > SOFT_MAX_ARRAY_LENGTH) {
- throw new IllegalArgumentException(String.format("Cannot read more
than %,d into a byte array", SOFT_MAX_ARRAY_LENGTH));
+ throw new IOException(String.format("Cannot read more than %,d
into a byte array", SOFT_MAX_ARRAY_LENGTH));
Review Comment:
@ppkarwasz
Is it worth also testing
```java
if (inputStream instanceof FileInputStream && ((FileInputStream)
inputStream).getChannel().size() > SOFT_MAX_ARRAY_LENGTH`) {
throw new IllegalArgumentException(...);
}
```
_before_ we call `copyToOutputStream()` ?
The above would be justified in an `IllegalArgumentException`. WDYT? Is that
too specific?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]