@@ -2898,15 +2898,16 @@ public static byte[] toByteArray(final InputStream input, final int size) throws
28982898 public static byte [] toByteArray (final InputStream input , final int size , final int chunkSize ) throws IOException {
28992899 Objects .requireNonNull (input , "input" );
29002900 if (chunkSize <= 0 ) {
2901- throw new IllegalArgumentException ("Chunk size must be greater than zero: " + chunkSize );
2901+ throw new IllegalArgumentException (String . format ( "chunkSize <= 0, chunkSize = %,d" , chunkSize ) );
29022902 }
29032903 if (size <= chunkSize ) {
29042904 // throws if size < 0
29052905 return toByteArray (input ::read , size );
29062906 }
29072907 final UnsynchronizedByteArrayOutputStream output = copyToOutputStream (input , size , chunkSize );
2908- if (output .size () != size ) {
2909- throw new EOFException ("Unexpected read size, current: " + output .size () + ", expected: " + size );
2908+ final int outSize = output .size ();
2909+ if (outSize != size ) {
2910+ throw new EOFException (String .format ("Expected read size: %,d, actual: %,d" , size , outSize ));
29102911 }
29112912 return output .toByteArray ();
29122913 }
@@ -2930,7 +2931,7 @@ public static byte[] toByteArray(final InputStream input, final int size, final
29302931 */
29312932 public static byte [] toByteArray (final InputStream input , final long size ) throws IOException {
29322933 if (size > Integer .MAX_VALUE ) {
2933- throw new IllegalArgumentException ("Size cannot be greater than Integer max value: " + size );
2934+ throw new IllegalArgumentException (String . format ( "size > Integer.MAX_VALUE, size = %,d" , size ) );
29342935 }
29352936 return toByteArray (input , (int ) size );
29362937 }
@@ -2947,7 +2948,7 @@ public static byte[] toByteArray(final InputStream input, final long size) throw
29472948 */
29482949 static byte [] toByteArray (final IOTriFunction <byte [], Integer , Integer , Integer > input , final int size ) throws IOException {
29492950 if (size < 0 ) {
2950- throw new IllegalArgumentException ("Size must be equal or greater than zero: " + size );
2951+ throw new IllegalArgumentException (String . format ( "size < 0, size = %,d" , size ) );
29512952 }
29522953 if (size == 0 ) {
29532954 return EMPTY_BYTE_ARRAY ;
@@ -2959,7 +2960,7 @@ static byte[] toByteArray(final IOTriFunction<byte[], Integer, Integer, Integer>
29592960 offset += read ;
29602961 }
29612962 if (offset != size ) {
2962- throw new EOFException ("Unexpected read size, current: " + offset + ", expected: " + size );
2963+ throw new EOFException (String . format ( "Expected read size: %,d, actual: %,d" , size , offset ) );
29632964 }
29642965 return data ;
29652966 }
0 commit comments