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:com.salas.bb.utils.xml.XmlReaderFactory.java

/**
 * Reads properties from the resource into the map. Each key in properties resource
 * is a value for comma-delimetered list of keys.
 *
 * @param propertiesName    name of properties resource.
 *
 * @return map.//from w  ww.ja v  a  2s.c o m
 *
 * @throws IOException in case of I/O error.
 */
static Map readPropsToMap(String propertiesName) throws IOException {
    Properties props = new Properties();
    props.load(XmlReaderFactory.class.getClassLoader().getResourceAsStream(propertiesName));

    Map map = new HashMap();

    Enumeration propEnumeration = props.propertyNames();
    while (propEnumeration.hasMoreElements()) {
        String readerClassName = ((String) propEnumeration.nextElement()).trim();
        String[] encodings = StringUtils.split(props.getProperty(readerClassName), ",");

        putKeysInMap(map, encodings, readerClassName);
    }

    return map;
}

From source file:massbank.svn.SVNUtils.java

/**
 * //from ww  w  .j a va  2  s  . c om
 */
public static String getLocalIPAddress() {
    String address = "";
    try {
        Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
        while (interfaces.hasMoreElements()) {
            NetworkInterface network = interfaces.nextElement();
            Enumeration<InetAddress> addresses = network.getInetAddresses();
            while (addresses.hasMoreElements()) {
                InetAddress inet = addresses.nextElement();
                if (!inet.isLoopbackAddress() && inet instanceof Inet4Address) {
                    return inet.getHostAddress();
                }
            }
        }
        address = InetAddress.getLocalHost().getHostAddress();
    } catch (Exception e) {
    }
    return address;
}

From source file:net.big_oh.common.web.WebUtil.java

/**
 * A convenience method that counts number of attributes stored in a user's
 * {@link HttpSession}.//from  www .j  a  v  a2s.  c om
 * 
 * @param session
 *            An HttpSession object from any web application.
 * @return A count of the number of attributes stored in an HttpSession.
 */
public static int countAttributesInSession(HttpSession session) {

    int count = 0;

    Enumeration<?> attributeEnum = session.getAttributeNames();
    while (attributeEnum.hasMoreElements()) {
        attributeEnum.nextElement();
        count++;
    }

    return count;

}

From source file:gov.nih.nci.cabig.ctms.web.WebTools.java

private static <T> SortedMap<String, T> namedAttributesToMap(Enumeration<String> names,
        AttributeAccessor<T> accessor) {
    SortedMap<String, T> map = new TreeMap<String, T>();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        map.put(name, accessor.getAttribute(name));
    }//  w  ww .  java2 s  .co  m
    return Collections.unmodifiableSortedMap(map);
}

From source file:org.jboss.spring.vfs.VFSResourcePatternResolvingHelper.java

public static Resource[] locateResources(String locationPattern, String rootDirPath, ClassLoader classLoader,
        PathMatcher pathMatcher, boolean oneMatchingRootOnly) throws IOException {
    String subPattern = locationPattern.substring(rootDirPath.length());
    if (rootDirPath.startsWith("/")) {
        rootDirPath = rootDirPath.substring(1);
    }/*from   w  ww . ja  v a2 s .co  m*/

    List<Resource> resources = new ArrayList<Resource>();
    Enumeration<URL> urls = classLoader.getResources(rootDirPath);
    if (!oneMatchingRootOnly) {
        while (urls.hasMoreElements()) {
            resources.addAll(getVFSResources(urls.nextElement(), subPattern, pathMatcher));
        }
    } else {
        resources.addAll(getVFSResources(classLoader.getResource(rootDirPath), subPattern, pathMatcher));
    }
    return resources.toArray(new Resource[resources.size()]);
}

From source file:com.amazonaws.codepipeline.jenkinsplugin.ExtractionTools.java

