Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MSHARED-881] use try-with-resources #32

Merged
merged 1 commit into from May 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,9 @@ void createFile( File file, long size )
void assertEqualContent( byte[] b0, File file )
throws IOException
{
InputStream is = new java.io.FileInputStream( file );
int count = 0, numRead = 0;
byte[] b1 = new byte[b0.length];
try
try ( InputStream is = new FileInputStream( file ) )
{
while ( count < b0.length && numRead >= 0 )
{
Expand All @@ -163,10 +162,6 @@ void assertEqualContent( byte[] b0, File file )
assertThat( "byte " + i + " differs", b1[i], is( b0[i] ) );
}
}
finally
{
is.close();
}
}

void deleteFile( File file )
Expand Down Expand Up @@ -336,17 +331,12 @@ public void copyURLToFile()
String resourceName = "/java/lang/Object.class";
FileUtils.copyURLToFile( getClass().getResource( resourceName ), file );

// Tests that resuorce was copied correctly
FileInputStream fis = new FileInputStream( file );
try
// Tests that resource was copied correctly
try ( FileInputStream fis = new FileInputStream( file ) )
{
assertThat( "Content is not equal.",
IOUtil.contentEquals( getClass().getResourceAsStream( resourceName ), fis ), is( true ) );
}
finally
{
fis.close();
}
//TODO Maybe test copy to itself like for copyFile()
}

Expand Down Expand Up @@ -883,15 +873,10 @@ public void fileUtils()
String filename = file1.getAbsolutePath();

//Create test file on-the-fly (used to be in CVS)
OutputStream out = new java.io.FileOutputStream( file1 );
try
try ( OutputStream out = new java.io.FileOutputStream( file1 ) )
{
out.write( "This is a test".getBytes( "UTF-8" ) );
}
finally
{
out.close();
}

File file2 = new File( tempFolder.getRoot(), "test2.txt" );

Expand Down