Repository: commons-release-plugin
Updated Branches:
  refs/heads/master 29c3d2d62 -> e46ed7dc6


Use try-with-resources.

Project: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/commons-release-plugin/commit/e46ed7dc
Tree: 
http://git-wip-us.apache.org/repos/asf/commons-release-plugin/tree/e46ed7dc
Diff: 
http://git-wip-us.apache.org/repos/asf/commons-release-plugin/diff/e46ed7dc

Branch: refs/heads/master
Commit: e46ed7dc654ed8579d6d1556a8d1e08e107ae939
Parents: 29c3d2d
Author: Gary Gregory <[email protected]>
Authored: Mon May 14 16:48:44 2018 -0600
Committer: Gary Gregory <[email protected]>
Committed: Mon May 14 16:48:44 2018 -0600

----------------------------------------------------------------------
 .../mojos/CommonsSiteCompressionMojo.java       | 39 ++++++++++----------
 1 file changed, 19 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/e46ed7dc/src/main/java/org/apache/commons/release/plugin/mojos/CommonsSiteCompressionMojo.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsSiteCompressionMojo.java
 
b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsSiteCompressionMojo.java
index b020d08..c27d83e 100644
--- 
a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsSiteCompressionMojo.java
+++ 
b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsSiteCompressionMojo.java
@@ -155,15 +155,14 @@ public class CommonsSiteCompressionMojo extends 
AbstractMojo {
      * @throws IOException when the copying of the files goes incorrectly.
      */
     private void writeZipFile(File workingDirectory, File directoryToZip, 
List<File> fileList) throws IOException {
-        FileOutputStream fos = new 
FileOutputStream(workingDirectory.getAbsolutePath() + "/site.zip");
-        ZipOutputStream zos = new ZipOutputStream(fos);
-        for (File file : fileList) {
-            if (!file.isDirectory()) { // we only zip files, not directories
-                addToZip(directoryToZip, file, zos);
+        try (FileOutputStream fos = new 
FileOutputStream(workingDirectory.getAbsolutePath() + "/site.zip");
+                ZipOutputStream zos = new ZipOutputStream(fos)) {
+            for (File file : fileList) {
+                if (!file.isDirectory()) { // we only zip files, not 
directories
+                    addToZip(directoryToZip, file, zos);
+                }
             }
         }
-        zos.close();
-        fos.close();
     }
 
     /**
@@ -177,19 +176,19 @@ public class CommonsSiteCompressionMojo extends 
AbstractMojo {
      * @throws IOException if adding the <code>file</code> doesn't work out 
properly.
      */
     private void addToZip(File directoryToZip, File file, ZipOutputStream zos) 
throws IOException {
-        FileInputStream fis = new FileInputStream(file);
-        // we want the zipEntry's path to be a relative path that is relative
-        // to the directory being zipped, so chop off the rest of the path
-        String zipFilePath = 
file.getCanonicalPath().substring(directoryToZip.getCanonicalPath().length() + 
1,
-                file.getCanonicalPath().length());
-        ZipEntry zipEntry = new ZipEntry(zipFilePath);
-        zos.putNextEntry(zipEntry);
-        byte[] bytes = new byte[SharedFunctions.BUFFER_BYTE_SIZE];
-        int length;
-        while ((length = fis.read(bytes)) >= 0) {
-            zos.write(bytes, 0, length);
+        try (FileInputStream fis = new FileInputStream(file)) {
+            // we want the zipEntry's path to be a relative path that is 
relative
+            // to the directory being zipped, so chop off the rest of the path
+            String zipFilePath = 
file.getCanonicalPath().substring(directoryToZip.getCanonicalPath().length() + 
1,
+                    file.getCanonicalPath().length());
+            ZipEntry zipEntry = new ZipEntry(zipFilePath);
+            zos.putNextEntry(zipEntry);
+            byte[] bytes = new byte[SharedFunctions.BUFFER_BYTE_SIZE];
+            int length;
+            while ((length = fis.read(bytes)) >= 0) {
+                zos.write(bytes, 0, length);
+            }
+            zos.closeEntry();
         }
-        zos.closeEntry();
-        fis.close();
     }
 }

Reply via email to