ZipUtil { public static FileSystem openZipFs(Path path) throws IOException, URISyntaxException { try { URI uri = new URI("jar:" + path.toUri().toString()); return getOrCreateZipFs(uri); } catch (Throwable e) { try { URI uri = new URI("jar:" + URLDecoder.decode(path.toUri().toString(), Constants.ENCODING)); return getOrCreateZipFs(uri); } catch (Throwable e2) { URI uri = new URI("jar:" + URLEncoder.encode(path.toUri().toString(), Constants.ENCODING)); return getOrCreateZipFs(uri); } } }  static void extract(Path zipFile, Path toDir); static void extract(FileSystem zipFile, Path toDir); static FileSystem openZipFs(Path path); static FileSystem createZipFs(Path path);  }
@Test public void testMultipleOpenZipFs() throws Exception { Path zipFile = IO.toPath(ZipUtilTest.class.getResource("example.zip").toURI()); try (FileSystem fs1 = ZipUtil.openZipFs(zipFile)) { try (FileSystem fs2 = ZipUtil.openZipFs(zipFile)) { assertExampleZip(fs1); assertExampleZip(fs2); } } }
@Test public void testOpenZipFsVirtualFS() throws Exception { final Path srcZipFile = Paths.get(ZipUtilTest.class.getResource("example.zip").toURI()); Configuration[] configs = new Configuration[]{Configuration.osX(), Configuration.unix(), Configuration.windows()}; for (Configuration config : configs) { final FileSystem fileSystem = Jimfs.newFileSystem(config); final Path path = fileSystem.getPath("a", "b c", "mu\\d", "hi", "file.zip"); Files.createDirectories(path.getParent()); Files.copy(srcZipFile, path); final FileSystem zipFs = ZipUtil.openZipFs(path); assertExampleZip(zipFs); } }