From 85168f7e1aff2e474b7d33562bf5f4345d1e3b8b Mon Sep 17 00:00:00 2001 From: Antoine Levy-Lambert Date: Wed, 20 Sep 2006 03:51:10 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@448049 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/types/resources/URLResource.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/org/apache/tools/ant/types/resources/URLResource.java b/src/main/org/apache/tools/ant/types/resources/URLResource.java index 11dcb3f9e..74466f1b8 100644 --- a/src/main/org/apache/tools/ant/types/resources/URLResource.java +++ b/src/main/org/apache/tools/ant/types/resources/URLResource.java @@ -25,6 +25,8 @@ import java.io.OutputStream; 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 @@ public class URLResource extends Resource { } try { connect(); - return conn.getContentLength(); + long contentlength = conn.getContentLength(); + close(); + return contentlength; } catch (IOException e) { return UNKNOWN_SIZE; } @@ -300,11 +304,29 @@ public class URLResource extends Resource { } } + 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(); }