List of usage examples for java.util Enumeration hasMoreElements
boolean hasMoreElements();
From source file:Main.java
/** * Check whether the given Enumeration contains the given element. * @param enumeration the Enumeration to check * @param element the element to look for * @return <code>true</code> if found, <code>false</code> else *///from w w w .j a v a 2s .c om public static boolean contains(Enumeration enumeration, Object element) { if (enumeration != null) { while (enumeration.hasMoreElements()) { Object candidate = enumeration.nextElement(); if (ObjectUtils.nullSafeEquals(candidate, element)) { return true; } } } return false; }
From source file:com.qatickets.common.HttpUtils.java
public static Map<String, String> extractParameters(HttpServletRequest req) { final Map<String, String> params = new HashMap<String, String>(); final Enumeration enames = req.getParameterNames(); while (enames.hasMoreElements()) { final String name = (String) enames.nextElement(); final String value = req.getParameter(name); params.put(name, value);/*from w w w.jav a 2 s .c o m*/ } return params; }
From source file:cn.leancloud.diamond.server.utils.SystemConfig.java
private static String getHostAddress() { String address = "127.0.0.1"; try {// w w w . ja v a2s . c o m Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); while (en.hasMoreElements()) { NetworkInterface ni = en.nextElement(); Enumeration<InetAddress> ads = ni.getInetAddresses(); while (ads.hasMoreElements()) { InetAddress ip = ads.nextElement(); if (!ip.isLoopbackAddress() && ip.isSiteLocalAddress()) { return ip.getHostAddress(); } } } } catch (Exception e) { } return address; }
From source file:local.edg.ClassDB.java
/** * Generates a data base with class informations about a given application * /*w ww.ja v a 2 s. com*/ * @param appClasses * The classes of the application as directories to class-files or as path to jar-files. * * @return Data base with class information. */ public static Map<String, Class> create(String[] appClasses) { ClassDbVisitor cv = new ClassDbVisitor(); for (String s : appClasses) { File f = new File(s); if (f.isDirectory()) { Collection<File> files = FileUtils.listFiles(f, new String[] { "class" }, true); for (File cf : files) { try { ClassReader cr = new ClassReader(new FileInputStream(cf)); cr.accept(cv, 0); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } else if (f.isFile() && s.toLowerCase().endsWith(".jar")) { try { ZipFile zf = new ZipFile(f); Enumeration<? extends ZipEntry> en = zf.entries(); while (en.hasMoreElements()) { ZipEntry e = en.nextElement(); String name = e.getName(); if (name.endsWith(".class")) { new ClassReader(zf.getInputStream(e)).accept(cv, 0); } } } catch (IOException e1) { e1.printStackTrace(); } } } return cv.getClassDb(); }
From source file:Main.java
public static <T> List<T> toList(Enumeration<? extends T> things) { AbstractList<T> list = new ArrayList<T>(); while (things.hasMoreElements()) { list.add(things.nextElement());//www.j a va 2s . co m } return list; }
From source file:edu.umd.cs.guitar.testcase.plugin.edg.ClassDB.java
/** * Generates a database containing class information about given application classes * @param appClasses The classes of an application as directories to class-files or as path to jar-files * @return Database containing class information *///from ww w. j a va2 s . c o m public static Map<String, Class> create(String[] appClasses) { ClassDBVisitor cv = new ClassDBVisitor(); for (String s : appClasses) { File f = new File(s); if (f.isDirectory()) { Collection<File> files = FileUtils.listFiles(f, new String[] { "class" }, true); for (File cf : files) { try { ClassReader cr = new ClassReader(new FileInputStream(cf)); cr.accept(cv, 0); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } else if (f.isFile() && s.toLowerCase().endsWith(".jar")) { try { ZipFile zf = new ZipFile(f); Enumeration<? extends ZipEntry> en = zf.entries(); while (en.hasMoreElements()) { ZipEntry e = en.nextElement(); String name = e.getName(); if (name.endsWith(".class")) { new ClassReader(zf.getInputStream(e)).accept(cv, 0); } } } catch (IOException e1) { e1.printStackTrace(); } } } return cv.getClassDb(); }
From source file:Main.java
/** * get all the classes name in "classes.dex", "classes2.dex", .... * * @param context the application context * @return all the classes name/*from w ww . j av a 2s . c o m*/ * @throws PackageManager.NameNotFoundException * @throws IOException */ public static List<String> getAllClasses(Context context) throws PackageManager.NameNotFoundException, IOException { List<String> classNames = new ArrayList<String>(); for (String path : getSourcePaths(context)) { try { DexFile dexfile = null; if (path.endsWith(EXTRACTED_SUFFIX)) { //NOT use new DexFile(path), because it will throw "permission error in /data/dalvik-cache" dexfile = DexFile.loadDex(path, path + ".tmp", 0); } else { dexfile = new DexFile(path); } Enumeration<String> dexEntries = dexfile.entries(); while (dexEntries.hasMoreElements()) { classNames.add(dexEntries.nextElement()); } } catch (IOException e) { throw new IOException("Error at loading dex file '" + path + "'"); } } return classNames; }
From source file:Main.java
public static String getIPAddr() { try {//from w w w . j av a2s. c om Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { NetworkInterface networkInterface = networkInterfaces.nextElement(); Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses(); while (inetAddresses.hasMoreElements()) { InetAddress inetAddress = inetAddresses.nextElement(); return inetAddress.getHostAddress().toString(); } } } catch (SocketException e) { e.printStackTrace(); } return null; }
From source file:com.manydesigns.elements.servlet.ServletUtils.java
public static void dumpRequestAttributes(HttpServletRequest request) { Enumeration attNames = request.getAttributeNames(); while (attNames.hasMoreElements()) { String attrName = (String) attNames.nextElement(); Object attrValue = request.getAttribute(attrName); logger.info("{} = {}", attrName, attrValue); }/*from w ww . j av a 2 s.c o m*/ }
From source file:com.skcraft.launcher.builder.BuilderUtils.java
public static ZipEntry getZipEntry(ZipFile jarFile, String path) { Enumeration<? extends ZipEntry> entries = jarFile.entries(); String expected = normalizePath(path); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); String test = normalizePath(entry.getName()); if (expected.equals(test)) { return entry; }/*from w w w. j av a 2 s . c o m*/ } return null; }