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.itude.mobile.mobbl.server.util.HeaderUtil.java

public static void printRequestHeaders(Logger logger, HttpServletRequest request) {
    if (request == null)
        throw new IllegalArgumentException("Request can't be null");
    if (logger == null)
        throw new IllegalArgumentException("Logger can't be null");

    logger.debug("List of request parameters:");

    @SuppressWarnings("unchecked")
    Enumeration<String> requestHeaders = request.getHeaderNames();
    if (requestHeaders != null) {
        while (requestHeaders.hasMoreElements()) {
            String header = requestHeaders.nextElement();

            @SuppressWarnings("unchecked")
            Enumeration<String> headers = request.getHeaders(header);
            if (headers != null) {
                while (headers.hasMoreElements())
                    logger.debug(header + ":" + headers.nextElement());
            }/*from  w ww  .  j  a  v  a2 s . c  om*/
        }
    }
}

From source file:Main.java

/**
 * Create a Hashtable by pairing the given keys with the given values.
 * Equivalent to python code <code>dict(zip(keys, values))</code>
 *///from w ww .  j a  va  2s.c  o  m
public static Hashtable createHashtable(Vector keys, Vector values) {
    Enumeration keyEnum = keys.elements();
    Enumeration valEnum = values.elements();

    Hashtable result = new Hashtable();
    while (keyEnum.hasMoreElements() && valEnum.hasMoreElements())
        result.put(keyEnum.nextElement(), valEnum.nextElement());

    return result;
}

From source file:com.enonic.esl.io.FileUtil.java

/**
 * Inflates a zip into a directory. Creates the directory and/or its parents if they don't exists.
 *
 * @param zipFile ZipFile zip file to inflate
 * @param dir     File destination directory
 *///www .j  a va2s  .c o m
public static void inflateZipFile(ZipFile zipFile, File dir) throws IOException {
    Enumeration entries = zipFile.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = (ZipEntry) entries.nextElement();
        inflateFile(dir, zipFile, entry);
    }
}

From source file:com.pureinfo.srm.RequestUtils.java

public static PureProperties parse(HttpServletRequest _request) throws PureException {
    logger.debug("enti");
    PureProperties props = new PureProperties();

    Enumeration names = _request.getParameterNames();
    logger.debug("enti11111111111#" + names.hasMoreElements());
    while (names.hasMoreElements()) {
        String sName = (String) names.nextElement();
        String[] values = _request.getParameterValues(sName);
        if (values.length == 1) {
            props.setProperty(sName, values[0]);
        } else {//from w  w w.  j a  va2  s . c om
            props.setProperty(sName, values);
        }

    }

    String sContentType = _request.getContentType();
    if (sContentType != null && sContentType.startsWith("multipart/form-data")) {
        logger.debug("enti111");
        DiskFileUpload upload = new DiskFileUpload();
        List items;
        try {
            items = upload.parseRequest(_request);
        } catch (FileUploadException ex) {
            throw new PureException(PureException.UNKNOWN, "upload error", ex);
        }
        logger.debug("enti111111111111" + items.size());
        for (Iterator iter = items.iterator(); iter.hasNext();) {
            FileItem item = (FileItem) iter.next();
            if (item.getName() == null) {
                props.setProperty(item.getFieldName(), item.getString());
            } else {
                props.setProperty(item.getFieldName(), item);
            }
            logger.debug("name:" + item.getFieldName() + "-value:" + props.getProperty(item.getFieldName()));
        }
    }

    return props;
}

From source file:mitm.common.util.LogUtils.java

/**
 * Disables all Log4J and JSE logging.//from   w  w  w  . ja va2  s. c  o 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:net.minecrell.quartz.launch.mappings.MappingsLoader.java

public static Mappings load(Logger logger) throws IOException {
    URI source;/*  w  w  w .  ja  v a 2  s.com*/
    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:Main.java

