private static void unpack(File archive, File targetDir) throws IOException { if (!targetDir.exists()) { //noinspection ResultOfMethodCallIgnored targetDir.mkdir(); } String extension = Files.getFileExtension(archive.getPath()).toLowerCase(); switch (extension) { case "zip": case "jar": BundleJarUtil.unJar(Locations.toLocation(archive), targetDir); break; case "gz": // gz is not recommended for archiving multiple files together. So we only support .tar.gz Preconditions.checkArgument(archive.getName().endsWith(".tar.gz"), "'.gz' format is not supported for " + "archiving multiple files. Please use 'zip', 'jar', '.tar.gz', 'tgz' or 'tar'."); untargz(archive, targetDir); break; case "tgz": untargz(archive, targetDir); break; case "tar": untar(archive, targetDir); break; default: throw new IllegalArgumentException(String.format("Unsupported compression type '%s'. Only 'zip', 'jar', " + "'tar.gz', 'tgz' and 'tar' are supported.", extension)); } }
private static void unpack(File archive, File targetDir) throws IOException { if (!targetDir.exists()) { //noinspection ResultOfMethodCallIgnored targetDir.mkdir(); } String extension = Files.getFileExtension(archive.getPath()).toLowerCase(); switch (extension) { case "zip": case "jar": BundleJarUtil.unJar(Locations.toLocation(archive), targetDir); break; case "gz": // gz is not recommended for archiving multiple files together. So we only support .tar.gz Preconditions.checkArgument(archive.getName().endsWith(".tar.gz"), "'.gz' format is not supported for " + "archiving multiple files. Please use 'zip', 'jar', '.tar.gz', 'tgz' or 'tar'."); untargz(archive, targetDir); break; case "tgz": untargz(archive, targetDir); break; case "tar": untar(archive, targetDir); break; default: throw new IllegalArgumentException(String.format("Unsupported compression type '%s'. Only 'zip', 'jar', " + "'tar.gz', 'tgz' and 'tar' are supported.", extension)); } }