Are valid java.net.URIs for nested archives?

It is possible, although not recommended, to read archive formats, which are mainly renamed .zip files (.ear, .war, .jar, etc.) using jar: URI .

For example, the following code works well when the uri variable is evaluated as one, a top-level archive, for example. when uri is jar:file:///Users/justingarrick/Desktop/test/my_war.war!/

 private FileSystem createZipFileSystem(Path path) throws IOException { URI uri = URI.create("jar:" + path.toUri().toString()); FileSystem fs; try { fs = FileSystems.getFileSystem(uri); } catch (FileSystemNotFoundException e) { fs = FileSystems.newFileSystem(uri, new HashMap<>()); } return fs; } 

However, the getFileSystem and newFileSystem fail with an IllegalArgumentException when the URI contains nested archives, for example. when uri is jar:jar:file:///Users/justingarrick/Desktop/test/my_war.war!/some_jar.jar!/ (a.jar inside a.war).

Is there a valid java.net.URI scheme for attached archive files?

+6
source share
1 answer

As stated in Jonas Berlin's comment above, the answer is no . From java.net.JarURLConnection source :

 /* get the specs for a given url out of the cache, and compute and * cache them if they're not there. */ private void parseSpecs(URL url) throws MalformedURLException { String spec = url.getFile(); int separator = spec.indexOf("!/"); /* * REMIND: we don't handle nested JAR URLs */ if (separator == -1) { throw new MalformedURLException("no !/ found in url spec:" + spec); } jarFileURL = new URL(spec.substring(0, separator++)); entryName = null; /* if ! is the last letter of the innerURL, entryName is null */ if (++separator != spec.length()) { entryName = spec.substring(separator, spec.length()); entryName = ParseUtil.decode (entryName); } } 
0
source

Source: https://habr.com/ru/post/978201/


All Articles