List of usage examples for java.util Enumeration hasMoreElements
boolean hasMoreElements();
From source file:Main.java
/** * Convert the enumeration to a collection. * * @param enumeration The enumeration to convert to Collection. * @param <T> The type of object stored in the enumeration. * * @return A Collection containing all the elements of the enumeration. *//*from w ww . j av a 2 s . c om*/ public static <T> Collection<T> toCollection(Enumeration<T> enumeration) { Collection<T> collection = newList(25); while (enumeration.hasMoreElements()) { collection.add(enumeration.nextElement()); } return collection; }
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 ww w .j av a 2s . c o m*/ return null; }
From source file:Main.java
public static String readChannelString(String path, String prefixString) { String ret = null;//from w w w . j av a2s. c om ZipFile zipfile = null; try { zipfile = new ZipFile(path); Enumeration<?> entries = zipfile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = ((ZipEntry) entries.nextElement()); String entryName = entry.getName(); if (debug) { System.out.println(entryName); } if (entryName.contains(prefixString)) { ret = entryName; break; } } if (ret != null) { String[] split = ret.split("_"); if (split != null && split.length >= 2) { String substring = ret.substring(split[0].length() + 1); if (debug) { System.out.println(String.format("find channel string:%s", substring)); } return substring; } } else { if (debug) { System.out.println("not find channel"); } } } catch (IOException e) { e.printStackTrace(); } finally { if (zipfile != null) { try { zipfile.close(); } catch (IOException e) { e.printStackTrace(); } } } return ret; }
From source file:com.opoopress.maven.plugins.plugin.zip.ZipUtils.java
public static void unzipFileToDirectory(File file, File destDir, boolean keepTimestamp) throws IOException { // create output directory if it doesn't exist if (!destDir.exists()) destDir.mkdirs();//from ww w . j a v a 2 s . c o m ZipFile zipFile = new ZipFile(file); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.isDirectory()) { new File(destDir, entry.getName()).mkdirs(); continue; } InputStream inputStream = zipFile.getInputStream(entry); File destFile = new File(destDir, entry.getName()); System.out.println("Unzipping to " + destFile.getAbsolutePath()); FileUtils.copyInputStreamToFile(inputStream, destFile); IOUtils.closeQuietly(inputStream); if (keepTimestamp) { long time = entry.getTime(); if (time > 0) { destFile.setLastModified(time); } } } zipFile.close(); }
From source file:Main.java
public static String getIpInfo() { String ipInfo = null;/*from w w w . ja v a 2s .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:com.doculibre.constellio.wicket.utils.SimpleParamsUtils.java
@SuppressWarnings("unchecked") public static SimpleParams toSimpleParams(HttpServletRequest request) { SimpleParams params = new SimpleParams(); Enumeration<String> paramNames = request.getParameterNames(); while (paramNames.hasMoreElements()) { String paramName = (String) paramNames.nextElement(); List<String> paramValues = Arrays.asList(request.getParameterValues(paramName)); params.add(paramName, paramValues); }/*from w w w.j a v a 2 s . c om*/ return params; }
From source file:com.ironiacorp.persistence.SqlUtil.java
/** * Unload the database driver (if it's loaded). *///from w w w.j a v a2s . c o m public static void unloadDriver(String driver) { if (!SqlUtil.isDriverLoaded(driver)) { return; } Enumeration<Driver> drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { Driver d = drivers.nextElement(); if (d.getClass().getName().equals(driver)) { try { DriverManager.deregisterDriver(d); } catch (SQLException e) { } } } }
From source file:Main.java
public static String enumerationToString(Enumeration enm) { StringBuffer sb = new StringBuffer(100); boolean firstItem = true; sb.append("["); while (enm.hasMoreElements()) { if (!firstItem) { sb.append(", "); }/*ww w.j av a2s . co m*/ sb.append(enm.nextElement()); firstItem = false; } sb.append("]"); return sb.toString(); }
From source file:Main.java
public static String getHostIP() { String hostIp = null;//from w w w.j av a 2 s. com try { Enumeration nis = NetworkInterface.getNetworkInterfaces(); InetAddress ia = null; while (nis.hasMoreElements()) { NetworkInterface ni = (NetworkInterface) nis.nextElement(); Enumeration<InetAddress> ias = ni.getInetAddresses(); while (ias.hasMoreElements()) { ia = ias.nextElement(); if (ia instanceof Inet6Address) { continue;// skip ipv6 } String ip = ia.getHostAddress(); if (!"127.0.0.1".equals(ip)) { hostIp = ia.getHostAddress(); break; } } } } catch (SocketException e) { Log.i("yao", "SocketException"); e.printStackTrace(); } return hostIp; }
From source file:com.athomas.androidkickstartr.util.ResourcesUtils.java
private static void copyResourcesToFromJar(File target, URL url) throws IOException { JarURLConnection connection = (JarURLConnection) url.openConnection(); JarFile jarFile = connection.getJarFile(); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); InputStream is = jarFile.getInputStream(jarEntry); String entryPath = jarEntry.getName(); File file = null;/*from ww w . j a v a 2s. c o m*/ String dirs = ""; if (entryPath.contains("/")) { int lastIndexOf = entryPath.lastIndexOf("/"); dirs = (String) entryPath.subSequence(0, lastIndexOf + 1); } File parent = new File(target, dirs); parent.mkdirs(); if (!jarEntry.isDirectory()) { String[] splitedPath = entryPath.split("/"); String fileName = splitedPath[splitedPath.length - 1]; file = new File(parent, fileName); FileUtils.copyInputStreamToFile(is, file); } } }