Example usage for java.util Enumeration nextElement

List of usage examples for java.util Enumeration nextElement

Introduction

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

Prototype

E nextElement();

Source Link

Document

Returns the next element of this enumeration if this enumeration object has at least one more element to provide.

Usage

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 w  w  w  . ja  va 2s.  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.lily.dap.web.util.WebUtils.java

/**
 * Request Parameters.//from   w  w w .j  a  va 2s.co m
 * 
 * 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:massbank.svn.SVNUtils.java

/**
 * /*from  w  w  w .j  av  a  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:com.limegroup.gnutella.gui.LanguageUtils.java

/**
 * Returns the languages as found from the classpath in messages.jar
 *//*from ww w  .  j  av a 2s  .co  m*/
static void addLocalesFromJar(List<Locale> locales, File jar) {
    ZipFile zip = null;
    try {
        zip = new ZipFile(jar);
        Enumeration<? extends ZipEntry> entries = zip.entries();
        while (entries.hasMoreElements()) {
            String name = entries.nextElement().getName();
            if (!name.startsWith(BUNDLE_PREFIX) || !name.endsWith(BUNDLE_POSTFIX) || name.indexOf("$") != -1) {
                continue;
            }

            String iso = name.substring(BUNDLE_PREFIX.length(), name.length() - BUNDLE_POSTFIX.length());
            List<String> tokens = new ArrayList<String>(Arrays.asList(iso.split("_", 3)));
            if (tokens.size() < 1) {
                continue;
            }
            while (tokens.size() < 3) {
                tokens.add("");
            }

            Locale locale = new Locale(tokens.get(0), tokens.get(1), tokens.get(2));
            locales.add(locale);
        }
    } catch (IOException e) {
        LOG.warn("Could not determine locales", e);
    } finally {
        if (zip != null) {
            try {
                zip.close();
            } catch (IOException ioe) {
            }
        }
    }
}

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  www.  ja  v  a  2 s  . c  o 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:nl.verheulconsultants.monitorisp.service.Utilities.java

/**
 * This utility is not yet used.//from w w w  . j  a  v a 2  s.  co 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.google.code.pentahoflashcharts.charts.PentahoOFC4JChartHelper.java

@SuppressWarnings("unchecked")
private static Map createChartFactoryMap() {
    Properties chartFactories = new Properties();
    // First, get known chart factories...
    try {//from ww  w .  j ava  2 s  . c  o m
        ResourceBundle pluginBundle = ResourceBundle.getBundle(PLUGIN_BUNDLE_NAME);
        if (pluginBundle != null) { // Copy the bundle here...
            Enumeration keyEnum = pluginBundle.getKeys();
            String bundleKey = null;
            while (keyEnum.hasMoreElements()) {
                bundleKey = (String) keyEnum.nextElement();
                chartFactories.put(bundleKey, pluginBundle.getString(bundleKey));
            }
        }
    } catch (Exception ex) {
        logger.warn(Messages.getString("PentahoOFC4JChartHelper.WARN_NO_CHART_FACTORY_PROPERTIES_BUNDLE")); //$NON-NLS-1$
    }
    // Get overrides...
    //
    // Note - If the override wants to remove an existing "known" plugin, 
    // simply adding an empty value will cause the "known" plugin to be removed.
    //
    if (PentahoSystem.getObjectFactory() == null
            || !PentahoSystem.getObjectFactory().objectDefined(ISolutionRepository.class.getSimpleName())) {
        // this is ok
        return chartFactories;
    }
    ISolutionRepository solutionRepository = PentahoSystem.get(ISolutionRepository.class,
            new StandaloneSession("system")); //$NON-NLS-1$
    try {
        if (solutionRepository.resourceExists(SOLUTION_PROPS)) {
            InputStream is = solutionRepository.getResourceInputStream(SOLUTION_PROPS, false);
            Properties overrideChartFactories = new Properties();
            overrideChartFactories.load(is);
            chartFactories.putAll(overrideChartFactories); // load over the top of the known properties
        }
    } catch (FileNotFoundException ignored) {
        logger.warn(Messages.getString("PentahoOFC4JChartHelper.WARN_NO_CHART_FACTORY_PROPERTIES")); //$NON-NLS-1$
    } catch (IOException ignored) {
        logger.warn(Messages.getString("PentahoOFC4JChartHelper.WARN_BAD_CHART_FACTORY_PROPERTIES"), ignored); //$NON-NLS-1$
    }

    return chartFactories;
}

From source file:com.netflix.config.ClasspathPropertiesConfiguration.java

private static void loadResources(ClassLoader loader, String resourceName) throws Exception {
    Enumeration<URL> resources = loader.getResources(resourceName);
    boolean loadedResources = false;
    while (resources.hasMoreElements()) {
        URL from = resources.nextElement();
        /* Properties props = loadProperties(from);
        String configName = getConfigName(props, from);
        containerConfiguration.addConfiguration(
              new PropertiesConfiguration(from), configName); */
        ConfigurationManager.loadPropertiesFromResources(from.getPath());
        log.debug("Added properties from:" + from + from.getPath());
        loadedResources = true;// w  w  w . java 2 s  .co m
    }
    if (!loadedResources) {
        log.debug("Did not find any properties resource in the classpath with name:"
                + propertiesResourceRelativePath);
    }
}

From source file:edu.utah.further.i2b2.hook.further.web.ServletUtil.java

/**
 * @param request/*from  ww w.  ja v  a  2 s  . c  o  m*/
 */
public static void printRequestHeaders(final HttpServletRequest request) {
    log.debug("Request headers:");
    final Enumeration<?> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        final String name = (String) headerNames.nextElement();
        log.debug(name + " = " + request.getHeader(name));
    }
}

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

/**
 * Logs at trace level the request headers
 * /*w w w .  j  a v  a  2  s . c o  m*/
 * @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));
    }
}