Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
7 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| * @param destination the directory to which to extract the files (already created) | |||
| * @throws IOException an I/O error occurs | |||
| */ | |||
| protected void extract(Path archiveFile, Path destination) throws IOException { | |||
| try (ArchiveInputStream archiveInputStream = createArchiveInputStream(archiveFile)) { | |||
|
|||
|
|||
| ArchiveEntry entry; | |||
| while ((entry = archiveInputStream.getNextEntry()) != null) { | |||
| Path entryPath = destination.resolve(entry.getName()).normalize().toAbsolutePath(); | |||
| if (!entryPath.startsWith(destination)) { | |||
| throw new IOException("Bad zip entry [" + entry.getName() + "]"); | |||
| } | |||
| if (entry.isDirectory()) { | |||
| Files.createDirectories(destination.resolve(entry.getName()).normalize().toAbsolutePath()); | |||
| Files.createDirectories(entryPath); | |||
| } | |||
| else { | |||
| Path file = destination.resolve(entry.getName()).normalize().toAbsolutePath(); | |||
| Path parent = file.getParent(); | |||
| Path parent = entryPath.getParent(); | |||
| if (!Files.exists(parent)) { | |||
| Files.createDirectories(parent); | |||
| } | |||
| Files.copy(archiveInputStream, file, StandardCopyOption.REPLACE_EXISTING); | |||
| Files.copy(archiveInputStream, entryPath, StandardCopyOption.REPLACE_EXISTING); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| /** | |||