List of usage examples for java.util Enumeration nextElement
E nextElement();
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} if found, {@code false} else *///from www .j a v a 2 s .com public static boolean contains(Enumeration<?> enumeration, Object element) { if (enumeration != null) { while (enumeration.hasMoreElements()) { Object candidate = enumeration.nextElement(); if (Objects.equals(candidate, element)) return true; } } return false; }
From source file:Main.java
private static List<InputStream> loadResources(String name, ClassLoader classLoader) throws IOException { final List<InputStream> list = new ArrayList<InputStream>(); final Enumeration<URL> systemResources = (classLoader == null ? ClassLoader.getSystemClassLoader() : classLoader).getResources(name); while (systemResources.hasMoreElements()) { list.add(systemResources.nextElement().openStream()); }//from w w w.j a v a2 s . c o m return list; }
From source file:info.magnolia.cms.filters.MultipartRequestFilter.java
/** * Adds all request paramaters as request attributes. * @param request HttpServletRequest//from w w w. ja va 2s.com */ private static void parseParameters(HttpServletRequest request) throws IOException { MultipartForm form = new MultipartForm(); String encoding = StringUtils.defaultString(request.getCharacterEncoding(), "UTF-8"); //$NON-NLS-1$ MultipartRequest multi = new MultipartRequest(request, Path.getTempDirectoryPath(), MAX_FILE_SIZE, encoding, null); Enumeration params = multi.getParameterNames(); while (params.hasMoreElements()) { String name = (String) params.nextElement(); String value = multi.getParameter(name); form.addParameter(name, value); String[] s = multi.getParameterValues(name); if (s != null) { form.addparameterValues(name, s); } } Enumeration files = multi.getFileNames(); while (files.hasMoreElements()) { String name = (String) files.nextElement(); form.addDocument(name, multi.getFilesystemName(name), multi.getContentType(name), multi.getFile(name)); } request.setAttribute(MultipartForm.REQUEST_ATTRIBUTE_NAME, form); }
From source file:local.edg.ClassDB.java
/** * Generates a data base with class informations about a given application * /*from w ww . ja va 2s . c o m*/ * @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 String getIpInfo() { String ipInfo = null;/* w ww . ja v a2 s.co m*/ try { Enumeration<NetworkInterface> faces = NetworkInterface.getNetworkInterfaces(); LOOP: while (faces.hasMoreElements()) { Enumeration<InetAddress> addresses = faces.nextElement().getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress inetAddress = addresses.nextElement(); if (!inetAddress.isLoopbackAddress()) { ipInfo = inetAddress.getHostAddress().toString(); break LOOP; } } } } catch (Exception e) { } if (TextUtils.isEmpty(ipInfo)) { ipInfo = ""; } return ipInfo; }
From source file:cn.leancloud.diamond.server.utils.SystemConfig.java
private static String getHostAddress() { String address = "127.0.0.1"; try {/* w w w . j a va 2s . 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: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 w w w . ja v a 2s .co 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
public static List<File> unzip(File zip, File toDir) throws IOException { ZipFile zf = null;// w ww.ja v a 2s . co m List<File> files = null; try { zf = new ZipFile(zip); files = new ArrayList<File>(); Enumeration<?> entries = zf.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); if (entry.isDirectory()) { new File(toDir, entry.getName()).mkdirs(); continue; } InputStream input = null; OutputStream output = null; try { File f = new File(toDir, entry.getName()); input = zf.getInputStream(entry); output = new FileOutputStream(f); copy(input, output); files.add(f); } finally { closeQuietly(output); closeQuietly(input); } } } finally { if (zf != null) { zf.close(); } } return files; }
From source file:com.qatickets.common.HttpUtils.java
public static Map<String, String> getHeadersAsMap(HttpServletRequest req) { final Map<String, String> headers = new HashMap<String, String>(); final Enumeration enames = req.getHeaderNames(); while (enames.hasMoreElements()) { final String name = (String) enames.nextElement(); final String value = req.getHeader(name); headers.put(name, value);//from www . j av a 2 s . com } return headers; }
From source file:com.jaeksoft.searchlib.util.NetworksUtils.java
public static final String getFirstHardwareAddress() throws URISyntaxException, UnknownHostException, SocketException { InetAddress localhost = InetAddress.getLocalHost(); String hardwareAddress = null; if (localhost != null) hardwareAddress = getHardwareAddress(NetworkInterface.getByInetAddress(localhost)); if (hardwareAddress != null) return hardwareAddress; Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { hardwareAddress = getHardwareAddress(networkInterfaces.nextElement()); if (hardwareAddress != null) return hardwareAddress; }/*from w ww.j a va 2 s . c o m*/ return null; }