static (File outputDirectory, String outputDirectoryCanonicalPath, ZipFile zip, ZipEntry entry) { def output = new File(outputDirectory, entry.name) if (!output.canonicalPath.startsWith(outputDirectoryCanonicalPath)) { throw new ZipException("Zip entry '${entry.name}' is outside of the output directory") } if (entry.isDirectory()) { output.mkdirs() } else { output.parentFile.mkdirs() zip.getInputStream(entry).withCloseable { Files.copy(it, output.toPath()) } } }