JkUtilsPath { public static Path zipRoot(Path zipFile) { final URI uri = URI.create("jar:" + zipFile.toUri()); final Map<String, String> env = JkUtilsIterable.mapOf("create", "true"); FileSystem fileSystem; try { try { fileSystem = FileSystems.getFileSystem(uri); } catch (FileSystemNotFoundException e) { fileSystem = FileSystems.newFileSystem(uri, env); } } catch (final IOException e) { throw new UncheckedIOException(e); } catch(ZipError e) { throw JkUtilsThrowable.unchecked(e, "Error while opening zip archive " + zipFile); } return fileSystem.getPath("/"); } private  JkUtilsPath(); static List<Path> disambiguate(Iterable<Path> paths); static Path firstExisting(Path... paths); static Path get(URL url); static Path zipRoot(Path zipFile); static List<File> toFiles(Collection<Path> paths); static File[] toFiles(Path ... paths); static Path[] toPaths(File ... files); static List<Path> toPaths(Iterable<File> files); static boolean isSameFile(Path path1, Path path2); static Path createTempFile(String prefix, String extension, FileAttribute ... fileAttributes); static List<String> readAllLines(Path path); static byte[] readAllBytes(Path path); static void deleteFile(Path path); static void deleteIfExists(Path path); static void createFile(Path path, FileAttribute<?>... attrs); static void createFileSafely(Path path, FileAttribute<?>... attrs); static void write(Path path, byte[] bytes, OpenOption ... options); static Path createTempDirectory(String prefix, FileAttribute ... fileAttributes); static DirectoryStream<Path> newDirectoryStream(Path root, DirectoryStream.Filter<Path> filter); static List<Path> listDirectChildren(Path path); static void createDirectories(Path path, FileAttribute<?>... attrs); static void copy(Path source, Path target, CopyOption ...copyOptions); static URL toUrl(Path path); static Stream<Path> walk(Path path, FileVisitOption ...options); static Stream<Path> walk(Path path, int deep, FileVisitOption ...options); static void walkFileTree(Path path, FileVisitor<Path> visitor); static int copyDirContent(Path sourceDir, Path targetDir, PathMatcher pathMatcher, CopyOption ... copyOptions); static int childrenCount(Path dir, int max, boolean includeDirectories, PathMatcher pathMatcher);  }
@Test public void testZipRoot() throws IOException { Path zipFile = Paths.get("toto.zip"); Files.deleteIfExists(zipFile); Path zipPath = JkUtilsPath.zipRoot(zipFile); assertTrue(Files.exists(zipPath)); Files.deleteIfExists(zipFile); Path dirWithSpaces = Files.createTempDirectory("folder name with space"); Path otherPath = dirWithSpaces.resolve("toto.zip"); System.out.println(otherPath.toUri()); JkUtilsPath.zipRoot(otherPath); }