22
22
23
23
import java .io .BufferedOutputStream ;
24
24
import java .io .File ;
25
- import java .io .FileInputStream ;
26
25
import java .io .FileReader ;
27
26
import java .io .FileWriter ;
28
27
import java .io .IOException ;
@@ -115,8 +114,8 @@ private void assertEqualContent( byte[] b0, byte[] b1 )
115
114
private void assertEqualContent ( File f0 , File f1 )
116
115
throws IOException
117
116
{
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 () );
120
119
byte [] buf0 = new byte [FILE_SIZE ];
121
120
byte [] buf1 = new byte [FILE_SIZE ];
122
121
int n0 = 0 ;
@@ -145,7 +144,7 @@ private void assertEqualContent( File f0, File f1 )
145
144
private void assertEqualContent ( byte [] b0 , File file )
146
145
throws IOException
147
146
{
148
- FileInputStream is = new FileInputStream ( file );
147
+ InputStream is = Files . newInputStream ( file . toPath () );
149
148
byte [] b1 = new byte [b0 .length ];
150
149
int numRead = is .read ( b1 );
151
150
assertTrue ( "Different number of bytes" , numRead == b0 .length && is .available () == 0 );
@@ -160,7 +159,7 @@ public void testInputStreamToOutputStream()
160
159
throws Exception
161
160
{
162
161
File destination = newFile ( "copy1.txt" );
163
- FileInputStream fin = new FileInputStream ( testFile );
162
+ InputStream fin = Files . newInputStream ( testFile . toPath () );
164
163
OutputStream fout = Files .newOutputStream ( destination .toPath () );
165
164
166
165
IOUtil .copy ( fin , fout );
@@ -179,7 +178,7 @@ public void testInputStreamToWriter()
179
178
throws Exception
180
179
{
181
180
File destination = newFile ( "copy2.txt" );
182
- FileInputStream fin = new FileInputStream ( testFile );
181
+ InputStream fin = Files . newInputStream ( testFile . toPath () );
183
182
FileWriter fout = new FileWriter ( destination );
184
183
185
184
IOUtil .copy ( fin , fout );
@@ -198,7 +197,7 @@ public void testInputStreamToWriter()
198
197
public void testInputStreamToString ()
199
198
throws Exception
200
199
{
201
- FileInputStream fin = new FileInputStream ( testFile );
200
+ InputStream fin = Files . newInputStream ( testFile . toPath () );
202
201
String out = IOUtil .toString ( fin );
203
202
assertNotNull ( out );
204
203
assertTrue ( "Not all bytes were read" , fin .available () == 0 );
@@ -304,7 +303,7 @@ public void testStringToWriter()
304
303
public void testInputStreamToByteArray ()
305
304
throws Exception
306
305
{
307
- FileInputStream fin = new FileInputStream ( testFile );
306
+ InputStream fin = Files . newInputStream ( testFile . toPath () );
308
307
byte [] out = IOUtil .toByteArray ( fin );
309
308
assertNotNull ( out );
310
309
assertTrue ( "Not all bytes were read" , fin .available () == 0 );
@@ -333,7 +332,7 @@ public void testByteArrayToWriter()
333
332
{
334
333
File destination = newFile ( "copy7.txt" );
335
334
FileWriter fout = new FileWriter ( destination );
336
- FileInputStream fin = new FileInputStream ( testFile );
335
+ InputStream fin = Files . newInputStream ( testFile . toPath () );
337
336
338
337
// Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid.
339
338
byte [] in = IOUtil .toByteArray ( fin );
@@ -350,7 +349,7 @@ public void testByteArrayToWriter()
350
349
public void testByteArrayToString ()
351
350
throws Exception
352
351
{
353
- FileInputStream fin = new FileInputStream ( testFile );
352
+ InputStream fin = Files . newInputStream ( testFile . toPath () );
354
353
byte [] in = IOUtil .toByteArray ( fin );
355
354
// Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid.
356
355
String str = IOUtil .toString ( in );
@@ -364,7 +363,7 @@ public void testByteArrayToOutputStream()
364
363
{
365
364
File destination = newFile ( "copy8.txt" );
366
365
OutputStream fout = Files .newOutputStream ( destination .toPath () );
367
- FileInputStream fin = new FileInputStream ( testFile );
366
+ InputStream fin = Files . newInputStream ( testFile . toPath () );
368
367
369
368
// Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid.
370
369
byte [] in = IOUtil .toByteArray ( fin );
0 commit comments