Browse Source

Add caching to JarFile.getUrl()

Fixes gh-1178
pull/1181/head
Phillip Webb 12 years ago
parent
commit
35b26b52f2
  1. 11
      spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java

11
spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java

@ -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
* @throws MalformedURLException * @throws MalformedURLException
*/ */
public URL getUrl() throws MalformedURLException { public URL getUrl() throws MalformedURLException {
Handler handler = new Handler(this); if (this.url == null) {
String file = this.rootFile.getFile().toURI() + this.pathFromRoot + "!/"; Handler handler = new Handler(this);
return new URL("jar", "", -1, file, handler); String file = this.rootFile.getFile().toURI() + this.pathFromRoot + "!/";
this.url = new URL("jar", "", -1, file, handler);
}
return this.url;
} }
@Override @Override

Loading…
Cancel
Save