¿Se puede crear un java.nio.file.FileSystem para un archivo zip que está dentro de un archivo zip?
Si es así, ¿cómo se ve el URI?
Si no, supongo que tendré que volver a usar ZipInputStream.
Estoy tratando de recurrir al método a continuación. La implementación actual crea un URI "jar:jar:...". Sé que está mal (y es un recordatorio potencialmente traumático de un personaje de película). ¿Que debería ser?
private static void traverseZip(Path zipFile ) { // Example: URI uri = URI.create("jar:file:/codeSamples/zipfs/zipfstest.zip"); String sURI = "jar:" + zipFile.toUri().toString(); URI uri = URI.create(sURI); Map<String, String> env = new HashMap<>(); try (FileSystem fs = FileSystems.newFileSystem(uri, env)) { Iterable<Path> rootDirs = fs.getRootDirectories(); for (Path rootDir : rootDirs) { traverseDirectory(rootDir ); // Recurses back into this method for ZIP files } } catch (IOException e) { System.err.println(e); } }Puede usar FileSystem.getPath para devolver una Path adecuada para usar con otra llamada FileSystems.newFileSystem que abre el ZIP/archivo anidado.
Por ejemplo, este código abre un archivo war y lee el contenido del archivo jar interno:
Path war = Path.of("webapps.war"); String pathInWar = "WEB-INF/lib/some.jar"; try (FileSystem fs = FileSystems.newFileSystem(war)) { Path jar = fs.getPath(pathInWar); try (FileSystem inner = FileSystems.newFileSystem(jar)) { for (Path root : inner.getRootDirectories()) { try (Stream<Path> stream = Files.find(root, Integer.MAX_VALUE, (p,a) -> true)) { stream.forEach(System.out::println); } } } }Tenga en cuenta también que su código puede pasar en zipFile sin cambiar a URI:
try (FileSystem fs = FileSystems.newFileSystem(zipFile, env)) {