@@ -2640,9 +2640,6 @@ public static BufferedReader toBufferedReader(final Reader reader, final int siz
26402640 /**
26412641 * Reads all remaining bytes from the given {@link InputStream} into a new {@code byte[]}.
26422642 *
2643- * <p>The method accumulates the data in temporary buffers and returns a single array
2644- * containing the entire contents once the end of the stream is reached.</p>
2645- *
26462643 * @param inputStream the {@link InputStream} to read; must not be {@code null}.
26472644 * @return a new byte array.
26482645 * @throws IllegalArgumentException if the size of the stream is greater than {@code Integer.MAX_VALUE}.
@@ -2663,9 +2660,6 @@ public static byte[] toByteArray(final InputStream inputStream) throws IOExcepti
26632660 /**
26642661 * Reads exactly {@code size} bytes from the given {@link InputStream} into a new {@code byte[]}.
26652662 *
2666- * <p>The method allocates a single array of the requested size and fills it directly
2667- * from the stream.</p>
2668- *
26692663 * @param input the {@link InputStream} to read; must not be {@code null}.
26702664 * @param size the exact number of bytes to read; must be {@code >= 0}.
26712665 * @return a new byte array of length {@code size}.
@@ -2682,9 +2676,6 @@ public static byte[] toByteArray(final InputStream input, final int size) throws
26822676 /**
26832677 * Reads exactly {@code size} bytes from the given {@link InputStream} into a new {@code byte[]}.
26842678 *
2685- * <p>The method allocates a single array of the requested size and fills it directly
2686- * from the stream.</p>
2687- *
26882679 * @param input the {@link InputStream} to read; must not be {@code null}.
26892680 * @param size the exact number of bytes to read; must be {@code >= 0} and {@code <= Integer.MAX_VALUE}.
26902681 * @return a new byte array of length {@code size}.
@@ -2705,8 +2696,12 @@ public static byte[] toByteArray(final InputStream input, final long size) throw
27052696 /**
27062697 * Reads exactly {@code size} bytes from the given {@link InputStream} into a new {@code byte[]}.
27072698 *
2708- * <p>The method accumulates the data in temporary buffers of size at most {@code bufferSize}
2709- * and returns a single array containing the entire contents once the end of the stream is reached.</p>
2699+ * <p>When reading from an untrusted stream, this variant lowers the risk of
2700+ * {@link OutOfMemoryError} by allocating data in buffers of up to {@code bufferSize}
2701+ * bytes rather than in one large array.</p>
2702+ *
2703+ * <p>Note, however, that this approach requires additional temporary memory
2704+ * compared to {@link #toByteArray(InputStream, int)}.</p>
27102705 *
27112706 * @param input the {@link InputStream} to read; must not be {@code null}.
27122707 * @param size the exact number of bytes to read; must be {@code >= 0}.
0 commit comments