Extract the contents of a .zip archive into a folder. Ignores (does not extract) any __MACOSX files from macOS archives.
(File zipFile, File dest)
| 688 | * Ignores (does not extract) any __MACOSX files from macOS archives. |
| 689 | */ |
| 690 | static public void unzip(File zipFile, File dest) throws IOException { |
| 691 | FileInputStream fis = new FileInputStream(zipFile); |
| 692 | CheckedInputStream checksum = new CheckedInputStream(fis, new Adler32()); |
| 693 | ZipInputStream zis = new ZipInputStream(new BufferedInputStream(checksum)); |
| 694 | ZipEntry entry; |
| 695 | while ((entry = zis.getNextEntry()) != null) { |
| 696 | final String name = entry.getName(); |
| 697 | if (!name.startsWith(("__MACOSX"))) { |
| 698 | File currentFile = new File(dest, name); |
| 699 | if (entry.isDirectory()) { |
| 700 | currentFile.mkdirs(); |
| 701 | } else { |
| 702 | File parentDir = currentFile.getParentFile(); |
| 703 | // Sometimes the directory entries aren't already created |
| 704 | if (!parentDir.exists()) { |
| 705 | parentDir.mkdirs(); |
| 706 | } |
| 707 | currentFile.createNewFile(); |
| 708 | unzipEntry(zis, currentFile); |
| 709 | } |
| 710 | } |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | |
| 715 | static protected void unzipEntry(ZipInputStream zin, File f) throws IOException { |
no test coverage detected