commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1094224 - in /commons/proper/compress/trunk/src: changes/changes.xml main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
Date Mon, 18 Apr 2011 04:28:14 GMT
Author: bodewig
Date: Mon Apr 18 04:28:14 2011
New Revision: 1094224

URL: http://svn.apache.org/viewvc?rev=1094224&view=rev
Log:
add a finalize method to ZipFile as suggested on the user list

Modified:
    commons/proper/compress/trunk/src/changes/changes.xml
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java

Modified: commons/proper/compress/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=1094224&r1=1094223&r2=1094224&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Mon Apr 18 04:28:14 2011
@@ -45,6 +45,10 @@ The <action> type attribute can be add,u
   </properties>
   <body>
     <release version="1.2" date="as in SVN" description="Release 1.2">
+      <action type="update" date="2011-04-18">
+        ZipFile now implements finalize which closes the underlying
+        file.
+      </action>
       <action issue="COMPRESS-117" type="update" date="2011-03-23">
         Certain tar files not recognised by ArchiveStreamFactory.
       </action> 

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java?rev=1094224&r1=1094223&r2=1094224&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
Mon Apr 18 04:28:14 2011
@@ -112,6 +112,11 @@ public class ZipFile {
     private final boolean useUnicodeExtraFields;
 
     /**
+     * Whether the file is closed.
+     */
+    private boolean closed;
+
+    /**
      * Opens the given file for reading, assuming "UTF8" for file names.
      *
      * @param f the archive.
@@ -208,8 +213,11 @@ public class ZipFile {
      * Closes the archive.
      * @throws IOException if an error occurs closing the archive.
      */
-    public void close() throws IOException {
-        archive.close();
+    public synchronized void close() throws IOException {
+        if (!closed) {
+            closed = true;
+            archive.close();
+        }
     }
 
     /**
@@ -307,6 +315,19 @@ public class ZipFile {
         }
     }
 
+    /**
+     * Ensures that the close method of this zipfile is called when
+     * there are no more references to it.
+     * @see close()
+     */
+    protected void finalize() throws Throwable {
+        try {
+            close();
+        } finally {
+            super.finalize();
+        }
+    }
+
     private static final int CFH_LEN =
         /* version made by                 */ SHORT
         /* version needed to extract       */ + SHORT



Mime
View raw message