Example usage for java.util Enumeration hasMoreElements

List of usage examples for java.util Enumeration hasMoreElements

Introduction

In this page you can find the example usage for java.util Enumeration hasMoreElements.

Prototype

boolean hasMoreElements();

Source Link

Document

Tests if this enumeration contains more elements.

Usage

From source file:it.geosolutions.sfs.web.Start.java

private static boolean keyStoreContainsCertificate(KeyStore ks, String hostname) throws Exception {
    //          SubjectDnX509PrincipalExtractor ex = new SubjectDnX509PrincipalExtractor();
    Enumeration<String> e = ks.aliases();
    while (e.hasMoreElements()) {
        String alias = e.nextElement();
        if (ks.isCertificateEntry(alias)) {
            Certificate c = ks.getCertificate(alias);
            if (c instanceof X509Certificate) {
                X500Principal p = (X500Principal) ((X509Certificate) c).getSubjectX500Principal();
                if (p.getName().contains(hostname))
                    return true;
            }//ww  w . j  a v a2 s  .c  om
        }
    }
    return false;
}

From source file:io.fabric8.maven.core.util.ClassUtil.java

private static Set<String> extractUrlAsStringsFromEnumeration(Enumeration<URL> urlEnum) {
    Set<String> ret = new HashSet<String>();
    while (urlEnum.hasMoreElements()) {
        ret.add(urlEnum.nextElement().toExternalForm());
    }// www.jav a  2  s. c  om
    return ret;
}

From source file:Main.java

/**
 * Given an Object, and a key (index), returns the value associated with
 * that key in the Object. The following checks are made:
 * <ul>//from   ww  w .  ja v a  2 s.  c  o  m
 * <li>If obj is a Map, use the index as a key to get a value. If no match continue.
 * <li>Check key is an Integer. If not, return the object passed in.
 * <li>If obj is a Map, get the nth value from the <b>keySet</b> iterator.
 *     If the Map has fewer than n entries, return an empty Iterator.
 * <li>If obj is a List or an array, get the nth value, throwing IndexOutOfBoundsException,
 *     ArrayIndexOutOfBoundsException, resp. if the nth value does not exist.
 * <li>If obj is an iterator, enumeration or Collection, get the nth value from the iterator,
 *     returning an empty Iterator (resp. Enumeration) if the nth value does not exist.
 * <li>Return the original obj.
 * </ul>
 *
 * @param obj  the object to get an index of
 * @param index  the index to get
 * @return the object at the specified index
 * @throws IndexOutOfBoundsException
 * @throws ArrayIndexOutOfBoundsException
 *
 * @deprecated use {@link #get(Object, int)} instead. Will be removed in v4.0
 */
public static Object index(Object obj, Object index) {
    if (obj instanceof Map) {
        Map map = (Map) obj;
        if (map.containsKey(index)) {
            return map.get(index);
        }
    }
    int idx = -1;
    if (index instanceof Integer) {
        idx = ((Integer) index).intValue();
    }
    if (idx < 0) {
        return obj;
    } else if (obj instanceof Map) {
        Map map = (Map) obj;
        Iterator iterator = map.keySet().iterator();
        return index(iterator, idx);
    } else if (obj instanceof List) {
        return ((List) obj).get(idx);
    } else if (obj instanceof Object[]) {
        return ((Object[]) obj)[idx];
    } else if (obj instanceof Enumeration) {
        Enumeration it = (Enumeration) obj;
        while (it.hasMoreElements()) {
            idx--;
            if (idx == -1) {
                return it.nextElement();
            } else {
                it.nextElement();
            }
        }
    } else if (obj instanceof Iterator) {
        return index((Iterator) obj, idx);
    } else if (obj instanceof Collection) {
        Iterator iterator = ((Collection) obj).iterator();
        return index(iterator, idx);
    }
    return obj;
}

From source file:org.apache.cxf.transport.jms.JMSOldConfigHolder.java

public static Properties getInitialContextEnv(AddressType addrType) {
    Properties env = new Properties();
    java.util.ListIterator listIter = addrType.getJMSNamingProperty().listIterator();
    while (listIter.hasNext()) {
        JMSNamingPropertyType propertyPair = (JMSNamingPropertyType) listIter.next();
        if (null != propertyPair.getValue()) {
            env.setProperty(propertyPair.getName(), propertyPair.getValue());
        }//w ww  . jav  a 2 s.  c o m
    }
    if (LOG.isLoggable(Level.FINE)) {
        Enumeration props = env.propertyNames();
        while (props.hasMoreElements()) {
            String name = (String) props.nextElement();
            String value = env.getProperty(name);
            LOG.log(Level.FINE, "Context property: " + name + " | " + value);
        }
    }
    return env;
}

From source file:com.glaf.core.config.CustomProperties.java

