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?
source share