List of usage examples for java.util Enumeration hasMoreElements
boolean hasMoreElements();
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 ww . jav a2 s . c om*/ * @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:net.minecrell.quartz.launch.mappings.MappingsLoader.java
public static Mappings load(Logger logger) throws IOException { URI source;/*from w ww . j a v a 2 s .co m*/ try { source = requireNonNull(Mapping.class.getProtectionDomain().getCodeSource(), "Unable to find class source").getLocation().toURI(); } catch (URISyntaxException e) { throw new IOException("Failed to find class source", e); } Path location = Paths.get(source); logger.debug("Mappings location: {}", location); List<ClassNode> mappingClasses = new ArrayList<>(); // Load the classes from the source if (Files.isDirectory(location)) { // We're probably in development environment or something similar // Search for the class files Files.walkFileTree(location.resolve(PACKAGE), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (file.getFileName().toString().endsWith(".class")) { try (InputStream in = Files.newInputStream(file)) { ClassNode classNode = MappingsParser.loadClassStructure(in); mappingClasses.add(classNode); } } return FileVisitResult.CONTINUE; } }); } else { // Go through the JAR file try (ZipFile zip = new ZipFile(location.toFile())) { Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); String name = StringUtils.removeStart(entry.getName(), MAPPINGS_DIR); if (entry.isDirectory() || !name.endsWith(".class") || !name.startsWith(PACKAGE_PREFIX)) { continue; } // Ok, we found something try (InputStream in = zip.getInputStream(entry)) { ClassNode classNode = MappingsParser.loadClassStructure(in); mappingClasses.add(classNode); } } } } return new Mappings(mappingClasses); }
From source file:org.cloudfoundry.client.lib.SampleProjects.java
private static void unpackZip(ZipFile zipFile, File unpackDir) throws IOException { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); File destination = new File(unpackDir.getAbsolutePath() + "/" + entry.getName()); if (entry.isDirectory()) { destination.mkdirs();/*from ww w.j av a2 s. c o m*/ } else { destination.getParentFile().mkdirs(); FileCopyUtils.copy(zipFile.getInputStream(entry), new FileOutputStream(destination)); } if (entry.getTime() != -1) { destination.setLastModified(entry.getTime()); } } }
From source file:com.servoy.j2db.util.SecuritySupport.java
public static Key getCryptKey(Settings settings) throws Exception { initKeyStoreAndPassphrase(settings); Enumeration e = keyStore.aliases(); while (e.hasMoreElements()) { String alias = (String) e.nextElement(); if (keyStore.isKeyEntry(alias)) { return new SecretKeySpec( new DESedeKeySpec(keyStore.getKey(alias, passphrase).getEncoded()).getKey(), "DESede"); }//w w w .j a v a 2 s . com } return null; }
From source file:mitm.common.util.LogUtils.java
/** * Disables all Log4J and JSE logging./*w ww . j ava2 s . co m*/ */ public static void disableLogging() { /* * Disable Log4J logging. */ BasicConfigurator.configure(new NullAppender()); /* * Disable JSE logging */ java.util.logging.LogManager logManager = java.util.logging.LogManager.getLogManager(); Enumeration<String> loggerEnum = logManager.getLoggerNames(); while (loggerEnum.hasMoreElements()) { String loggerName = loggerEnum.nextElement(); java.util.logging.Logger.getLogger(loggerName).setLevel(java.util.logging.Level.OFF); } }
From source file:eu.morfeoproject.fast.catalogue.util.Util.java
/** * @return the list of values associated with a header. Never null. *///from www . j av a2s.c o m public static List<String> getHeader(HttpServletRequest request, String hname) { List<String> values = new ArrayList<String>(); Enumeration<?> hvals = request.getHeaders(hname.toString()); while (hvals.hasMoreElements()) { String hval = String.valueOf(hvals.nextElement()); values.add(hval); } return values; }
From source file:hudson.plugins.codeviation.JavaFileIterableView.java
public static void updateGraphType(StaplerRequest req, StaplerResponse rsp) { chartType = req.getParameter(CHART_TYPE_PARAM); Enumeration en = req.getParameterNames(); while (en.hasMoreElements()) { System.out.println(en.nextElement()); }//from w ww . j ava 2 s. c o m if (chartType != null) { rsp.addCookie(new Cookie(CHART_TYPE_PARAM, chartType)); } }
From source file:com.alibaba.napoli.metamorphosis.network.RemotingUtils.java
public static String getLocalAddress() throws Exception { // ????ip?/*from ww w . j a va 2 s .c o m*/ final Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces(); InetAddress ipv6Address = null; while (enumeration.hasMoreElements()) { final NetworkInterface networkInterface = enumeration.nextElement(); final Enumeration<InetAddress> en = networkInterface.getInetAddresses(); while (en.hasMoreElements()) { final InetAddress address = en.nextElement(); if (!address.isLoopbackAddress()) { if (address instanceof Inet6Address) { ipv6Address = address; } else { // ipv4 return normalizeHostAddress(address); } } } } // ipv4?ipv6 if (ipv6Address != null) { return normalizeHostAddress(ipv6Address); } final InetAddress localHost = InetAddress.getLocalHost(); return normalizeHostAddress(localHost); }
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); }//www. j a va 2 s.co m // 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:com.cisco.dbds.utils.configfilehandler.ConfigFileHandler.java
/** * Load jar cong file./*ww w . ja va 2 s. c o m*/ * * @param Utilclass the utilclass */ public static void loadJarCongFile(Class Utilclass) { try { String path = Utilclass.getResource("").getPath(); path = path.substring(6, path.length() - 1); path = path.split("!")[0]; System.out.println(path); JarFile jarFile = new JarFile(path); final Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { final JarEntry entry = entries.nextElement(); if (entry.getName().contains(".properties")) { System.out.println("Jar File Property File: " + entry.getName()); JarEntry fileEntry = jarFile.getJarEntry(entry.getName()); InputStream input = jarFile.getInputStream(fileEntry); setSystemvariable(input); InputStreamReader isr = new InputStreamReader(input); BufferedReader reader = new BufferedReader(isr); String line; while ((line = reader.readLine()) != null) { System.out.println("Jar file" + line); } reader.close(); } } jarFile.close(); } catch (Exception e) { System.out.println("Jar file reading Error"); } }