private static void extractZipFile(final File destination, final ZipFile zipFile) throws IOException {
    final Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();

    while (entries.hasMoreElements()) {
        final ZipArchiveEntry entry = entries.nextElement();
        final File entryDestination = getDestinationFile(destination, entry.getName());

        if (entry.isDirectory()) {
            entryDestination.mkdirs();//from   ww  w .  j a  v a2 s . c om
        } else {
            entryDestination.getParentFile().mkdirs();
            final InputStream in = zipFile.getInputStream(entry);
            try (final OutputStream out = new FileOutputStream(entryDestination)) {
                IOUtils.copy(in, out);
                IOUtils.closeQuietly(in);
            }
        }
    }
}

From source file:com.hhi.bigdata.platform.push.client.RegisterUtil.java

/**
 * <pre>//  w w w.j a  v  a2 s .  co m
 * create a SSLSocketFactory instance with given parameters
 * </pre>
 * @param keystore
 * @param password
 * @return
 * @throws IOException
 */
private static PrivateKey getPrivateKey(KeyStore keystore, String password) throws Exception {
    Key key = null;

    // List the aliases
    Enumeration<String> aliases = keystore.aliases();
    while (aliases.hasMoreElements()) {
        String alias = (String) aliases.nextElement();

        if (keystore.isKeyEntry(alias)) {
            key = keystore.getKey(alias, password.toCharArray());
        }
    }

    return (PrivateKey) key;
}

From source file:com.lily.dap.web.util.WebUtils.java

/**
 * Request Parameters./* w w  w.  ja v a  2 s .  c om*/
 * 
 * Parameter.
 */
@SuppressWarnings("unchecked")
public static Map<String, String> getParametersStartingWith(HttpServletRequest request, String prefix) {
    if (prefix == null)
        prefix = "";

    Map params = new TreeMap();
    Enumeration paramNames = request.getParameterNames();

    while (paramNames != null && paramNames.hasMoreElements()) {
        String paramName = (String) paramNames.nextElement();
        if ("".equals(prefix) || paramName.startsWith(prefix)) {
            String unprefixed = paramName.substring(prefix.length());
            String[] values = request.getParameterValues(paramName);
            if (values == null || values.length == 0)
                ;// Do nothing, no values found at all.
            else if (values.length > 1)
                params.put(unprefixed, StringUtils.join(values));
            else
                params.put(unprefixed, values[0]);

        }
    }

    return params;
}

From source file:net.big_oh.common.web.WebUtil.java

/**
 * A convenience method that performs a reverse lookup to find all names
 * under which an attribute is stored in a user's {@link HttpSession}.
 * //from  ww  w .j a  v  a  2 s. co  m
 * @param session
 *            An HttpSession object from any web application.
 * @param sessionAttribute
 *            Attribute name of interest.
 * @return A seet of all attribute names under which the sessionAttribute
 *         parameter is stored in the session.
 */
public static Set<String> getNamesForSessionAttribute(HttpSession session, Object sessionAttribute) {

    Set<String> attributeNames = new HashSet<String>();

    Enumeration<?> attributeEnum = session.getAttributeNames();
    while (attributeEnum.hasMoreElements()) {
        String attributeName = (String) attributeEnum.nextElement();
        if (sessionAttribute == session.getAttribute(attributeName)) {
            attributeNames.add(attributeName);
        }

    }

    return attributeNames;

}

From source file:com.bluexml.xforms.messages.MsgPool.java

/**
 * Tests whether a key exists in the properties file.
 * /*from w w  w .  ja  v a2s. co  m*/
 * @param theKey
 *            the reference key text being tested
 * @return
 */
private static boolean hasProperty(String theKey) {
    getInstance();
    Enumeration<?> properties = MsgPool.getPool().propertyNames();
    while (properties.hasMoreElements()) {
        String aKey = (String) properties.nextElement();
        if (StringUtils.equals(theKey, aKey)) {
            return true;
        }
    }
    return false;
}