public static List<String> getDexEntries() {
    try {//from  www.jav  a  2s . c  o m
        Object app = Class.forName("android.app.ActivityThread").getMethod("currentApplication").invoke(null);
        Object codePath = Class.forName("android.app.Application").getMethod("getPackageCodePath").invoke(app);
        Class<?> dexFileClass = Class.forName("dalvik.system.DexFile");
        Object dexFile = dexFileClass.getConstructor(String.class).newInstance(codePath);
        Enumeration<String> entries = (Enumeration<String>) dexFileClass.getMethod("entries").invoke(dexFile);
        List<String> dexEntries = new LinkedList<String>();
        while (entries.hasMoreElements()) {
            String entry = entries.nextElement();
            entry = entry.replace('.', '/') + ".class";
            dexEntries.add(entry);
        }
        dexFileClass.getMethod("close").invoke(dexFile);
        return dexEntries;
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (SecurityException e) {
        throw new RuntimeException(e);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    } catch (InstantiationException e) {
        throw new RuntimeException(e);
    }
}

From source file:io.fabric8.maven.core.extenvvar.ExternalEnvVarHandler.java

/**
 * Finds all of the environment json schemas and combines them together
 *//*from  w  ww .jav a2 s . c o m*/
private static JsonSchema loadEnvironmentSchemas(ClassLoader classLoader, String... folderPaths)
        throws IOException {
    JsonSchema answer = null;
    Enumeration<URL> resources = classLoader.getResources(ENVIRONMENT_SCHEMA_FILE);
    while (resources.hasMoreElements()) {
        URL url = resources.nextElement();
        JsonSchema schema = loadSchema(url);
        answer = combineSchemas(answer, schema);
    }
    for (String folderPath : folderPaths) {
        File file = new File(folderPath, ENVIRONMENT_SCHEMA_FILE);
        if (file.isFile()) {
            JsonSchema schema = loadSchema(file);
            answer = combineSchemas(answer, schema);
        }
    }
    return answer;
}

From source file:org.eclipse.virgo.snaps.SnapsTagTests.java

private static final String[] toArray(Enumeration<?> enumeration) {
    List<String> list = new ArrayList<String>();
    while (enumeration.hasMoreElements()) {
        String element = enumeration.nextElement().toString();
        list.add(element);// w w w  . j a  va2 s.co  m
    }
    return list.toArray(new String[list.size()]);
}

From source file:io.fabric8.vertx.maven.plugin.utils.WebJars.java

public static void extract(final AbstractVertxMojo mojo, File in, File out, boolean stripVersion)
        throws IOException {
    ZipFile file = new ZipFile(in);
    try {/*from ww  w. j  a v a2  s .  c  o m*/
        Enumeration<? extends ZipEntry> entries = file.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            if (entry.getName().startsWith(WEBJAR_LOCATION) && !entry.isDirectory()) {
                // Compute destination.
                File output = new File(out, entry.getName().substring(WEBJAR_LOCATION.length()));
                if (stripVersion) {
                    String path = entry.getName().substring(WEBJAR_LOCATION.length());
                    Matcher matcher = WEBJAR_INTERNAL_PATH_REGEX.matcher(path);
                    if (matcher.matches()) {
                        output = new File(out, matcher.group(1) + "/" + matcher.group(3));
                    } else {
                        mojo.getLog().warn(path
                                + " does not match the regex - did not strip the version for this" + " file");
                    }
                }
                InputStream stream = null;
                try {
                    stream = file.getInputStream(entry);
                    output.getParentFile().mkdirs();
                    org.apache.commons.io.FileUtils.copyInputStreamToFile(stream, output);
                } catch (IOException e) {
                    mojo.getLog().error("Cannot unpack " + entry.getName() + " from " + file.getName(), e);
                    throw e;
                } finally {
                    IOUtils.closeQuietly(stream);
                }
            }
        }
    } finally {
        IOUtils.closeQuietly(file);
    }
}