MCPcopy Create free account
hub / github.com/LFYSec/MScan / extractJar

Method extractJar

src/main/java/fdu/secsys/microservice/util/JarUtil.java:46–73  ·  view source on GitHub ↗
(Path jarFilePath, Path destDir)

Source from the content-addressed store, hash-verified

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 {

Callers 1

parseJarMethod · 0.95

Calls 4

entriesMethod · 0.80
containsMethod · 0.65
getNameMethod · 0.65
resolveMethod · 0.45

Tested by

no test coverage detected