private static void loadFilterConfig(Properties filterProperties, ClassLoader classLoader) throws IOException { if (classLoader == null) { return; } for (Enumeration<URL> e = classLoader.getResources("META-INF/druid-filter.properties"); e.hasMoreElements();) { URL url = e.nextElement(); Properties property = new Properties(); InputStream is = null; try { is = url.openStream(); property.load(is); } finally { JdbcUtils.close(is); } filterProperties.putAll(property); } }
private static HttpHeaders createDefaultHttpHeaders(HttpServletRequest request) { HttpHeaders headers = new HttpHeaders(); for (Enumeration<?> names = request.getHeaderNames(); names.hasMoreElements(); ) { String name = (String) names.nextElement(); for (Enumeration<?> values = request.getHeaders(name); values.hasMoreElements(); ) { headers.add(name, (String) values.nextElement()); } } return headers; }
/** * Copy the configured output {@link Properties}, if any, into the * {@link Transformer#setOutputProperty output property set} of the supplied * {@link Transformer}. * @param transformer the target transformer */ protected final void copyOutputProperties(Transformer transformer) { if (this.outputProperties != null) { Enumeration<?> en = this.outputProperties.propertyNames(); while (en.hasMoreElements()) { String name = (String) en.nextElement(); transformer.setOutputProperty(name, this.outputProperties.getProperty(name)); } } }
@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()); } }
Properties props = new Properties(); try { Enumeration<URL> resources = classLoader.getResources("META-INF/io.netty.versions.properties"); while (resources.hasMoreElements()) { URL url = resources.nextElement(); InputStream in = url.openStream(); try { props.load(in); } finally { try { in.close(); } catch (Exception ignore) { for (Object o: props.keySet()) { String k = (String) o;
Properties props = new Properties(); while (urls.hasMoreElements()) { URL url = urls.nextElement(); URLConnection con = url.openConnection(); ResourceUtils.useCachesIfNecessary(con); InputStream is = con.getInputStream(); try { if (resourceName.endsWith(XML_FILE_EXTENSION)) { props.loadFromXML(is); props.load(is); is.close();
protected String getCommandFromManifest() { try { Enumeration<URL> resources = RunCommand.class.getClassLoader().getResources("META-INF/MANIFEST.MF"); while (resources.hasMoreElements()) { InputStream stream = resources.nextElement().openStream(); Manifest manifest = new Manifest(stream); Attributes attributes = manifest.getMainAttributes(); String mainClass = attributes.getValue("Main-Class"); if (main.getClass().getName().equals(mainClass)) { String command = attributes.getValue("Main-Command"); if (command != null) { stream.close(); return command; } } stream.close(); } } catch (IOException e) { throw new IllegalStateException(e.getMessage()); } return null; }
Hashtable filters = new Hashtable(); Enumeration e = props.keys(); String name = ""; while (e.hasMoreElements()) { String key = (String) e.nextElement(); if (key.startsWith(filterPrefix)) { int dotIdx = key.indexOf('.', fIdx); name = key.substring(dotIdx+1); filterOpts.add(new NameValue(name, value)); while (g.hasMoreElements()) { String key = (String) g.nextElement(); String clazz = props.getProperty(key); if (clazz != null) { LogLog.debug("Filter key: ["+key+"] class: ["+props.getProperty(key) +"] props: "+filters.get(key)); Filter filter = (Filter) OptionConverter.instantiateByClassName(clazz, Filter.class, null); if (filter != null) { PropertySetter propSetter = new PropertySetter(filter); Vector v = (Vector)filters.get(key); Enumeration filterProps = v.elements(); while (filterProps.hasMoreElements()) { NameValue kv = (NameValue)filterProps.nextElement(); propSetter.setProperty(kv.key, kv.value);
jar = new JarFile(new File(jarFile.toURI())); final List<JarEntry> containedJarFileEntries = new ArrayList<JarEntry>(); Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); String name = entry.getName(); for (int i = 0; i < containedJarFileEntries.size(); i++) { final JarEntry entry = containedJarFileEntries.get(i); String name = entry.getName(); throw new ProgramInvocationException( "An I/O error occurred while creating temporary file to extract nested library '" + entry.getName() + "'.", e); in = new BufferedInputStream(jar.getInputStream(entry)); while ((numRead = in.read(buffer)) != -1) { out.write(buffer, 0, numRead); in.close();
@Override public Enumeration keys() { Enumeration keysEnum = super.keys(); Vector<String> keyList = new Vector<>(); while (keysEnum.hasMoreElements()) { keyList.add((String)keysEnum.nextElement()); } Collections.sort(keyList); return keyList.elements(); }
@Override public Map<String, String[]> getParameterMap() { Map<String, String[]> result = new LinkedHashMap<>(); Enumeration<String> names = getParameterNames(); while (names.hasMoreElements()) { String name = names.nextElement(); result.put(name, getParameterValues(name)); } return result; }
public void setColumnMargin(int margin) { this.margin = margin; Enumeration<Object> enumeration = vector.elements(); while (enumeration.hasMoreElements()) { Object obj = enumeration.nextElement(); if (obj instanceof ColumnGroup) { ((ColumnGroup) obj).setColumnMargin(margin); } } }
JarFile jar = null; try { jarURL = new URL("file:/" + file.getCanonicalPath()); jarURL = new URL("jar:" + jarURL.toExternalForm() + "!/"); JarURLConnection conn = (JarURLConnection) jarURL.openConnection(); jar = conn.getJarFile(); 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) {
public static String getVersion() { try { ClassLoader classLoader = Jadx.class.getClassLoader(); if (classLoader != null) { Enumeration<URL> resources = classLoader.getResources("META-INF/MANIFEST.MF"); while (resources.hasMoreElements()) { Manifest manifest = new Manifest(resources.nextElement().openStream()); String ver = manifest.getMainAttributes().getValue("jadx-version"); if (ver != null) { return ver; } } } } catch (Exception e) { LOG.error("Can't get manifest file", e); } return "dev"; } }
/** * Set the mappings of bean keys to a comma-separated list of method names. * The property key should match the bean key and the property value should match * the list of method names. When searching for method names for a bean, Spring * will check these mappings first. * @param mappings the mappings of bean keys to method names */ public void setMethodMappings(Properties mappings) { this.methodMappings = new HashMap<>(); for (Enumeration<?> en = mappings.keys(); en.hasMoreElements();) { String beanKey = (String) en.nextElement(); String[] methodNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey)); this.methodMappings.put(beanKey, new HashSet<>(Arrays.asList(methodNames))); } }
@Override public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String uri = request.getRequestURI(); HessianSkeleton skeleton = skeletonMap.get(uri); if (!request.getMethod().equalsIgnoreCase("POST")) { response.setStatus(500); } else { RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort()); Enumeration<String> enumeration = request.getHeaderNames(); while (enumeration.hasMoreElements()) { String key = enumeration.nextElement(); if (key.startsWith(Constants.DEFAULT_EXCHANGER)) { RpcContext.getContext().setAttachment(key.substring(Constants.DEFAULT_EXCHANGER.length()), request.getHeader(key)); } } try { skeleton.invoke(request.getInputStream(), response.getOutputStream()); } catch (Throwable e) { throw new ServletException(e); } } }
List<FileMeta> getResourceListing(URL dirURL, String path) throws IOException { List<FileMeta> listFiles = new ArrayList<>(); if (null == CACHE_JAR_FILE) { //strip out only the JAR file String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); CACHE_JAR_FILE = new JarFile(URLDecoder.decode(jarPath, "UTF-8")); } Enumeration<JarEntry> entries = CACHE_JAR_FILE.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); String name = jarEntry.getName(); if (!name.startsWith(path) || name.equals(path + "/")) { continue; } FileMeta fileMeta = new FileMeta(); fileMeta.name = name.substring(path.length() + 1); fileMeta.isDirectory = jarEntry.isDirectory(); if (!fileMeta.isDirectory) { fileMeta.length = jarEntry.getSize(); } listFiles.add(fileMeta); } return listFiles; }
throws IOException { URLConnection con = rootDirURL.openConnection(); JarFile jarFile; String jarFileUrl; ResourceUtils.useCachesIfNecessary(jarCon); jarFile = jarCon.getJarFile(); jarFileUrl = jarCon.getJarFileURL().toExternalForm(); JarEntry jarEntry = jarCon.getJarEntry(); rootEntryPath = (jarEntry != null ? jarEntry.getName() : ""); closeJarFile = !jarCon.getUseCaches(); String urlFile = rootDirURL.getFile(); try { int separatorIndex = urlFile.indexOf(ResourceUtils.WAR_URL_SEPARATOR); jarFile = new JarFile(urlFile); jarFileUrl = urlFile; rootEntryPath = ""; for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) { JarEntry entry = entries.nextElement(); String entryPath = entry.getName(); if (entryPath.startsWith(rootEntryPath)) { String relativePath = entryPath.substring(rootEntryPath.length()); jarFile.close();
private static void extractContents() { // Check if we're running inside a JAR file if(!LoklakServer.class.getResource("LoklakServer.class").getPath().startsWith("file:")) return; try { JarFile jar = new JarFile(LoklakServer.class.getProtectionDomain().getCodeSource().getLocation().getPath()); Enumeration entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry file = (JarEntry) entries.nextElement(); for (String s : FOLDER_TO_EXTRACT) { if (file.getName().startsWith(s + File.separator)) { extract(jar, file); continue; } } } } catch (IOException e) { DAO.severe("An exception has occurred while extracting contents from JAR File", e); DAO.log("Exiting due to fatal error ..."); System.exit(1); } }
/** * This method is periodically invoked so that memory * footprint will be minimized. */ void compress() { if (compressCount++ > COMPRESS_THRESHOLD) { compressCount = 0; Enumeration e = classes.elements(); while (e.hasMoreElements()) ((CtClass)e.nextElement()).compress(); } }