diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java index 28abc20f10..d0ee8e2b29 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java @@ -30,6 +30,9 @@ import java.net.URLConnection; import java.net.URLEncoder; import java.net.URLStreamHandler; import java.security.Permission; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; /** * {@link java.net.JarURLConnection} used to support {@link JarFile#getUrl()}. @@ -65,6 +68,16 @@ class JarURLConnection extends java.net.JarURLConnection { private static final String READ_ACTION = "read"; + private static final Map absoluteFileCache = Collections + .synchronizedMap(new LinkedHashMap(16, 0.75f, true) { + + @Override + protected boolean removeEldestEntry(Map.Entry eldest) { + return size() >= 50; + } + + }); + private static ThreadLocal useFastExceptions = new ThreadLocal(); private final JarFile jarFile; @@ -95,9 +108,20 @@ class JarURLConnection extends java.net.JarURLConnection { } private String getNormalizedFileUrl(URL url) { - String fileName = url.getFile(); - return new File(URI.create(fileName).getSchemeSpecificPart()).getAbsoluteFile() - .toURI().toString() + (fileName.endsWith("/") ? "/" : ""); + String file = url.getFile(); + String path = ""; + int separatorIndex = file.indexOf(SEPARATOR); + if (separatorIndex > 0) { + path = file.substring(separatorIndex); + file = file.substring(0, separatorIndex); + } + String absoluteFile = JarURLConnection.absoluteFileCache.get(file); + if (absoluteFile == null) { + absoluteFile = new File(URI.create(file).getSchemeSpecificPart()) + .getAbsoluteFile().toURI().toString(); + JarURLConnection.absoluteFileCache.put(file, absoluteFile); + } + return absoluteFile + path; } private JarFile getNestedJarFile(JarFile jarFile, String name) throws IOException {