@Override protected void scanJarFile(ClassLoader classloader, JarFile file) { Enumeration<JarEntry> entries = file.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (entry.isDirectory() || entry.getName().equals(JarFile.MANIFEST_NAME)) { continue; } resources.get(classloader).add(entry.getName()); } }
protected void addJarEntryToIndex(JarEntry entry, StringBuilder buffer) { // no need to show empty directories if (!entry.isDirectory()) { buffer.append(entry.getName()); buffer.append("\n"); } }
private void explodeNatives() throws IOException { URL urlOfJar = getJarURL(); LOGGER.info("[TFS SDK] Exploding natives from {} to folder {}", urlOfJar.toString(), tempFolder.getAbsolutePath()); JarInputStream jarStream = new JarInputStream(urlOfJar.openStream()); JarEntry entry; while ((entry = jarStream.getNextJarEntry()) != null) { if (!entry.isDirectory() && entry.getName().startsWith("tfssdk/native/")) { File newFile = new File(tempFolder, entry.getName()); newFile.getParentFile().mkdirs(); LOGGER.info("[TFS SDK] Extract {} -> {}", entry.getName(), newFile); try (OutputStream fos = new FileOutputStream(newFile)) { IOUtils.copy(jarStream, fos); } } } }
private void addParentFirstPatternsFromJar(File jar) throws IOException { JarFile jarFile = new JarFile(jar); jarFile.stream() .filter(jarEntry -> !jarEntry.isDirectory() && jarEntry.getName().endsWith(".class")) .map(jarEntry -> compileJarEntryPattern(trimDotClass(jarEntry.getName()))) .forEach(pattern -> parentFirst.add(pattern)); }
/** * 扫描jar包 * * @param jar jar包 */ private void scanJar(JarFile jar) { String name; for (JarEntry entry : new EnumerationIter<>(jar.entries())) { name = StrUtil.removePrefix(entry.getName(), StrUtil.SLASH); if (name.startsWith(this.packagePath)) { if (name.endsWith(FileUtil.CLASS_EXT) && false == entry.isDirectory()) { final String className = name// .substring(0, name.length() - 6)// .replace(CharUtil.SLASH, CharUtil.DOT);// addIfAccept(loadClass(className)); } } } }
@Override protected void scanJarFile(ClassLoader classloader, JarFile file) { Enumeration<JarEntry> entries = file.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (entry.isDirectory() || entry.getName().equals(JarFile.MANIFEST_NAME)) { continue; } resources.get(classloader).add(entry.getName()); } }
private static void extract(JarFile jar, JarEntry file) throws IOException { Path workingDirectory = Paths.get("").toAbsolutePath(); File target = new File(workingDirectory.toString() + File.separator + file.getName()); if (target.exists()) return; if (file.isDirectory()) { target.mkdir(); return; } Files.copy(jar.getInputStream(file), target.toPath()); }
private URL[] enumerateJar(URL urlOfJar) { LOGGER.debug("Enumerating jar: {}", urlOfJar); List<URL> urls = new ArrayList<>(); urls.add(urlOfJar); try { JarInputStream jarStream = new JarInputStream(urlOfJar.openStream()); JarEntry entry; while ((entry = jarStream.getNextJarEntry()) != null) { if (!entry.isDirectory() && entry.getName().endsWith(".jar")) { urls.add(expandJarAndReturnURL(jarStream, entry)); } } } catch (IOException e) { LOGGER.error("Failed to enumerate jar {}", urlOfJar, e); } return urls.toArray(new URL[0]); }
/** * 扫描jar包 * * @param jar jar包 */ private void scanJar(JarFile jar) { String name; for (JarEntry entry : new EnumerationIter<>(jar.entries())) { name = StrUtil.removePrefix(entry.getName(), StrUtil.SLASH); if (name.startsWith(this.packagePath)) { if (name.endsWith(FileUtil.CLASS_EXT) && false == entry.isDirectory()) { final String className = name// .substring(0, name.length() - 6)// .replace(CharUtil.SLASH, CharUtil.DOT);// addIfAccept(loadClass(className)); } } } }
@Override protected void scanJarFile(ClassLoader classloader, JarFile file) { Enumeration<JarEntry> entries = file.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (entry.isDirectory() || entry.getName().equals(JarFile.MANIFEST_NAME)) { continue; } resources.get(classloader).add(entry.getName()); } }
@SuppressWarnings("ResultOfMethodCallIgnored") private void copyFromJarToLocation(final JarFile jarFile, final JarEntry entry, final String fromRoot, final File toRoot) throws IOException { String destinationName = entry.getName().replaceFirst(fromRoot, ""); File newFile = new File(toRoot, destinationName); log.debug("Copying resource {} from JAR file {}", fromRoot, jarFile.getName()); if (!entry.isDirectory()) { // Create parent directories Path parent = newFile.getAbsoluteFile().toPath().getParent(); parent.toFile().mkdirs(); newFile.deleteOnExit(); try (InputStream is = jarFile.getInputStream(entry)) { Files.copy(is, newFile.toPath()); } catch (IOException e) { log.error("Failed to extract classpath resource " + entry.getName() + " from JAR file " + jarFile.getName(), e); throw e; } } }
@Override public boolean hasNext() { if (next == null) { try { do { this.next = jarInputStream.getNextJarEntry(); if (next == null) { break; } if (!next.isDirectory() && next.getName().startsWith(parent)) { if (recursive || next.getName().substring(parent.length()).indexOf(JAR_FILE_SEPARATOR) == -1) { break; } } } while (true); } catch (final IOException | SecurityException e) { LOGGER.log(Level.CONFIG, LocalizationMessages.JAR_SCANNER_UNABLE_TO_READ_ENTRY(), e); return false; } } if (next == null) { close(); return false; } return true; }
public List<String> getAllEntriesFromJar() { List<String> mass = new ArrayList<>(); Enumeration<JarEntry> entries = jfile.entries(); while (entries.hasMoreElements()) { JarEntry e = entries.nextElement(); if (!e.isDirectory()) { mass.add(e.getName()); } } return mass; }
JarEntry entry; while ((entry = jis.getNextJarEntry()) != null) { if (entry.isDirectory()) { File dir = new File(destDir, entry.getName()); dir.mkdir(); if (entry.getTime() != -1) { File destFile = new File(destDir, entry.getName()); if (mVerbose) { System.out.println("unjarring " + destFile + " from " + entry.getName());
@Override public boolean hasNext() { if (next == null) { try { do { this.next = jarInputStream.getNextJarEntry(); if (next == null) { break; } if (!next.isDirectory() && next.getName().startsWith(parent)) { if (recursive || next.getName().substring(parent.length()).indexOf(JAR_FILE_SEPARATOR) == -1) { break; } } } while (true); } catch (final IOException | SecurityException e) { LOGGER.log(Level.CONFIG, LocalizationMessages.JAR_SCANNER_UNABLE_TO_READ_ENTRY(), e); return false; } } if (next == null) { close(); return false; } return true; }
@Override protected void scanJarFile(ClassLoader classloader, JarFile file) { Enumeration<JarEntry> entries = file.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (entry.isDirectory() || entry.getName().equals(JarFile.MANIFEST_NAME)) { continue; } resources.get(classloader).add(entry.getName()); } }
entry != null; entry = jar.getNextJarEntry()) { if (!entry.isDirectory() && unpackRegex.matcher(entry.getName()).matches()) { File file = new File(toDir, entry.getName()); if (!file.getCanonicalPath().startsWith(targetDirPath)) { throw new IOException("expanding " + entry.getName() + " would create file outside of " + toDir);
/** * @param file File. * @throws Exception In case of error. */ private void processFile(File file, int prefixLen) throws Exception { if (!file.exists()) throw new FileNotFoundException("File doesn't exist: " + file); if (file.isDirectory()) { for (File f : file.listFiles()) processFile(f, prefixLen); } else { assert file.isFile(); String path = file.getPath(); if (path.toLowerCase().endsWith(".jar")) { try (JarInputStream jin = new JarInputStream(new BufferedInputStream(new FileInputStream(path)))) { JarEntry entry; while ((entry = jin.getNextJarEntry()) != null) { if (!entry.isDirectory() && entry.getName().toLowerCase().endsWith(".class")) processClassFile(entry.getName(), 0); } } } else if (path.toLowerCase().endsWith(".class")) processClassFile(path, prefixLen); } }
Enumeration<JarEntry> e = jar.entries(); while (e.hasMoreElements()) { JarEntry entry = e.nextElement(); if (entry.isDirectory()) { if (entry.getName().toUpperCase().equals("META-INF/")) { continue; map.put(new URL(jarURL.toExternalForm() + entry.getName()), packageNameFor(entry)); } catch (MalformedURLException murl) {
File jsonFile = new File(artifactFile, "META-INF/glowroot.plugin.json"); if (!jsonFile.exists()) { return null; JarEntry jarEntry; while ((jarEntry = jarIn.getNextJarEntry()) != null) { String name = jarEntry.getName(); if (jarEntry.isDirectory()) { continue;