List of usage examples for java.util Enumeration nextElement
E nextElement();
From source file:Main.java
public static <E> Iterator<E> asIterator(final Enumeration<E> e) { return new Iterator<E>() { @Override// w w w . j a v a 2s. co m public boolean hasNext() { return e.hasMoreElements(); } @Override public E next() { return e.nextElement(); } @Override public void remove() { throw new UnsupportedOperationException(); } }; }
From source file:com.frostwire.util.VPNs.java
private static boolean isAnyNetworkInterfaceATunnel() { boolean result = false; try {/* w ww . j av a 2 s .co m*/ Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { NetworkInterface iface = networkInterfaces.nextElement(); if (iface.getDisplayName().contains("tun")) { result = true; break; } } } catch (Throwable e) { e.printStackTrace(); } return result; }
From source file:com.ephesoft.dcma.util.NetworkUtil.java
/** * Utility method which will fetch the ip address of the system. * // w w w. j av a 2 s . c om * @return ip address of the system. */ public static String getSystemIPAddress() { StringBuilder input = new StringBuilder(UtilConstants.INPUT_CONST); boolean first = true; String returnAddress = null; try { for (Enumeration<NetworkInterface> enumer = NetworkInterface.getNetworkInterfaces(); enumer .hasMoreElements();) { NetworkInterface netInterface = enumer.nextElement(); Enumeration<InetAddress> inetEnum = netInterface.getInetAddresses(); while (inetEnum.hasMoreElements()) { InetAddress inetAddress = inetEnum.nextElement(); if (!inetAddress.isLoopbackAddress()) { if (first) { first = false; } else { input.append(UtilConstants.FORWARD_SLASH); } input.append(inetAddress.getHostAddress()); } } } } catch (Exception e) { LOG.error(e.getMessage(), e); returnAddress = IPADDRESS; } if (null == returnAddress) { returnAddress = first ? IPADDRESS : input.toString(); } return returnAddress; }
From source file:com.hw.util.CompressUtils.java
private static void unzipFolder(File uncompressFile, File descPathFile, boolean override) { ZipFile zipFile = null;//from w ww. j a v a 2s. c o m try { zipFile = new ZipFile(uncompressFile, "GBK"); Enumeration<ZipArchiveEntry> entries = zipFile.getEntries(); while (entries.hasMoreElements()) { ZipArchiveEntry zipEntry = entries.nextElement(); String name = zipEntry.getName(); name = name.replace("\\", "/"); File currentFile = new File(descPathFile, name); //? if (currentFile.isFile() && currentFile.exists() && !override) { continue; } if (name.endsWith("/")) { currentFile.mkdirs(); continue; } else { currentFile.getParentFile().mkdirs(); } FileOutputStream fos = null; try { fos = new FileOutputStream(currentFile); InputStream is = zipFile.getInputStream(zipEntry); IOUtils.copy(is, fos); } finally { IOUtils.closeQuietly(fos); } } } catch (IOException e) { throw new RuntimeException("", e); } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException e) { } } } }
From source file:deodex.tools.ZipTools.java
/** * check if the given fileName matches a file in the given zipFile * without extraction ,file name can contain full paths in zip like * '/path/myFile.txt //w w w. j av a 2 s. c o m * @param fileName file name to search fot * @param zipFile the zip in which we will search for the file * @return isFileFound returns true is a file matches the given file */ public static boolean isFileinZipFailSafe(String fileName, java.util.zip.ZipFile zipFile) { try { Enumeration<? extends ZipEntry> zipEntries = zipFile.entries(); while (zipEntries.hasMoreElements()) { if (zipEntries.nextElement().getName().contains(fileName)) { return true; } } } catch (Exception e) { Logger.appendLog("[ZipTools][EX]" + e.getStackTrace()); return false; } return false; }
From source file:b2s.idea.mavenize.JarCombiner.java
private static void copyContentsOf(File input, ZipOutputStream output, JarContext context) throws IOException { ZipFile zip = null;//from www .j a va 2s . c o m try { zip = new ZipFile(input); Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (fileCanBeIgnored(entry, context)) { continue; } if (isServiceEntry(entry)) { context.addService(entry.getName(), contentsOf(entry, zip)); continue; } output.putNextEntry(new ZipEntry(entry.getName())); output.write(contentsOf(entry, zip)); output.flush(); output.closeEntry(); context.addVisitedEntry(entry); } } finally { close(zip); } }
From source file:Main.java
/** * Add all elements of an {@link Enumeration} to a {@link Collection}. * /* w w w. ja v a 2 s . c om*/ * @param collection * to add from enumeration. * @param enumeration * to add to collection. * @return true if collection is modified, otherwise false. * @since 8.1 * @see Collection#addAll(Collection) */ public static final <T> boolean addAll(final Collection<T> collection, final Enumeration<T> enumeration) { if (null == enumeration) { return false; } boolean modified = false; while (enumeration.hasMoreElements()) { modified |= collection.add(enumeration.nextElement()); } return modified; }
From source file:com.android.tradefed.util.ZipUtil2.java
/** * Utility method to extract entire contents of zip file into given directory * * @param zipFile the {@link ZipFile} to extract * @param destDir the local dir to extract file to * @throws IOException if failed to extract file *///www . ja v a 2 s . c om public static void extractZip(ZipFile zipFile, File destDir) throws IOException { Enumeration<? extends ZipArchiveEntry> entries = zipFile.getEntries(); while (entries.hasMoreElements()) { ZipArchiveEntry entry = entries.nextElement(); File childFile = new File(destDir, entry.getName()); childFile.getParentFile().mkdirs(); if (entry.isDirectory()) { childFile.mkdirs(); applyUnixModeIfNecessary(entry, childFile); continue; } else { FileUtil.writeToFile(zipFile.getInputStream(entry), childFile); applyUnixModeIfNecessary(entry, childFile); } } }
From source file:com.ms.commons.test.classloader.util.AntxconfigUtil.java
@SuppressWarnings("unchecked") private static void autoconf(File tmp, String autoconfigPath, String autoconfigFile, PrintStream out) throws Exception { Enumeration<URL> urls = AntxconfigUtil.class.getClassLoader().getResources(autoconfigFile); for (; urls.hasMoreElements();) { URL url = urls.nextElement(); // copy xml File autoconfFile = new File(tmp, autoconfigFile); writeUrlToFile(url, autoconfFile); // copy vm SAXBuilder b = new SAXBuilder(); Document document = b.build(autoconfFile); List<Element> elements = XPath.selectNodes(document, GEN_PATH); for (Element element : elements) { String path = url.getPath(); String vm = element.getAttributeValue("template"); String vmPath = StringUtils.substringBeforeLast(path, "/") + "/" + vm; URL vmUrl = new URL(url.getProtocol(), url.getHost(), vmPath); File vmFile = new File(tmp, autoconfigPath + "/" + vm); writeUrlToFile(vmUrl, vmFile); }//from www. jav a 2 s. com // call antxconfig String args = ""; if (new File(DEFAULT_ANTX_FILE).isFile()) { args = " -u " + DEFAULT_ANTX_FILE; } Process p = Runtime.getRuntime().exec(ANTXCONFIG_CMD + args, null, tmp); BufferedInputStream in = new BufferedInputStream(p.getInputStream()); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String s; while ((s = br.readLine()) != null) { out.println(new String(s.getBytes(), ENDODING)); } FileUtils.deleteDirectory(new File(tmp, autoconfigPath)); } }
From source file:ste.web.beanshell.jetty.BeanShellUtils.java
/** * Cleans up request variables so that they won't be set in next invocations * * @param interpreter the beanshell interpreter * @param request the request/* w w w . j av a2 s . c om*/ * */ public static void cleanup(final Interpreter interpreter, final HttpServletRequest request) throws EvalError { Enumeration<String> params = request.getParameterNames(); while (params.hasMoreElements()) { interpreter.unset(params.nextElement()); } }