Extract the contents of a .zip archive into a folder. Ignores (does not extract) any __MACOSX files from macOS archives.
(File zipFile, File dest)
| 619 | * Ignores (does not extract) any __MACOSX files from macOS archives. |
| 620 | */ |
| 621 | static public void unzip(File zipFile, File dest) { |
| 622 | try { |
| 623 | FileInputStream fis = new FileInputStream(zipFile); |
| 624 | CheckedInputStream checksum = new CheckedInputStream(fis, new Adler32()); |
| 625 | ZipInputStream zis = new ZipInputStream(new BufferedInputStream(checksum)); |
| 626 | ZipEntry entry = null; |
| 627 | while ((entry = zis.getNextEntry()) != null) { |
| 628 | final String name = entry.getName(); |
| 629 | if (!name.startsWith(("__MACOSX"))) { |
| 630 | File currentFile = new File(dest, name); |
| 631 | if (entry.isDirectory()) { |
| 632 | currentFile.mkdirs(); |
| 633 | } else { |
| 634 | File parentDir = currentFile.getParentFile(); |
| 635 | // Sometimes the directory entries aren't already created |
| 636 | if (!parentDir.exists()) { |
| 637 | parentDir.mkdirs(); |
| 638 | } |
| 639 | currentFile.createNewFile(); |
| 640 | unzipEntry(zis, currentFile); |
| 641 | } |
| 642 | } |
| 643 | } |
| 644 | } catch (Exception e) { |
| 645 | e.printStackTrace(); |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | |
| 650 | static protected void unzipEntry(ZipInputStream zin, File f) throws IOException { |
no test coverage detected