@@ -683,13 +683,10 @@ void testConsumeReader() throws Exception {
683683 final long size = (long ) Integer .MAX_VALUE + (long ) 1 ;
684684 final Reader in = new NullReader (size );
685685 final Writer out = NullWriter .INSTANCE ;
686-
687686 // Test copy() method
688687 assertEquals (-1 , IOUtils .copy (in , out ));
689-
690688 // reset the input
691689 in .close ();
692-
693690 // Test consume() method
694691 assertEquals (size , IOUtils .consume (in ), "consume()" );
695692 }
@@ -913,12 +910,9 @@ void testCopy_ByteArray_OutputStream() throws Exception {
913910 // Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid.
914911 in = IOUtils .toByteArray (fin );
915912 }
916-
917913 try (OutputStream fout = Files .newOutputStream (destination .toPath ())) {
918914 CopyUtils .copy (in , fout );
919-
920915 fout .flush ();
921-
922916 TestUtils .checkFile (destination , testFile );
923917 TestUtils .checkWrite (fout );
924918 }
@@ -933,7 +927,6 @@ void testCopy_ByteArray_Writer() throws Exception {
933927 // Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid.
934928 in = IOUtils .toByteArray (fin );
935929 }
936-
937930 try (Writer fout = Files .newBufferedWriter (destination .toPath ())) {
938931 CopyUtils .copy (in , fout );
939932 fout .flush ();
@@ -951,11 +944,9 @@ void testCopy_String_Writer() throws Exception {
951944 // Create our String. Rely on testReaderToString() to make sure this is valid.
952945 str = IOUtils .toString (fin );
953946 }
954-
955947 try (Writer fout = Files .newBufferedWriter (destination .toPath ())) {
956948 CopyUtils .copy (str , fout );
957949 fout .flush ();
958-
959950 TestUtils .checkFile (destination , testFile );
960951 TestUtils .checkWrite (fout );
961952 }
@@ -970,19 +961,16 @@ void testCopyLarge_CharExtraLength() throws IOException {
970961 // Create streams
971962 is = new CharArrayReader (carr );
972963 os = new CharArrayWriter ();
973-
974964 // Test our copy method
975965 // for extra length, it reads till EOF
976966 assertEquals (200 , IOUtils .copyLarge (is , os , 0 , 2000 ));
977967 final char [] oarr = os .toCharArray ();
978-
979968 // check that output length is correct
980969 assertEquals (200 , oarr .length );
981970 // check that output data corresponds to input data
982971 assertEquals (1 , oarr [1 ]);
983972 assertEquals (79 , oarr [79 ]);
984973 assertEquals ((char ) -1 , oarr [80 ]);
985-
986974 } finally {
987975 IOUtils .closeQuietly (is );
988976 IOUtils .closeQuietly (os );
@@ -997,18 +985,15 @@ void testCopyLarge_CharFullLength() throws IOException {
997985 // Create streams
998986 is = new CharArrayReader (carr );
999987 os = new CharArrayWriter ();
1000-
1001988 // Test our copy method
1002989 assertEquals (200 , IOUtils .copyLarge (is , os , 0 , -1 ));
1003990 final char [] oarr = os .toCharArray ();
1004-
1005991 // check that output length is correct
1006992 assertEquals (200 , oarr .length );
1007993 // check that output data corresponds to input data
1008994 assertEquals (1 , oarr [1 ]);
1009995 assertEquals (79 , oarr [79 ]);
1010996 assertEquals ((char ) -1 , oarr [80 ]);
1011-
1012997 } finally {
1013998 IOUtils .closeQuietly (is );
1014999 IOUtils .closeQuietly (os );
@@ -1023,18 +1008,15 @@ void testCopyLarge_CharNoSkip() throws IOException {
10231008 // Create streams
10241009 is = new CharArrayReader (carr );
10251010 os = new CharArrayWriter ();
1026-
10271011 // Test our copy method
10281012 assertEquals (100 , IOUtils .copyLarge (is , os , 0 , 100 ));
10291013 final char [] oarr = os .toCharArray ();
1030-
10311014 // check that output length is correct
10321015 assertEquals (100 , oarr .length );
10331016 // check that output data corresponds to input data
10341017 assertEquals (1 , oarr [1 ]);
10351018 assertEquals (79 , oarr [79 ]);
10361019 assertEquals ((char ) -1 , oarr [80 ]);
1037-
10381020 } finally {
10391021 IOUtils .closeQuietly (is );
10401022 IOUtils .closeQuietly (os );
@@ -1049,18 +1031,15 @@ void testCopyLarge_CharSkip() throws IOException {
10491031 // Create streams
10501032 is = new CharArrayReader (carr );
10511033 os = new CharArrayWriter ();
1052-
10531034 // Test our copy method
10541035 assertEquals (100 , IOUtils .copyLarge (is , os , 10 , 100 ));
10551036 final char [] oarr = os .toCharArray ();
1056-
10571037 // check that output length is correct
10581038 assertEquals (100 , oarr .length );
10591039 // check that output data corresponds to input data
10601040 assertEquals (11 , oarr [1 ]);
10611041 assertEquals (79 , oarr [69 ]);
10621042 assertEquals ((char ) -1 , oarr [70 ]);
1063-
10641043 } finally {
10651044 IOUtils .closeQuietly (is );
10661045 IOUtils .closeQuietly (os );
@@ -1076,15 +1055,12 @@ void testCopyLarge_CharSkipInvalid() {
10761055
10771056 @ Test
10781057 void testCopyLarge_ExtraLength () throws IOException {
1079- try (ByteArrayInputStream is = new ByteArrayInputStream (iarr );
1080- ByteArrayOutputStream os = new ByteArrayOutputStream ()) {
1058+ try (ByteArrayInputStream is = new ByteArrayInputStream (iarr ); ByteArrayOutputStream os = new ByteArrayOutputStream ()) {
10811059 // Create streams
1082-
10831060 // Test our copy method
10841061 // for extra length, it reads till EOF
10851062 assertEquals (200 , IOUtils .copyLarge (is , os , 0 , 2000 ));
10861063 final byte [] oarr = os .toByteArray ();
1087-
10881064 // check that output length is correct
10891065 assertEquals (200 , oarr .length );
10901066 // check that output data corresponds to input data
@@ -1096,12 +1072,10 @@ void testCopyLarge_ExtraLength() throws IOException {
10961072
10971073 @ Test
10981074 void testCopyLarge_FullLength () throws IOException {
1099- try (ByteArrayInputStream is = new ByteArrayInputStream (iarr );
1100- ByteArrayOutputStream os = new ByteArrayOutputStream ()) {
1075+ try (ByteArrayInputStream is = new ByteArrayInputStream (iarr ); ByteArrayOutputStream os = new ByteArrayOutputStream ()) {
11011076 // Test our copy method
11021077 assertEquals (200 , IOUtils .copyLarge (is , os , 0 , -1 ));
11031078 final byte [] oarr = os .toByteArray ();
1104-
11051079 // check that output length is correct
11061080 assertEquals (200 , oarr .length );
11071081 // check that output data corresponds to input data
@@ -1113,12 +1087,10 @@ void testCopyLarge_FullLength() throws IOException {
11131087
11141088 @ Test
11151089 void testCopyLarge_NoSkip () throws IOException {
1116- try (ByteArrayInputStream is = new ByteArrayInputStream (iarr );
1117- ByteArrayOutputStream os = new ByteArrayOutputStream ()) {
1090+ try (ByteArrayInputStream is = new ByteArrayInputStream (iarr ); ByteArrayOutputStream os = new ByteArrayOutputStream ()) {
11181091 // Test our copy method
11191092 assertEquals (100 , IOUtils .copyLarge (is , os , 0 , 100 ));
11201093 final byte [] oarr = os .toByteArray ();
1121-
11221094 // check that output length is correct
11231095 assertEquals (100 , oarr .length );
11241096 // check that output data corresponds to input data
@@ -1130,12 +1102,10 @@ void testCopyLarge_NoSkip() throws IOException {
11301102
11311103 @ Test
11321104 void testCopyLarge_Skip () throws IOException {
1133- try (ByteArrayInputStream is = new ByteArrayInputStream (iarr );
1134- ByteArrayOutputStream os = new ByteArrayOutputStream ()) {
1105+ try (ByteArrayInputStream is = new ByteArrayInputStream (iarr ); ByteArrayOutputStream os = new ByteArrayOutputStream ()) {
11351106 // Test our copy method
11361107 assertEquals (100 , IOUtils .copyLarge (is , os , 10 , 100 ));
11371108 final byte [] oarr = os .toByteArray ();
1138-
11391109 // check that output length is correct
11401110 assertEquals (100 , oarr .length );
11411111 // check that output data corresponds to input data
@@ -1162,18 +1132,15 @@ void testCopyLarge_SkipWithInvalidOffset() throws IOException {
11621132 // Create streams
11631133 is = new ByteArrayInputStream (iarr );
11641134 os = new ByteArrayOutputStream ();
1165-
11661135 // Test our copy method
11671136 assertEquals (100 , IOUtils .copyLarge (is , os , -10 , 100 ));
11681137 final byte [] oarr = os .toByteArray ();
1169-
11701138 // check that output length is correct
11711139 assertEquals (100 , oarr .length );
11721140 // check that output data corresponds to input data
11731141 assertEquals (1 , oarr [1 ]);
11741142 assertEquals (79 , oarr [79 ]);
11751143 assertEquals (-1 , oarr [80 ]);
1176-
11771144 } finally {
11781145 IOUtils .closeQuietly (is );
11791146 IOUtils .closeQuietly (os );
@@ -1191,7 +1158,7 @@ void testRead_ReadableByteChannel() throws Exception {
11911158 assertEquals (0 , buffer .remaining ());
11921159 assertEquals (0 , input .read (buffer ));
11931160 buffer .clear ();
1194- assertThrows (EOFException .class , () -> IOUtils .readFully (input , buffer ), "Should have failed with EOFException" );
1161+ assertThrows (EOFException .class , () -> IOUtils .readFully (input , buffer ));
11951162 } finally {
11961163 IOUtils .closeQuietly (input , fileInputStream );
11971164 }
@@ -1226,11 +1193,8 @@ void testRead_InputStream_Offset_ArgumentsValidation(InputStream input, byte[] b
12261193 void testReadFully_InputStream__ReturnByteArray () throws Exception {
12271194 final byte [] bytes = "abcd1234" .getBytes (StandardCharsets .UTF_8 );
12281195 final ByteArrayInputStream stream = new ByteArrayInputStream (bytes );
1229-
12301196 final byte [] result = IOUtils .readFully (stream , bytes .length );
1231-
12321197 IOUtils .closeQuietly (stream );
1233-
12341198 assertEqualContent (result , bytes );
12351199 }
12361200
@@ -1240,11 +1204,11 @@ void testReadFully_InputStream_ByteArray() throws Exception {
12401204 final byte [] buffer = new byte [size ];
12411205 final InputStream input = new ByteArrayInputStream (new byte [size ]);
12421206
1243- assertThrows (IndexOutOfBoundsException .class , () -> IOUtils .readFully (input , buffer , 0 , -1 ), "Should have failed with IndexOutOfBoundsException" );
1207+ assertThrows (IndexOutOfBoundsException .class , () -> IOUtils .readFully (input , buffer , 0 , -1 ));
12441208
12451209 IOUtils .readFully (input , buffer , 0 , 0 );
12461210 IOUtils .readFully (input , buffer , 0 , size - 1 );
1247- assertThrows (EOFException .class , () -> IOUtils .readFully (input , buffer , 0 , 2 ), "Should have failed with EOFException" );
1211+ assertThrows (EOFException .class , () -> IOUtils .readFully (input , buffer , 0 , 2 ));
12481212 IOUtils .closeQuietly (input );
12491213 }
12501214
@@ -1273,7 +1237,7 @@ void testReadFully_ReadableByteChannel() throws Exception {
12731237 assertEquals (0 , input .read (buffer ));
12741238 IOUtils .readFully (input , buffer );
12751239 buffer .clear ();
1276- assertThrows (EOFException .class , () -> IOUtils .readFully (input , buffer ), "Should have failed with EOFxception" );
1240+ assertThrows (EOFException .class , () -> IOUtils .readFully (input , buffer ));
12771241 } finally {
12781242 IOUtils .closeQuietly (input , fileInputStream );
12791243 }
@@ -1287,8 +1251,8 @@ void testReadFully_Reader() throws Exception {
12871251
12881252 IOUtils .readFully (input , buffer , 0 , 0 );
12891253 IOUtils .readFully (input , buffer , 0 , size - 3 );
1290- assertThrows (IndexOutOfBoundsException .class , () -> IOUtils .readFully (input , buffer , 0 , -1 ), "Should have failed with IndexOutOfBoundsException" );
1291- assertThrows (EOFException .class , () -> IOUtils .readFully (input , buffer , 0 , 5 ), "Should have failed with EOFException" );
1254+ assertThrows (IndexOutOfBoundsException .class , () -> IOUtils .readFully (input , buffer , 0 , -1 ));
1255+ assertThrows (EOFException .class , () -> IOUtils .readFully (input , buffer , 0 , 5 ));
12921256 IOUtils .closeQuietly (input );
12931257 }
12941258
@@ -1628,13 +1592,11 @@ void testSkip_ReadableByteChannel() throws Exception {
16281592 @ Test
16291593 void testSkipFully_InputStream () throws Exception {
16301594 final int size = 1027 ;
1631-
16321595 try (InputStream input = new ByteArrayInputStream (new byte [size ])) {
1633- assertThrows (IllegalArgumentException .class , () -> IOUtils .skipFully (input , -1 ), "Should have failed with IllegalArgumentException" );
1634-
1596+ assertThrows (IllegalArgumentException .class , () -> IOUtils .skipFully (input , -1 ));
16351597 IOUtils .skipFully (input , 0 );
16361598 IOUtils .skipFully (input , size - 1 );
1637- assertThrows (IOException .class , () -> IOUtils .skipFully (input , 2 ), "Should have failed with IOException" );
1599+ assertThrows (IOException .class , () -> IOUtils .skipFully (input , 2 ));
16381600 }
16391601 }
16401602
@@ -1643,11 +1605,10 @@ void testSkipFully_InputStream_Buffer_New_bytes() throws Exception {
16431605 final int size = 1027 ;
16441606 final Supplier <byte []> bas = () -> new byte [size ];
16451607 try (InputStream input = new ByteArrayInputStream (new byte [size ])) {
1646- assertThrows (IllegalArgumentException .class , () -> IOUtils .skipFully (input , -1 , bas ), "Should have failed with IllegalArgumentException" );
1647-
1608+ assertThrows (IllegalArgumentException .class , () -> IOUtils .skipFully (input , -1 , bas ));
16481609 IOUtils .skipFully (input , 0 , bas );
16491610 IOUtils .skipFully (input , size - 1 , bas );
1650- assertThrows (IOException .class , () -> IOUtils .skipFully (input , 2 , bas ), "Should have failed with IOException" );
1611+ assertThrows (IOException .class , () -> IOUtils .skipFully (input , 2 , bas ));
16511612 }
16521613 }
16531614
@@ -1657,11 +1618,10 @@ void testSkipFully_InputStream_Buffer_Reuse_bytes() throws Exception {
16571618 final byte [] ba = new byte [size ];
16581619 final Supplier <byte []> bas = () -> ba ;
16591620 try (InputStream input = new ByteArrayInputStream (new byte [size ])) {
1660- assertThrows (IllegalArgumentException .class , () -> IOUtils .skipFully (input , -1 , bas ), "Should have failed with IllegalArgumentException" );
1661-
1621+ assertThrows (IllegalArgumentException .class , () -> IOUtils .skipFully (input , -1 , bas ));
16621622 IOUtils .skipFully (input , 0 , bas );
16631623 IOUtils .skipFully (input , size - 1 , bas );
1664- assertThrows (IOException .class , () -> IOUtils .skipFully (input , 2 , bas ), "Should have failed with IOException" );
1624+ assertThrows (IOException .class , () -> IOUtils .skipFully (input , 2 , bas ));
16651625 }
16661626 }
16671627
@@ -1670,11 +1630,10 @@ void testSkipFully_InputStream_Buffer_Reuse_ThreadLocal() throws Exception {
16701630 final int size = 1027 ;
16711631 final ThreadLocal <byte []> tl = ThreadLocal .withInitial (() -> new byte [size ]);
16721632 try (InputStream input = new ByteArrayInputStream (new byte [size ])) {
1673- assertThrows (IllegalArgumentException .class , () -> IOUtils .skipFully (input , -1 , tl ::get ), "Should have failed with IllegalArgumentException" );
1674-
1633+ assertThrows (IllegalArgumentException .class , () -> IOUtils .skipFully (input , -1 , tl ::get ));
16751634 IOUtils .skipFully (input , 0 , tl ::get );
16761635 IOUtils .skipFully (input , size - 1 , tl ::get );
1677- assertThrows (IOException .class , () -> IOUtils .skipFully (input , 2 , tl ::get ), "Should have failed with IOException" );
1636+ assertThrows (IOException .class , () -> IOUtils .skipFully (input , 2 , tl ::get ));
16781637 }
16791638 }
16801639
@@ -1683,10 +1642,10 @@ void testSkipFully_ReadableByteChannel() throws Exception {
16831642 final FileInputStream fileInputStream = new FileInputStream (testFile );
16841643 final FileChannel fileChannel = fileInputStream .getChannel ();
16851644 try {
1686- assertThrows (IllegalArgumentException .class , () -> IOUtils .skipFully (fileChannel , -1 ), "Should have failed with IllegalArgumentException" );
1645+ assertThrows (IllegalArgumentException .class , () -> IOUtils .skipFully (fileChannel , -1 ));
16871646 IOUtils .skipFully (fileChannel , 0 );
16881647 IOUtils .skipFully (fileChannel , FILE_SIZE - 1 );
1689- assertThrows (IOException .class , () -> IOUtils .skipFully (fileChannel , 2 ), "Should have failed with IOException" );
1648+ assertThrows (IOException .class , () -> IOUtils .skipFully (fileChannel , 2 ));
16901649 } finally {
16911650 IOUtils .closeQuietly (fileChannel , fileInputStream );
16921651 }
@@ -1698,8 +1657,8 @@ void testSkipFully_Reader() throws Exception {
16981657 try (Reader input = new CharArrayReader (new char [size ])) {
16991658 IOUtils .skipFully (input , 0 );
17001659 IOUtils .skipFully (input , size - 3 );
1701- assertThrows (IllegalArgumentException .class , () -> IOUtils .skipFully (input , -1 ), "Should have failed with IllegalArgumentException" );
1702- assertThrows (IOException .class , () -> IOUtils .skipFully (input , 5 ), "Should have failed with IOException" );
1660+ assertThrows (IllegalArgumentException .class , () -> IOUtils .skipFully (input , -1 ));
1661+ assertThrows (IOException .class , () -> IOUtils .skipFully (input , 5 ));
17031662 }
17041663 }
17051664
@@ -1711,7 +1670,6 @@ void testStringToOutputStream() throws Exception {
17111670 // Create our String. Rely on testReaderToString() to make sure this is valid.
17121671 str = IOUtils .toString (fin );
17131672 }
1714-
17151673 try (OutputStream fout = Files .newOutputStream (destination .toPath ())) {
17161674 CopyUtils .copy (str , fout );
17171675 // Note: this method *does* flush. It is equivalent to:
@@ -1720,7 +1678,6 @@ void testStringToOutputStream() throws Exception {
17201678 // _out.flush();
17211679 // out = fout;
17221680 // note: we don't flush here; this IOUtils method does it for us
1723-
17241681 TestUtils .checkFile (destination , testFile );
17251682 TestUtils .checkWrite (fout );
17261683 }
@@ -1791,7 +1748,7 @@ void testToByteArray_InputStream_Size() throws Exception {
17911748 @ Test
17921749 void testToByteArray_InputStream_Size_Truncated () throws Exception {
17931750 try (InputStream in = new NullInputStream (0 )) {
1794- assertThrows (EOFException .class , () -> IOUtils .toByteArray (in , 1 ), "Should have failed with EOFException" );
1751+ assertThrows (EOFException .class , () -> IOUtils .toByteArray (in , 1 ));
17951752 }
17961753 }
17971754
@@ -1816,17 +1773,15 @@ void testToByteArray_InputStream_Size_BufferSize_Throws(
18161773 @ Test
18171774 void testToByteArray_InputStream_SizeIllegal () throws Exception {
18181775 try (InputStream fin = Files .newInputStream (testFilePath )) {
1819- final IOException exc = assertThrows (IOException .class , () -> IOUtils .toByteArray (fin , testFile .length () + 1 ),
1820- "Should have failed with IOException" );
1776+ final IOException exc = assertThrows (IOException .class , () -> IOUtils .toByteArray (fin , testFile .length () + 1 ));
18211777 assertTrue (exc .getMessage ().startsWith ("Expected read size" ), exc .getMessage ());
18221778 }
18231779 }
18241780
18251781 @ Test
18261782 void testToByteArray_InputStream_SizeLong () throws Exception {
18271783 try (InputStream fin = Files .newInputStream (testFilePath )) {
1828- final IllegalArgumentException exc = assertThrows (IllegalArgumentException .class , () -> IOUtils .toByteArray (fin , (long ) Integer .MAX_VALUE + 1 ),
1829- "Should have failed with IllegalArgumentException" );
1784+ final IllegalArgumentException exc = assertThrows (IllegalArgumentException .class , () -> IOUtils .toByteArray (fin , (long ) Integer .MAX_VALUE + 1 ));
18301785 assertTrue (exc .getMessage ().startsWith ("size > Integer.MAX_VALUE" ), exc .getMessage ());
18311786 }
18321787 }
@@ -1864,7 +1819,6 @@ void testToByteArray_String() throws Exception {
18641819 try (Reader fin = Files .newBufferedReader (testFilePath )) {
18651820 // Create our String. Rely on testReaderToString() to make sure this is valid.
18661821 final String str = IOUtils .toString (fin );
1867-
18681822 final byte [] out = IOUtils .toByteArray (str );
18691823 assertEqualContent (str .getBytes (), out );
18701824 }
0 commit comments