List of usage examples for java.util Enumeration hasMoreElements
boolean hasMoreElements();
From source file:Main.java
private static List<InputStream> loadResources(String name, ClassLoader classLoader) throws IOException { final List<InputStream> list = new ArrayList<InputStream>(); final Enumeration<URL> systemResources = (classLoader == null ? ClassLoader.getSystemClassLoader() : classLoader).getResources(name); while (systemResources.hasMoreElements()) { list.add(systemResources.nextElement().openStream()); }/*from w w w.ja v a2s .com*/ return list; }
From source file:com.netsteadfast.greenstep.util.HostUtils.java
public static String getHostAddress() { String hostAddress = ""; try {/* ww w . j ava 2s.c om*/ Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces(); for (; nics.hasMoreElements() && "".equals(hostAddress);) { NetworkInterface interfece = nics.nextElement(); if (interfece.getName().toLowerCase().startsWith("lo")) { continue; } Enumeration<InetAddress> addrs = interfece.getInetAddresses(); for (; addrs.hasMoreElements() && "".equals(hostAddress);) { InetAddress addr = addrs.nextElement(); if (addr.getHostAddress().indexOf(":") > -1) { continue; } hostAddress = addr.getHostAddress(); } } } catch (SocketException e) { e.printStackTrace(); } if (StringUtils.isBlank(hostAddress)) { hostAddress = "127.0.0.1"; } return hostAddress; }
From source file:dk.dtu.imm.esculapauml.core.tests.uml.LoggingTest.java
/** * Returns true if it appears that log4j have been previously configured. * This code checks to see if there are any appenders defined for log4j * which is the definitive way to tell if log4j is already initialized * /* ww w . j a v a 2 s. c o m*/ * @return */ private static boolean isConfigured() { @SuppressWarnings("rawtypes") Enumeration appenders = Logger.getLogger("dk.dtu.imm.esculapauml").getAllAppenders(); return appenders.hasMoreElements(); }
From source file:py.una.pol.karaku.test.test.ValidationMessagesTest.java
@BeforeClass public static void before() { Locale locale = new Locale("es", "PY"); ResourceBundle toAdd = ResourceBundle.getBundle("language.validation.karaku", locale); Enumeration<String> en = toAdd.getKeys(); keys = new HashSet<String>(); while (en.hasMoreElements()) { keys.add("{" + en.nextElement() + "}"); }/*from w w w . ja va 2s .c om*/ }
From source file:Main.java
public static JComponent makeUI() { JTree tree = new JTree(); TreeModel model = tree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); Enumeration e = root.breadthFirstEnumeration(); while (e.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement(); Object o = node.getUserObject(); if (o instanceof String) { node.setUserObject(new CheckBoxNode((String) o, false)); }/*from w w w . ja v a 2 s.c om*/ } tree.setEditable(true); tree.setCellRenderer(new CheckBoxNodeRenderer()); tree.setCellEditor(new CheckBoxNodeEditor()); tree.expandRow(0); return new JScrollPane(tree); }
From source file:com.asakusafw.cleaner.log.LogMessageLoader.java
/** * ??//ww w. j av a 2s . c o m * ???????? * <p> * ????.properties????? * ??????????? * </p> * @param manager ? * @throws IOException ????? */ static void loadFile(LogMessageManager manager) throws IOException { // ? InputStream in = null; Properties props = new Properties(); try { in = LogMessageLoader.class.getClassLoader().getResourceAsStream(Constants.LOG_MESSAGE_FILE); props.load(in); Enumeration<?> keys = props.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); if (key.endsWith(LEVEL_KEY_END)) { String messageId = LogMessageLoader.getMessageId(key, LEVEL_KEY_END); manager.putLevel(messageId, props.getProperty(key)); } else if (key.endsWith(TEMPLATE_KEY_END)) { String messageId = LogMessageLoader.getMessageId(key, TEMPLATE_KEY_END); manager.putTemplate(messageId, props.getProperty(key)); } else if (key.endsWith(SIZE_KEY_END)) { String messageId = LogMessageLoader.getMessageId(key, SIZE_KEY_END); String sizeStr = props.getProperty(key); if (NumberUtils.isNumber(sizeStr)) { manager.putSize(messageId, Integer.valueOf(sizeStr)); } } } } catch (IOException ex) { throw new IOException( "??????????" + Constants.LOG_MESSAGE_FILE, ex); } finally { IOUtils.closeQuietly(in); } }
From source file:com.splout.db.common.GetIPAddresses.java
/** * Returns all available IP addresses./*w ww . j a v a 2 s .co m*/ * <p/> * In error case or if no network connection is established, we return an empty list here. * <p/> * Loopback addresses are excluded - so 127.0.0.1 will not be never returned. * <p/> * The "primary" IP might not be the first one in the returned list. * * @return Returns all IP addresses (can be an empty list in error case or if network connection is missing). * @throws SocketException * @since 0.1.0 */ public static Collection<InetAddress> getAllLocalIPs() throws SocketException { LinkedList<InetAddress> listAdr = new LinkedList<InetAddress>(); Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces(); if (nifs == null) return listAdr; while (nifs.hasMoreElements()) { NetworkInterface nif = nifs.nextElement(); // We ignore subinterfaces - as not yet needed. Enumeration<InetAddress> adrs = nif.getInetAddresses(); while (adrs.hasMoreElements()) { InetAddress adr = adrs.nextElement(); if (adr != null && !adr.isLoopbackAddress() && (nif.isPointToPoint() || !adr.isLinkLocalAddress())) { log.info("Available site local address: " + adr); listAdr.add(adr); } } } return listAdr; }
From source file:com.opengamma.util.ZipUtils.java
/** * Unzips a ZIP archive.//w w w .j a va 2s . co m * * @param zipFile the archive file, not null * @param outputDir the output directory, not null */ public static void unzipArchive(final ZipFile zipFile, final File outputDir) { ArgumentChecker.notNull(zipFile, "zipFile"); ArgumentChecker.notNull(outputDir, "outputDir"); try { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.isDirectory()) { FileUtils.forceMkdir(new File(outputDir, entry.getName())); continue; } File entryDestination = new File(outputDir, entry.getName()); entryDestination.getParentFile().mkdirs(); InputStream in = zipFile.getInputStream(entry); OutputStream out = new FileOutputStream(entryDestination); IOUtils.copy(in, out); IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } zipFile.close(); } catch (IOException ex) { throw new OpenGammaRuntimeException( "Error while extracting file: " + zipFile.getName() + " to: " + outputDir, ex); } }
From source file:com.dustindoloff.s3websitedeploy.Main.java
private static boolean upload(final AmazonS3 s3Client, final String bucket, final ZipFile zipFile) { boolean failed = false; final ObjectMetadata data = new ObjectMetadata(); final Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { final ZipEntry entry = entries.nextElement(); data.setContentLength(entry.getSize()); try {/*from w w w.ja v a 2s . c o m*/ s3Client.putObject(bucket, entry.getName(), zipFile.getInputStream(entry), data); } catch (final AmazonClientException | IOException e) { failed = true; } } return !failed; }
From source file:com.juhuasuan.osprey.LoggerInit.java
@SuppressWarnings("unchecked") static FileAppender searchFileAP(Enumeration<Appender> ppp) { FileAppender fp = null;//from w w w. ja v a 2 s . c om while (null == fp && ppp.hasMoreElements()) { Appender ap = ppp.nextElement(); if (ap instanceof FileAppender) { fp = (FileAppender) ap; } else if (ap instanceof AsyncAppender) { ppp = ((AsyncAppender) ap).getAllAppenders(); fp = searchFileAP(ppp); } } return fp; }