private byte[] loadWithSecurity(String path) throws IOException { URL scriptUrl = URLClassLoader.getSystemResource(path); if (scriptUrl.getProtocol().equals("jar")) { String jarPath = scriptUrl.getPath().substring(5, scriptUrl.getPath().indexOf("!")); JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8")); Enumeration<JarEntry> ens = jar.entries(); while (ens.hasMoreElements()) { JarEntry en = ens.nextElement(); if (!en.isDirectory()) { if (en.toString().equals(path)) { byte[] data = readAll(jar.getInputStream(en), en.getSize()); CodeSigner[] signers = en.getCodeSigners(); canLoadPack = signers != null && signers.length != 0; return data; } } } } return null; }
@Override protected void processJarEntry(JarFile jarFile, JarEntry jarEntry) throws IOException { /* * jarEntry.toStrng() will gives us eg. * - META-INF/ * - META-INF/MANIFEST.MF * etc. */ String _jarEntry = jarEntry.toString(); if (jarEntry.toString().startsWith(RESOURCE_PREFIX) && _jarEntry.length() > RESOURCE_PREFIX.length()) { // just so we don't get the root of the resource resources.add(jarEntry.toString()); } }
public JarredSource(JarEntry entry, JarOfTemplates jarOfTemplates) throws IOException { mJarEntry = entry; mJarOfTemplates = jarOfTemplates; mUrl = new URL(mJarOfTemplates.getUrl(), mJarEntry.toString()); }
protected static void discoverInJar(File file, List<String> controllerPackages) { String base = "app/controllers/"; try { JarFile jarFile = new JarFile(file); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); String path = jarEntry.toString(); if (path.startsWith(base) && !path.endsWith(".class") && !path.equals(base)) { controllerPackages.add(path.substring(base.length(), path.length() - 1).replace("/", ".")); } } } catch (Exception ignore) { } }
/** * Fetch all the entries in the given (jar) input stream and look for the * plugin directory. * @param is the input stream to analyse */ private Set<String> discoverJarPlugin(InputStream is) { Set<String> plugins = new HashSet<String>(); if (null==is) return plugins; JarEntry je = null; try { JarInputStream jis = new JarInputStream(is); do { je = jis.getNextJarEntry(); if (null != je) { String URL=je.toString(); if (URL.contains(PLUGIN_DIRECTORY) && URL.endsWith(PLUGIN_APSADMIN_PATH)) { plugins.add(URL); } } } while (je != null); } catch (Throwable t) { ApsSystemUtils.logThrowable(t, this, "discoverJarPlugin"); } return plugins; }
JarEntry file = (JarEntry) e.nextElement(); if (!file.toString().startsWith(insideJarRelativePath) ) { continue;
private static HashSet<String> readJarClassEntries(File file) throws FileNotFoundException, IOException, PatternSyntaxException { HashSet<String> set = new HashSet<String>(); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); JarInputStream is = new JarInputStream(bis); try { boolean end = false; while (!end) { JarEntry entry = is.getNextJarEntry(); if (entry != null) { // Filter only class files String entryName = entry.toString(); if (entryName.endsWith(".class")) { String className = translateClassEntry(entryName); set.add(className); } } else { end = true; } } } finally { is.close(); } return set; }
pkgnameTmp = pkgname.substring(1); // remove the leading "/" while (enm.hasMoreElements()) { if (enm.nextElement().toString().startsWith(pkgnameTmp)) { urlStr = "jar:file:" + classpathPart + "!" + pkgname; break;
pkgnameTmp = pkgname.substring(1); // remove the leading "/" while (enm.hasMoreElements()) { if (enm.nextElement().toString().startsWith(pkgnameTmp)) { urlStr = "jar:file:" + classpathPart + "!" + pkgname; break;
while (enumeration.hasMoreElements()) { JarEntry jarEntry = (JarEntry) enumeration.nextElement(); if (jarEntry.toString().endsWith(".class")) { String tmp = jarEntry.toString().replace('/', '.').replaceAll("\\.class", ""); if (!(tmp.indexOf(packageName) != -1)) continue; if (tmp.indexOf('$') != -1) continue;
while (enumeration.hasMoreElements()) { JarEntry jarEntry = (JarEntry) enumeration.nextElement(); if (jarEntry.toString().endsWith(".class")) { String tmp = jarEntry.toString().replace('/', '.').replaceAll("\\.class", ""); if (!(tmp.indexOf(packageName) != -1)) continue; if (tmp.indexOf('$') != -1) continue;
JarEntry entry = e.nextElement(); final String eName = entry.toString(); if( entry.isDirectory() || !eName.endsWith(".class") ) { continue; } final InputStream in = nyxletFile.getInputStream(entry);
} else { URL entryUrl = new URL(jarUrl + entry.toString()); RootedURL rurl = new RootedURL(jarUrl, entryUrl);
continue; } else { URL entryUrl = new URL(jarUrl + entry.toString()); RootedURL rurl = new RootedURL(jarUrl, entryUrl); if (((scan4Classes && isClassUrl(entryUrl))
JarFile jar = new JarFile(new File(jarURL.toURI())); JarEntry jarEntry = jar.getJarEntry(path.toString()); uri = new URI("jar:" + jarURL + "!/" + jarEntry.toString()); jar.close(); return uri;