@@ -223,16 +223,14 @@ public class IOUtils {
223223
224224 /**
225225 * The maximum size of an array in many Java VMs.
226+ * <p>
227+ * The constant is copied from OpenJDK's {@link jdk.internal.util.ArraysSupport#SOFT_MAX_ARRAY_LENGTH}.
228+ * </p>
226229 */
227- private static final int MAX_ARRAY_LENGTH = Integer .MAX_VALUE - 8 ;
230+ private static final int SOFT_MAX_ARRAY_LENGTH = Integer .MAX_VALUE - 8 ;
228231
229232 /*
230233 * Default maximum chunk size used when copying large streams into a byte array.
231- * <p>
232- * This value is somewhat arbitrary, currently aligned with the value used by
233- * <a href="https://github.com/python/cpython/blob/3.14/Lib/_pyio.py">Python</a>
234- * for copying streams.
235- * </p>
236234 */
237235 private static final int DEFAULT_CHUNK_SIZE = 128 * 1024 ;
238236
@@ -2666,10 +2664,10 @@ public static BufferedReader toBufferedReader(final Reader reader, final int siz
26662664 */
26672665 public static byte [] toByteArray (final InputStream inputStream ) throws IOException {
26682666 final UnsynchronizedByteArrayOutputStream output =
2669- copyToOutputStream (inputStream , MAX_ARRAY_LENGTH + 1 , DEFAULT_CHUNK_SIZE );
2670- if (output .size () > MAX_ARRAY_LENGTH ) {
2667+ copyToOutputStream (inputStream , SOFT_MAX_ARRAY_LENGTH + 1 , DEFAULT_CHUNK_SIZE );
2668+ if (output .size () > SOFT_MAX_ARRAY_LENGTH ) {
26712669 throw new IllegalArgumentException (
2672- String .format ("Cannot read more than %,d into a byte array" , MAX_ARRAY_LENGTH ));
2670+ String .format ("Cannot read more than %,d into a byte array" , SOFT_MAX_ARRAY_LENGTH ));
26732671 }
26742672 return output .toByteArray ();
26752673 }
0 commit comments