Commit ef2eb8af authored by Phillip Webb's avatar Phillip Webb

Fix URL from String creation to work on Windows

Fixed the nested jar URLHandler to correctly deal with files on
Windows.

Fixes gh-269
parent 0afdb713
...@@ -34,6 +34,8 @@ public class Handler extends URLStreamHandler { ...@@ -34,6 +34,8 @@ public class Handler extends URLStreamHandler {
// NOTE: in order to be found as a URL protocol hander, this class must be public, // NOTE: in order to be found as a URL protocol hander, this class must be public,
// must be named Handler and must be in a package ending '.jar' // must be named Handler and must be in a package ending '.jar'
private static final String FILE_PROTOCOL = "file:";
private static final String SEPARATOR = JarURLConnection.SEPARATOR; private static final String SEPARATOR = JarURLConnection.SEPARATOR;
private final JarFile jarFile; private final JarFile jarFile;
...@@ -74,7 +76,11 @@ public class Handler extends URLStreamHandler { ...@@ -74,7 +76,11 @@ public class Handler extends URLStreamHandler {
private JarFile getRootJarFile(String name) throws IOException { private JarFile getRootJarFile(String name) throws IOException {
try { try {
return new JarFile(new File(new URL(name).toURI())); if (!name.startsWith(FILE_PROTOCOL)) {
throw new IllegalStateException("Not a file URL");
}
String path = name.substring(FILE_PROTOCOL.length());
return new JarFile(new File(path));
} }
catch (Exception ex) { catch (Exception ex) {
throw new IOException("Unable to open root Jar file '" + name + "'", ex); throw new IOException("Unable to open root Jar file '" + name + "'", ex);
......
...@@ -104,7 +104,7 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD ...@@ -104,7 +104,7 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD
* @throws IOException * @throws IOException
*/ */
JarFile(RandomAccessDataFile file, JarEntryFilter... filters) throws IOException { JarFile(RandomAccessDataFile file, JarEntryFilter... filters) throws IOException {
this(file, file.getFile().getPath(), file, filters); this(file, file.getFile().getAbsolutePath(), file, filters);
} }
/** /**
......
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