Skip to content

Commit

Permalink
Add caching to JarFile.getUrl()
Browse files Browse the repository at this point in the history
Fixes gh-1178
  • Loading branch information
Phillip Webb committed Jun 26, 2014
1 parent 200cd53 commit 35b26b5
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD

private SoftReference<Manifest> manifest;

private URL url;

/**
* Create a new {@link JarFile} backed by the specified file.
* @param file the root jar file
Expand Down Expand Up @@ -417,9 +419,12 @@ public void close() throws IOException {
* @throws MalformedURLException
*/
public URL getUrl() throws MalformedURLException {
Handler handler = new Handler(this);
String file = this.rootFile.getFile().toURI() + this.pathFromRoot + "!/";
return new URL("jar", "", -1, file, handler);
if (this.url == null) {
Handler handler = new Handler(this);
String file = this.rootFile.getFile().toURI() + this.pathFromRoot + "!/";
this.url = new URL("jar", "", -1, file, handler);
}
return this.url;
}

@Override
Expand Down

0 comments on commit 35b26b5

Please sign in to comment.