You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2020/05/27 01:57:20 UTC

[maven-shared-utils] branch master updated: [MSHARED-881] use try-with-resources

This is an automated email from the ASF dual-hosted git repository.

olamy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git


The following commit(s) were added to refs/heads/master by this push:
     new 83d44c9  [MSHARED-881] use try-with-resources
83d44c9 is described below

commit 83d44c98dbc340006a28d2fd0acbf9b1844ac74c
Author: Dom <dc...@gmail.com>
AuthorDate: Fri May 22 04:31:50 2020 +0200

    [MSHARED-881] use try-with-resources
---
 .../maven/shared/utils/io/FileUtilsTest.java       | 23 ++++------------------
 1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
index 86dc0a2..66d1844 100644
--- a/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
@@ -156,10 +156,9 @@ public class FileUtilsTest
     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 )
             {
@@ -172,10 +171,6 @@ public class FileUtilsTest
                 assertThat( "byte " + i + " differs", b1[i], is( b0[i] ) );
             }
         }
-        finally
-        {
-            is.close();
-        }
     }
 
     void deleteFile( File file )
@@ -345,17 +340,12 @@ public class FileUtilsTest
         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()
     }
 
@@ -1180,15 +1170,10 @@ public class FileUtilsTest
         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" );