| 44 | } |
| 45 | |
| 46 | public static void extractJar(Path jarFilePath, Path destDir) throws IOException { |
| 47 | File jarFile = jarFilePath.toFile(); |
| 48 | try (JarFile file = new JarFile(jarFile)) { |
| 49 | Enumeration<JarEntry> entries = file.entries(); |
| 50 | while (entries.hasMoreElements()) { |
| 51 | JarEntry entry = entries.nextElement(); |
| 52 | if (!entry.isDirectory()) { |
| 53 | if (entry.getName().contains("..")) { |
| 54 | throw new IOException("Illegal character .. in entry name %s".formatted(entry.getName())); |
| 55 | } |
| 56 | Path entryFilePath = destDir.resolve(entry.getName()); |
| 57 | File entryFile = entryFilePath.toFile(); |
| 58 | File entryParent = entryFile.getParentFile(); |
| 59 | if (!entryParent.exists()) { |
| 60 | entryParent.mkdirs(); |
| 61 | } |
| 62 | try (InputStream inputStream = file.getInputStream(entry); |
| 63 | FileOutputStream outputStream = new FileOutputStream(entryFile)) { |
| 64 | byte[] buffer = new byte[1024]; |
| 65 | int bytesRead; |
| 66 | while ((bytesRead = inputStream.read(buffer)) != -1) { |
| 67 | outputStream.write(buffer, 0, bytesRead); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | public static void moveMapper(Path targetPath) { |
| 76 | try { |