List of usage examples for java.util Enumeration hasMoreElements
boolean hasMoreElements();
From source file:Main.java
/** * Converts the elements found in the given Enumeration into a list. *//*from w w w . j av a 2 s . c om*/ public static <T> List<T> asList(Enumeration<T> enu) { List<T> list = new ArrayList<T>(); while (enu != null && enu.hasMoreElements()) { list.add(enu.nextElement()); } return list; }
From source file:io.apiman.servers.gateway_es.Starter.java
/** * Loads properties from a file and puts them into system properties. *///from w w w. j av a 2s .c om @SuppressWarnings({ "nls", "unchecked" }) protected static void loadProperties() { URL configUrl = Starter.class.getClassLoader().getResource("gateway_es-apiman.properties"); if (configUrl == null) { throw new RuntimeException( "Failed to find properties file (see README.md): gateway_es-apiman.properties"); } InputStream is = null; try { is = configUrl.openStream(); Properties props = new Properties(); props.load(is); Enumeration<String> names = (Enumeration<String>) props.propertyNames(); while (names.hasMoreElements()) { String name = names.nextElement(); String value = props.getProperty(name); System.setProperty(name, value); } } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(is); } }
From source file:Main.java
public static String getLocalIpAddress() throws Exception { String ipAddress = null;/*from w w w .j a v a2 s .c o m*/ Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); while (en.hasMoreElements()) { NetworkInterface e = en.nextElement(); Enumeration<InetAddress> addresses = e.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress address = addresses.nextElement(); if (!address.isLoopbackAddress() && address.isSiteLocalAddress()) { ipAddress = address.getHostName(); break; } } } if (ipAddress == null) { ipAddress = InetAddress.getLocalHost().getHostAddress(); } return ipAddress; }
From source file:Main.java
public static String getLocalIpAddress() { try {// w w w.j a v a2s .c o m Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); while (en.hasMoreElements()) { NetworkInterface intf = en.nextElement(); String name = intf.getName(); if (name.compareTo("eth0") == 0 || name.compareTo("wlan0") == 0) { Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); while (enumIpAddr.hasMoreElements()) { InetAddress inetAddress = enumIpAddr.nextElement(); if (inetAddress.getClass() == Inet4Address.class) { return inetAddress.getHostAddress(); } } } } } catch (SocketException ex) { Log.e("MY", ex.toString()); } return null; }
From source file:Main.java
public static Collection toCollection(Enumeration _enum, Collection c) { if (c == null) c = new ArrayList(); while (_enum.hasMoreElements()) c.add(_enum.nextElement()); return c;/*from w ww. ja v a 2 s .com*/ }
From source file:Main.java
/** * Marshal the elements from the given enumeration into an array of the given type. Enumeration elements must be assignable to * the type of the given array. The array returned will be a different instance than the array given. *//*from w w w. j a v a2 s. c o m*/ public static <A, E extends A> A[] toArray(Enumeration<E> enumeration, A[] array) { ArrayList<A> elements = new ArrayList<>(); while (enumeration.hasMoreElements()) { elements.add(enumeration.nextElement()); } return elements.toArray(array); }
From source file:Main.java
/** * To check if the apk file is available to install. * /* w ww . ja va 2 s . com*/ * @param apkFilePath the apk file path * @return true if available, otherwise return false */ public static boolean isApkAvailable(String apkFilePath) { File apkFile = new File(apkFilePath); if (!apkFile.exists()) { return false; } try { ZipFile zipFile = new ZipFile(apkFile); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry zipEntry = entries.nextElement(); if (APK_MANIFEST.equals(zipEntry.getName())) { zipFile.close(); return true; } } zipFile.close(); } catch (Exception e) { return false; } return false; }
From source file:Main.java
/** * Dictionary does not have an equals./*from w w w . j av a 2s. c o m*/ * Please use Map.equals() * * <p>Follows the equals contract of Java 2's Map.</p> * * @since Ant 1.5 * @deprecated */ public static boolean equals(Dictionary d1, Dictionary d2) { if (d1 == d2) { return true; } if (d1 == null || d2 == null) { return false; } if (d1.size() != d2.size()) { return false; } Enumeration e1 = d1.keys(); while (e1.hasMoreElements()) { Object key = e1.nextElement(); Object value1 = d1.get(key); Object value2 = d2.get(key); if (value2 == null || !value1.equals(value2)) { return false; } } // don't need the opposite check as the Dictionaries have the // same size, so we've also covered all keys of d2 already. return true; }
From source file:Main.java
public static Vector createVector(Enumeration e) { Vector result = new Vector(); while (e.hasMoreElements()) result.addElement(e.nextElement()); return result; }
From source file:Main.java
public static InetAddress getHostAddress() { try {/* w w w. j av a 2s . co m*/ Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface iface = interfaces.nextElement(); // filters out 127.0.0.1 and inactive interfaces if (iface.isLoopback() || !iface.isUp()) continue; Enumeration<InetAddress> addresses = iface.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress addr = addresses.nextElement(); if (addr instanceof Inet4Address) return addr; } } } catch (SocketException e) { throw new RuntimeException(e); } return null; }