Commit 35b26b52 authored by Phillip Webb's avatar Phillip Webb

Add caching to JarFile.getUrl()

Fixes gh-1178
parent 200cd535
...@@ -84,6 +84,8 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD ...@@ -84,6 +84,8 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD
private SoftReference<Manifest> manifest; private SoftReference<Manifest> manifest;
private URL url;
/** /**
* Create a new {@link JarFile} backed by the specified file. * Create a new {@link JarFile} backed by the specified file.
* @param file the root jar file * @param file the root jar file
...@@ -417,9 +419,12 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD ...@@ -417,9 +419,12 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD
* @throws MalformedURLException * @throws MalformedURLException
*/ */
public URL getUrl() throws MalformedURLException { public URL getUrl() throws MalformedURLException {
if (this.url == null) {
Handler handler = new Handler(this); Handler handler = new Handler(this);
String file = this.rootFile.getFile().toURI() + this.pathFromRoot + "!/"; String file = this.rootFile.getFile().toURI() + this.pathFromRoot + "!/";
return new URL("jar", "", -1, file, handler); this.url = new URL("jar", "", -1, file, handler);
}
return this.url;
} }
@Override @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment