ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anto...@apache.org
Subject svn commit: r448049 - /ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java
Date Wed, 20 Sep 2006 03:51:10 GMT
Author: antoine
Date: Tue Sep 19 20:51:10 2006
New Revision: 448049

URL: http://svn.apache.org/viewvc?view=rev&rev=448049
Log:
add a close method for JarURLConnection, idea found in 
http://svn.apache.org/repos/asf/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarHolder.java

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java?view=diff&rev=448049&r1=448048&r2=448049
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java Tue Sep
19 20:51:10 2006
@@ -25,6 +25,8 @@
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.MalformedURLException;
+import java.net.JarURLConnection;
+import java.util.jar.JarFile;
 
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.BuildException;
@@ -202,7 +204,9 @@
         }
         try {
             connect();
-            return conn.getContentLength();
+            long contentlength = conn.getContentLength();
+            close();
+            return contentlength;
         } catch (IOException e) {
             return UNKNOWN_SIZE;
         }
@@ -300,11 +304,29 @@
         }
     }
 
+    private void close() {
+        if (conn != null) {
+            try {
+                if (conn instanceof JarURLConnection) {
+                    JarURLConnection juc = (JarURLConnection) conn;
+                    JarFile jf = juc.getJarFile();
+                    jf.close();
+                    jf = null;
+                }
+            } catch (IOException exc) {
+
+            } finally {
+                conn = null;
+            }
+        }
+    }
+
     /**
      * Finalize this URLResource.
      * @throws Throwable on error.
      */
     protected void finalize() throws Throwable {
+        close();
         conn = null;
         super.finalize();
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message