List of usage examples for java.util Enumeration hasMoreElements
boolean hasMoreElements();
From source file:Main.java
public static void expandTree(JTree tree) { DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot(); @SuppressWarnings("unchecked") Enumeration<DefaultMutableTreeNode> e = root.breadthFirstEnumeration(); while (e.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement(); if (node.isLeaf()) continue; int row = tree.getRowForPath(new TreePath(node.getPath())); tree.expandRow(row);/* w w w . j a v a 2 s . c om*/ } }
From source file:Main.java
/** * Create a Hashtable from a key, value, key, value... style * Enumeration./* w ww. j av a2s.c o m*/ */ public static Hashtable createHashtable(Enumeration e) { Hashtable result = new Hashtable(); while (e.hasMoreElements()) result.put(e.nextElement(), e.nextElement()); return result; }
From source file:LocalAddress.java
/** * Return an address of a non-loopback interface on the local host * //from ww w . ja v a 2 s . c o m * @return address * the InetAddress of the local host */ public static InetAddress getLocalAddress() { InetAddress addr = null; try { addr = InetAddress.getLocalHost(); // OK - is this the loopback addr ? if (!addr.isLoopbackAddress()) { return addr; } // plan B - enumerate the network interfaces Enumeration ifaces = NetworkInterface.getNetworkInterfaces(); while (ifaces.hasMoreElements()) { NetworkInterface netIf = (NetworkInterface) ifaces.nextElement(); Enumeration addrs = netIf.getInetAddresses(); while (addrs.hasMoreElements()) { addr = (InetAddress) addrs.nextElement(); //System.out.println( "enum: " + addr.getHostAddress() ); if (addr instanceof Inet6Address) { // probably not what we want - keep looking continue; } // chose (arbitrarily?) first non-loopback addr if (!addr.isLoopbackAddress()) { return addr; } } } // nothing so far - last resort return getReflectedAddress(); } catch (UnknownHostException uhE) { // deal with this } catch (SocketException sockE) { // can deal? } return null; }
From source file:Main.java
public static String getIpAddress(boolean alwaysGetWifi) { try {// w w w . java 2 s. c om Enumeration<NetworkInterface> enmNetI = NetworkInterface.getNetworkInterfaces(); while (enmNetI.hasMoreElements()) { NetworkInterface networkInterface = enmNetI.nextElement(); boolean b = alwaysGetWifi ? networkInterface.getDisplayName().equals("wlan0") || networkInterface.getDisplayName().equals("eth0") : true; if (b) { Enumeration<InetAddress> inetAddressEnumeration = networkInterface.getInetAddresses(); while (inetAddressEnumeration.hasMoreElements()) { InetAddress inetAddress = inetAddressEnumeration.nextElement(); if (inetAddress instanceof Inet4Address && !inetAddress.isLoopbackAddress()) { return "net name is " + networkInterface.getDisplayName() + ",ip is " + inetAddress.getHostAddress(); } } } } } catch (SocketException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static Collection<?> list(final Enumeration<?> e) { final ArrayList<Object> l = new ArrayList<Object>(); if (e != null) { while (e.hasMoreElements()) { final Object object = e.nextElement(); if (object != null) { l.add(object);// w w w .j a v a 2 s .co m } } } return l; }
From source file:com.bank.manager.configs.ContextCleanupListener.java
/** * Find all ServletContext attributes which implement {@link DisposableBean} * and destroy them, removing all affected ServletContext attributes eventually. * @param sc the ServletContext to check *///from w ww . ja v a 2 s. co m static void cleanupAttributes(ServletContext sc) { Enumeration<String> attrNames = sc.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = attrNames.nextElement(); if (attrName.startsWith("org.springframework.")) { Object attrValue = sc.getAttribute(attrName); if (attrValue instanceof DisposableBean) { try { ((DisposableBean) attrValue).destroy(); } catch (Throwable ex) { logger.error("Couldn't invoke destroy method of attribute with name '" + attrName + "'", ex); } } } } }
From source file:com.zergiu.tvman.TVMan.java
private static void configureLoggers(TVManOptions options) { if (options.isDebug()) { org.apache.log4j.Logger log4JLogging = org.apache.log4j.Logger.getLogger("com.zergiu.tvman"); log4JLogging.setLevel(Level.DEBUG); }//from w w w . j a v a 2s . c o m if (options.isQuiet()) { org.apache.log4j.Logger log4JLogging = org.apache.log4j.Logger.getRootLogger(); Enumeration<?> loggers = log4JLogging.getLoggerRepository().getCurrentLoggers(); while (loggers.hasMoreElements()) { org.apache.log4j.Logger logger = (org.apache.log4j.Logger) loggers.nextElement(); logger.setLevel(Level.ERROR); } log4JLogging.setLevel(Level.ERROR); } }
From source file:Main.java
/** * Uncompresses zipped files//from w w w. j a v a2s . co m * @param zippedFile The file to uncompress * @param destinationDir Where to put the files * @return list of unzipped files * @throws java.io.IOException thrown if there is a problem finding or writing the files */ public static List<File> unzip(File zippedFile, File destinationDir) throws IOException { int buffer = 2048; List<File> unzippedFiles = new ArrayList<File>(); BufferedOutputStream dest; BufferedInputStream is; ZipEntry entry; ZipFile zipfile = new ZipFile(zippedFile); Enumeration e = zipfile.entries(); while (e.hasMoreElements()) { entry = (ZipEntry) e.nextElement(); is = new BufferedInputStream(zipfile.getInputStream(entry)); int count; byte data[] = new byte[buffer]; File destFile; if (destinationDir != null) { destFile = new File(destinationDir, entry.getName()); } else { destFile = new File(entry.getName()); } FileOutputStream fos = new FileOutputStream(destFile); dest = new BufferedOutputStream(fos, buffer); try { while ((count = is.read(data, 0, buffer)) != -1) { dest.write(data, 0, count); } unzippedFiles.add(destFile); } finally { dest.flush(); dest.close(); is.close(); } } return unzippedFiles; }
From source file:Main.java
public static InetAddress getLocalInetAddress() { InetAddress ip = null;//from ww w . j ava 2 s. c o m try { Enumeration<NetworkInterface> en_netInterface = NetworkInterface.getNetworkInterfaces(); while (en_netInterface.hasMoreElements()) { NetworkInterface ni = (NetworkInterface) en_netInterface.nextElement(); Enumeration<InetAddress> en_ip = ni.getInetAddresses(); while (en_ip.hasMoreElements()) { ip = en_ip.nextElement(); if (!ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1) break; else ip = null; } if (ip != null) { break; } } } catch (SocketException e) { e.printStackTrace(); } return ip; }
From source file:Main.java
/** * Iterates over APK (jar entries) to populate * //from ww w . j a v a 2 s . c o m * @param projectFile * @return * @throws IOException * @throws CertificateException */ public static List<Certificate> populateCertificate(File projectFile) throws IOException, CertificateException { List<Certificate> certList = new ArrayList<Certificate>(); JarFile jar = new JarFile(projectFile); Enumeration<JarEntry> jarEntries = jar.entries(); while (jarEntries.hasMoreElements()) { JarEntry entry = jarEntries.nextElement(); if (entry.getName().toLowerCase().contains(DSA) || entry.getName().toLowerCase().contains(RSA)) { certList.addAll(extractCertificate(jar, entry)); } } return certList; }