Skip to content

Commit d8b4807

Browse files
committed
Merge branch 'pr-336'
This closes #336
2 parents c7cb67f + ef1ae84 commit d8b4807

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ The <action> type attribute can be add,update,fix,remove.
4747
<body>
4848
<release version="2.12.0" date="2021-MM-DD" description="Java 8 required.">
4949
<!-- FIX -->
50+
<action issue="IO-697" dev="kinow" type="fix" due-to="otter606">
51+
IOUtils.toByteArray size validation does not match documentation.
52+
</action>
5053
<action dev="ggregory" type="fix" due-to="Gary Gregory">
5154
Fix Javadoc links to the JRE Javadoc 8.
5255
</action>

src/main/java/org/apache/commons/io/IOUtils.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,13 +2497,13 @@ public static byte[] toByteArray(final InputStream inputStream) throws IOExcepti
24972497

24982498
/**
24992499
* Gets the contents of an {@code InputStream} as a {@code byte[]}. Use this method instead of
2500-
* {@code toByteArray(InputStream)} when {@code InputStream} size is known
2500+
* {@code toByteArray(InputStream)} when {@code InputStream} size is known.
25012501
*
25022502
* @param input the {@code InputStream} to read.
2503-
* @param size the size of {@code InputStream}.
2504-
* @return the requested byte array.
2505-
* @throws IOException if an I/O error occurs or {@code InputStream} size differ from parameter size.
2506-
* @throws IllegalArgumentException if size is less than zero.
2503+
* @param size the size of {@code InputStream} to read, where 0 &lt; {@code size} &lt;= length of input stream.
2504+
* @return byte [] of length {@code size}.
2505+
* @throws IOException if an I/O error occurs or {@code InputStream} length is smaller than parameter {@code size}.
2506+
* @throws IllegalArgumentException if {@code size} is less than zero.
25072507
* @since 2.1
25082508
*/
25092509
public static byte[] toByteArray(final InputStream input, final int size) throws IOException {
@@ -2540,10 +2540,9 @@ public static byte[] toByteArray(final InputStream input, final int size) throws
25402540
* (Arrays can have no more than Integer.MAX_VALUE entries anyway)
25412541
*
25422542
* @param input the {@code InputStream} to read from
2543-
* @param size the size of {@code InputStream}
2544-
* @return the requested byte array
2545-
* @throws IOException if an I/O error occurs or {@code InputStream} size differ from parameter
2546-
* size
2543+
* @param size the size of {@code InputStream} to read, where 0 &lt; {@code size} &lt;= min(Integer.MAX_VALUE, length of input stream).
2544+
* @return byte [] the requested byte array, of length {@code size}
2545+
* @throws IOException if an I/O error occurs or {@code InputStream} length is less than {@code size}
25472546
* @throws IllegalArgumentException if size is less than zero or size is greater than Integer.MAX_VALUE
25482547
* @see IOUtils#toByteArray(java.io.InputStream, int)
25492548
* @since 2.1

0 commit comments

Comments
 (0)