|
47 | 47 | public class FileUtilities { |
48 | 48 |
|
49 | 49 | public static void extractArchive(File sourceBundle, File root) throws IOException { |
50 | | - ZipFile zipfile = new ZipFile(sourceBundle); |
51 | | - |
52 | | - Enumeration<ZipArchiveEntry> e = zipfile.getEntries(); |
53 | | - |
54 | | - while (e.hasMoreElements()) { |
55 | | - ZipArchiveEntry ze = e.nextElement(); |
56 | | - File file = new File(root, ze.getName()); |
57 | | - if (ze.isUnixSymlink()) { |
58 | | - File target = new File(file.getParent(), zipfile.getUnixSymlink(ze)); |
59 | | - /* |
60 | | - * A weirdness is that an object may already have been exploded |
61 | | - * before the symlink entry is reached in the ZipFile. So |
62 | | - * unlink any existing entry to avoid an exception on creating |
63 | | - * the symlink. |
64 | | - */ |
65 | | - if (file.isDirectory()) { |
66 | | - removeDirs(file); |
67 | | - } else if (file.exists()) { |
68 | | - file.delete(); |
69 | | - } |
70 | | - Files.createSymbolicLink(file.toPath(), target.toPath()); |
71 | | - } else if (ze.isDirectory()) { |
72 | | - file.mkdirs(); |
73 | | - } else { |
74 | | - try (InputStream in = zipfile.getInputStream(ze); OutputStream out = new FileOutputStream(file)) { |
75 | | - if (in == null) { |
76 | | - throw new IOException("Cannot get InputStream for " + ze); |
| 50 | + try (ZipFile zipfile = new ZipFile(sourceBundle)) { |
| 51 | + Enumeration<ZipArchiveEntry> e = zipfile.getEntries(); |
| 52 | + |
| 53 | + while (e.hasMoreElements()) { |
| 54 | + ZipArchiveEntry ze = e.nextElement(); |
| 55 | + File file = new File(root, ze.getName()); |
| 56 | + if (ze.isUnixSymlink()) { |
| 57 | + File target = new File(file.getParent(), zipfile.getUnixSymlink(ze)); |
| 58 | + /* |
| 59 | + * A weirdness is that an object may already have been |
| 60 | + * exploded before the symlink entry is reached in the |
| 61 | + * ZipFile. So unlink any existing entry to avoid an |
| 62 | + * exception on creating the symlink. |
| 63 | + */ |
| 64 | + if (file.isDirectory()) { |
| 65 | + removeDirs(file); |
| 66 | + } else if (file.exists()) { |
| 67 | + file.delete(); |
| 68 | + } |
| 69 | + Files.createSymbolicLink(file.toPath(), target.toPath()); |
| 70 | + } else if (ze.isDirectory()) { |
| 71 | + file.mkdirs(); |
| 72 | + } else { |
| 73 | + try (InputStream in = zipfile.getInputStream(ze); |
| 74 | + OutputStream out = new FileOutputStream(file)) { |
| 75 | + if (in == null) { |
| 76 | + throw new IOException("Cannot get InputStream for " + ze); |
| 77 | + } |
| 78 | + copyFile(in, out); |
77 | 79 | } |
78 | | - copyFile(in, out); |
79 | 80 | } |
80 | 81 | } |
81 | 82 | } |
|
0 commit comments