2222
2323import java .io .BufferedOutputStream ;
2424import java .io .File ;
25- import java .io .FileInputStream ;
2625import java .io .FileReader ;
2726import java .io .FileWriter ;
2827import java .io .IOException ;
@@ -115,8 +114,8 @@ private void assertEqualContent( byte[] b0, byte[] b1 )
115114 private void assertEqualContent ( File f0 , File f1 )
116115 throws IOException
117116 {
118- FileInputStream is0 = new FileInputStream ( f0 );
119- FileInputStream is1 = new FileInputStream ( f1 );
117+ InputStream is0 = Files . newInputStream ( f0 . toPath () );
118+ InputStream is1 = Files . newInputStream ( f1 . toPath () );
120119 byte [] buf0 = new byte [FILE_SIZE ];
121120 byte [] buf1 = new byte [FILE_SIZE ];
122121 int n0 = 0 ;
@@ -145,7 +144,7 @@ private void assertEqualContent( File f0, File f1 )
145144 private void assertEqualContent ( byte [] b0 , File file )
146145 throws IOException
147146 {
148- FileInputStream is = new FileInputStream ( file );
147+ InputStream is = Files . newInputStream ( file . toPath () );
149148 byte [] b1 = new byte [b0 .length ];
150149 int numRead = is .read ( b1 );
151150 assertTrue ( "Different number of bytes" , numRead == b0 .length && is .available () == 0 );
@@ -160,7 +159,7 @@ public void testInputStreamToOutputStream()
160159 throws Exception
161160 {
162161 File destination = newFile ( "copy1.txt" );
163- FileInputStream fin = new FileInputStream ( testFile );
162+ InputStream fin = Files . newInputStream ( testFile . toPath () );
164163 OutputStream fout = Files .newOutputStream ( destination .toPath () );
165164
166165 IOUtil .copy ( fin , fout );
@@ -179,7 +178,7 @@ public void testInputStreamToWriter()
179178 throws Exception
180179 {
181180 File destination = newFile ( "copy2.txt" );
182- FileInputStream fin = new FileInputStream ( testFile );
181+ InputStream fin = Files . newInputStream ( testFile . toPath () );
183182 FileWriter fout = new FileWriter ( destination );
184183
185184 IOUtil .copy ( fin , fout );
@@ -198,7 +197,7 @@ public void testInputStreamToWriter()
198197 public void testInputStreamToString ()
199198 throws Exception
200199 {
201- FileInputStream fin = new FileInputStream ( testFile );
200+ InputStream fin = Files . newInputStream ( testFile . toPath () );
202201 String out = IOUtil .toString ( fin );
203202 assertNotNull ( out );
204203 assertTrue ( "Not all bytes were read" , fin .available () == 0 );
@@ -304,7 +303,7 @@ public void testStringToWriter()
304303 public void testInputStreamToByteArray ()
305304 throws Exception
306305 {
307- FileInputStream fin = new FileInputStream ( testFile );
306+ InputStream fin = Files . newInputStream ( testFile . toPath () );
308307 byte [] out = IOUtil .toByteArray ( fin );
309308 assertNotNull ( out );
310309 assertTrue ( "Not all bytes were read" , fin .available () == 0 );
@@ -333,7 +332,7 @@ public void testByteArrayToWriter()
333332 {
334333 File destination = newFile ( "copy7.txt" );
335334 FileWriter fout = new FileWriter ( destination );
336- FileInputStream fin = new FileInputStream ( testFile );
335+ InputStream fin = Files . newInputStream ( testFile . toPath () );
337336
338337 // Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid.
339338 byte [] in = IOUtil .toByteArray ( fin );
@@ -350,7 +349,7 @@ public void testByteArrayToWriter()
350349 public void testByteArrayToString ()
351350 throws Exception
352351 {
353- FileInputStream fin = new FileInputStream ( testFile );
352+ InputStream fin = Files . newInputStream ( testFile . toPath () );
354353 byte [] in = IOUtil .toByteArray ( fin );
355354 // Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid.
356355 String str = IOUtil .toString ( in );
@@ -364,7 +363,7 @@ public void testByteArrayToOutputStream()
364363 {
365364 File destination = newFile ( "copy8.txt" );
366365 OutputStream fout = Files .newOutputStream ( destination .toPath () );
367- FileInputStream fin = new FileInputStream ( testFile );
366+ InputStream fin = Files . newInputStream ( testFile . toPath () );
368367
369368 // Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid.
370369 byte [] in = IOUtil .toByteArray ( fin );
0 commit comments