List of usage examples for java.util.jar JarEntry getName
public String getName()
From source file:org.raspinloop.fmi.VMRunnerUtils.java
private static boolean containsClass(JarFile jarFile, String agentRunnerClassName) { Enumeration<JarEntry> e = jarFile.entries(); while (e.hasMoreElements()) { JarEntry je = e.nextElement(); if (je.isDirectory() || !je.getName().endsWith(".class")) { continue; }/* w w w . java 2s .c o m*/ // -6 because of .class String className = je.getName().substring(0, je.getName().length() - 6); className = className.replace('/', '.'); if (className.equals(agentRunnerClassName)) return true; } return false; }
From source file:org.jvnet.hudson.test.JellyTestSuiteBuilder.java
static Map<URL, String> scan(File resources, String extension) throws IOException { Map<URL, String> result = new HashMap<>(); if (resources.isDirectory()) { for (File f : FileUtils.listFiles(resources, new String[] { extension }, true)) { result.put(f.toURI().toURL(), f.getAbsolutePath().substring((resources.getAbsolutePath() + File.separator).length())); }//from ww w . java 2 s .c o m } else if (resources.getName().endsWith(".jar")) { String jarUrl = resources.toURI().toURL().toExternalForm(); JarFile jf = new JarFile(resources); Enumeration<JarEntry> e = jf.entries(); while (e.hasMoreElements()) { JarEntry ent = e.nextElement(); if (ent.getName().endsWith("." + extension)) { result.put(new URL("jar:" + jarUrl + "!/" + ent.getName()), ent.getName()); } } jf.close(); } return result; }
From source file:org.jiemamy.utils.ClassTraversal.java
/** * ??jar????/*ww w .j ava2s .c o m*/ * * @param jarFile Jar * @param handler ? * @throws TraversalHandlerException ??????? * @throws IllegalArgumentException ?{@code null}??? */ public static void forEach(JarFile jarFile, ClassHandler handler) throws TraversalHandlerException { Validate.notNull(jarFile); Validate.notNull(handler); boolean hasWarExtension = jarFile.getName().endsWith(WAR_FILE_EXTENSION); Enumeration<JarEntry> enumeration = jarFile.entries(); while (enumeration.hasMoreElements()) { JarEntry entry = enumeration.nextElement(); String entryName = entry.getName().replace('\\', '/'); if (entryName.endsWith(CLASS_EXTENSION)) { int startPos = hasWarExtension && entryName.startsWith(WEB_INF_CLASSES_PATH) ? WEB_INF_CLASSES_PATH.length() : 0; String className = entryName.substring(startPos, entryName.length() - CLASS_EXTENSION.length()) .replace('/', '.'); int pos = className.lastIndexOf('.'); String packageName = (pos == -1) ? null : className.substring(0, pos); String shortClassName = (pos == -1) ? className : className.substring(pos + 1); handler.processClass(packageName, shortClassName); } } }
From source file:com.igormaznitsa.jcp.it.maven.ITPreprocessorMojo.java
private static JarEntry findClassEntry(final JarAnalyzer jar, final String path) { for (final JarEntry e : (List<JarEntry>) jar.getClassEntries()) { if (path.equals(e.getName())) { return e; }/* w w w .j av a2 s. c o m*/ } return null; }
From source file:org.diffkit.common.DKUnjar.java
/** * closes inputStream_ at the end/* w w w .j a v a 2 s.c om*/ */ public static void unjar(JarInputStream inputStream_, File outputDir_) throws IOException { DKValidate.notNull(inputStream_, outputDir_); if (!outputDir_.isDirectory()) throw new RuntimeException(String.format("directory does not exist->%s", outputDir_)); JarEntry entry = null; while ((entry = inputStream_.getNextJarEntry()) != null) { File outFile = new File(outputDir_, entry.getName()); OutputStream outStream = new BufferedOutputStream(new FileOutputStream(outFile)); DKStreamUtil.copy(inputStream_, outStream); outStream.flush(); outStream.close(); } inputStream_.close(); }
From source file:com.apifest.oauth20.LifecycleEventHandlers.java
@SuppressWarnings("unchecked") public static void loadLifecycleHandlers(URLClassLoader classLoader, String customJar) { try {//from w w w. jav a2s . c o m if (classLoader != null) { JarFile jarFile = new JarFile(customJar); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (entry.isDirectory() || !entry.getName().endsWith(".class")) { continue; } // remove .class String className = entry.getName().substring(0, entry.getName().length() - 6); className = className.replace('/', '.'); try { // REVISIT: check for better solution if (className.startsWith("org.jboss.netty") || className.startsWith("org.apache.log4j") || className.startsWith("org.apache.commons")) { continue; } Class<?> clazz = classLoader.loadClass(className); if (clazz.isAnnotationPresent(OnRequest.class) && LifecycleHandler.class.isAssignableFrom(clazz)) { requestEventHandlers.add((Class<LifecycleHandler>) clazz); log.debug("preIssueTokenHandler added {}", className); } if (clazz.isAnnotationPresent(OnResponse.class) && LifecycleHandler.class.isAssignableFrom(clazz)) { responseEventHandlers.add((Class<LifecycleHandler>) clazz); log.debug("postIssueTokenHandler added {}", className); } if (clazz.isAnnotationPresent(OnException.class) && ExceptionEventHandler.class.isAssignableFrom(clazz)) { exceptionHandlers.add((Class<ExceptionEventHandler>) clazz); log.debug("exceptionHandlers added {}", className); } } catch (ClassNotFoundException e1) { // continue } } } } catch (MalformedURLException e) { log.error("cannot load lifecycle handlers", e); } catch (IOException e) { log.error("cannot load lifecycle handlers", e); } catch (IllegalArgumentException e) { log.error(e.getMessage()); } }
From source file:com.cisco.dbds.utils.configfilehandler.ConfigFileHandler.java
/** * Load jar cong file./*from ww w . ja va 2s .c o m*/ * * @param Utilclass the utilclass */ public static void loadJarCongFile(Class Utilclass) { try { String path = Utilclass.getResource("").getPath(); path = path.substring(6, path.length() - 1); path = path.split("!")[0]; System.out.println(path); JarFile jarFile = new JarFile(path); final Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { final JarEntry entry = entries.nextElement(); if (entry.getName().contains(".properties")) { System.out.println("Jar File Property File: " + entry.getName()); JarEntry fileEntry = jarFile.getJarEntry(entry.getName()); InputStream input = jarFile.getInputStream(fileEntry); setSystemvariable(input); InputStreamReader isr = new InputStreamReader(input); BufferedReader reader = new BufferedReader(isr); String line; while ((line = reader.readLine()) != null) { System.out.println("Jar file" + line); } reader.close(); } } jarFile.close(); } catch (Exception e) { System.out.println("Jar file reading Error"); } }
From source file:com.athomas.androidkickstartr.util.ResourcesUtils.java
private static void copyResourcesToFromJar(File target, URL url) throws IOException { JarURLConnection connection = (JarURLConnection) url.openConnection(); JarFile jarFile = connection.getJarFile(); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); InputStream is = jarFile.getInputStream(jarEntry); String entryPath = jarEntry.getName(); File file = null;/* w w w . ja v a2s .c om*/ String dirs = ""; if (entryPath.contains("/")) { int lastIndexOf = entryPath.lastIndexOf("/"); dirs = (String) entryPath.subSequence(0, lastIndexOf + 1); } File parent = new File(target, dirs); parent.mkdirs(); if (!jarEntry.isDirectory()) { String[] splitedPath = entryPath.split("/"); String fileName = splitedPath[splitedPath.length - 1]; file = new File(parent, fileName); FileUtils.copyInputStreamToFile(is, file); } } }
From source file:org.javaweb.utils.ClassUtils.java
/** * ?jarclass/*w w w. j a va 2s . c o m*/ * * @param url * @param classList * @throws IOException */ public static void getAllJarClass(URL url, Set<String> classList) throws IOException { if (url != null) { JarURLConnection juc = (JarURLConnection) url.openConnection(); JarFile jf = juc.getJarFile(); Enumeration<JarEntry> je = jf.entries(); while (je.hasMoreElements()) { JarEntry jar = je.nextElement(); if (jar.getName().endsWith(".class")) { String classPath = jar.getName().replaceAll("\\\\", "/").replaceAll("/+", "."); classList.add(classPath.substring(0, classPath.length() - ".class".length())); } } } }
From source file:org.apache.pluto.util.assemble.io.JarStreamingAssembly.java
private static JarEntry smartClone(JarEntry originalJarEntry) { final JarEntry newJarEntry = new JarEntry(originalJarEntry.getName()); newJarEntry.setComment(originalJarEntry.getComment()); newJarEntry.setExtra(originalJarEntry.getExtra()); newJarEntry.setMethod(originalJarEntry.getMethod()); newJarEntry.setTime(originalJarEntry.getTime()); //Must set size and CRC for STORED entries if (newJarEntry.getMethod() == ZipEntry.STORED) { newJarEntry.setSize(originalJarEntry.getSize()); newJarEntry.setCrc(originalJarEntry.getCrc()); }//w w w . ja v a2 s . c om return newJarEntry; }