public static void reload() {
    if (!loading.get()) {
        InputStream inputStream = null;
        try {// w ww .  ja  v a2s. com
            loading.set(true);
            String config = SystemProperties.getConfigRootPath() + "/conf/props";
            logger.debug(config);
            File directory = new File(config);
            if (directory.exists()) {
                String[] filelist = directory.list();
                if (filelist != null) {
                    for (int i = 0, len = filelist.length; i < len; i++) {
                        String filename = config + "/" + filelist[i];
                        logger.debug(filename);
                        File file = new File(filename);
                        if (file.isFile() && file.getName().endsWith(".properties")) {
                            logger.info("load properties:" + file.getAbsolutePath());
                            inputStream = new FileInputStream(file);
                            Properties p = PropertiesUtils.loadProperties(inputStream);
                            if (p != null) {
                                Enumeration<?> e = p.keys();
                                while (e.hasMoreElements()) {
                                    String key = (String) e.nextElement();
                                    String value = p.getProperty(key);
                                    properties.setProperty(key, value);
                                    properties.setProperty(key.toLowerCase(), value);
                                    properties.setProperty(key.toUpperCase(), value);
                                }
                            }
                            IOUtils.closeStream(inputStream);
                        }
                    }
                }
            }
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        } finally {
            loading.set(false);
            IOUtils.closeStream(inputStream);
        }
    }
}

From source file:android.databinding.tool.util.GenerationalClassUtil.java

private static void loadFomZipFile(File file) throws IOException {
    ZipFile zipFile = new ZipFile(file);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        for (ExtensionFilter filter : ExtensionFilter.values()) {
            if (!filter.accept(entry.getName())) {
                continue;
            }/*from  www  . j a  va2  s.c om*/
            InputStream inputStream = null;
            try {
                inputStream = zipFile.getInputStream(entry);
                Serializable item = fromInputStream(inputStream);
                L.d("loaded item %s from zip file", item);
                if (item != null) {
                    //noinspection unchecked
                    sCache[filter.ordinal()].add(item);
                }
            } catch (IOException e) {
                L.e(e, "Could not merge in Bindables from %s", file.getAbsolutePath());
            } catch (ClassNotFoundException e) {
                L.e(e, "Could not read Binding properties intermediate file. %s", file.getAbsolutePath());
            } finally {
                IOUtils.closeQuietly(inputStream);
            }
        }
    }
}

From source file:Main.java

public static NetworkInterface getActiveNetworkInterface() {

    Enumeration<NetworkInterface> interfaces = null;
    try {/*  www .  j a v  a  2 s  .c  o m*/
        interfaces = NetworkInterface.getNetworkInterfaces();
    } catch (SocketException e) {
        return null;
    }

    while (interfaces.hasMoreElements()) {
        NetworkInterface iface = interfaces.nextElement();
        Enumeration<InetAddress> inetAddresses = iface.getInetAddresses();

        /* Check if we have a non-local address. If so, this is the active
         * interface.
         *
         * This isn't a perfect heuristic: I have devices which this will
         * still detect the wrong interface on, but it will handle the
         * common cases of wifi-only and Ethernet-only.
         */
        while (inetAddresses.hasMoreElements()) {
            InetAddress addr = inetAddresses.nextElement();

            if (!(addr.isLoopbackAddress() || addr.isLinkLocalAddress())) {
                return iface;
            }
        }
    }

    return null;
}

From source file:org.carewebframework.ui.util.RequestUtil.java

/**
 * Logs at trace level the request headers
 * /*from   w  w w  . j  ava 2 s .  c  om*/
 * @throws IllegalStateException if called outside scope of an HttpServletRequest
 */
public static void logHeaderNames() throws IllegalStateException {
    final HttpServletRequest request = assertRequest();
    final Enumeration<?> enumeration = request.getHeaderNames();
    while (enumeration.hasMoreElements()) {
        final String headerName = (String) enumeration.nextElement();
        log.trace(String.format("HeaderName: %s", headerName));
    }
}

From source file:nl.verheulconsultants.monitorisp.service.Utilities.java

/**
 * This utility is not yet used.//from w w w  . j ava  2s  . c  o  m
 *
 * @return the location of the log files
 */
public static String getLogFileName() {
    FileAppender fileAppender = null;

    Enumeration appenders = LogManager.getRootLogger().getAllAppenders();

    while (appenders.hasMoreElements()) {
        Appender currAppender = (Appender) appenders.nextElement();
        if (currAppender instanceof FileAppender) {
            fileAppender = (FileAppender) currAppender;
        }
    }

    if (fileAppender != null) {
        return fileAppender.getFile();
    } else {
        return "Log file location not found.";
    }
}

From source file:com.glaf.core.xml.XmlProperties.java

public static void reload() {
    if (!loading.get()) {
        InputStream inputStream = null;
        try {/*from  w w w  .j a  va  2s  .co  m*/
            loading.set(true);
            String config = SystemProperties.getConfigRootPath() + "/conf/templates/xml";
            File directory = new File(config);
            if (directory.exists() && directory.isDirectory()) {
                String[] filelist = directory.list();
                if (filelist != null) {
                    for (int i = 0, len = filelist.length; i < len; i++) {
                        String filename = config + "/" + filelist[i];
                        File file = new File(filename);
                        if (file.isFile() && file.getName().endsWith(".properties")) {
                            inputStream = new FileInputStream(file);
                            Properties p = PropertiesUtils.loadProperties(inputStream);
                            if (p != null) {
                                Enumeration<?> e = p.keys();
                                while (e.hasMoreElements()) {
                                    String key = (String) e.nextElement();
                                    String value = p.getProperty(key);
                                    properties.setProperty(key, value);
                                    properties.setProperty(key.toLowerCase(), value);
                                    properties.setProperty(key.toUpperCase(), value);
                                }
                            }
                            IOUtils.closeStream(inputStream);
                        }
                    }
                }
            }
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        } finally {
            loading.set(false);
            IOUtils.closeStream(inputStream);
        }
    }
}