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:mojo.view.util.DebugUtils.java

@SuppressWarnings("rawtypes")
public static void logRequestHeaders(HttpServletRequest req) {
    logger.debug("REQUEST HEADERS");
    logger.debug("---------------");

    Enumeration enums = req.getHeaderNames();

    while (enums.hasMoreElements()) {
        String headerName = (String) enums.nextElement();
        String headerValue = req.getHeader(headerName);
        logger.debug(headerName + ": " + headerValue);
    }// ww  w  .ja  va  2s. co m

    logger.debug("");
}

From source file:net.bpelunit.util.ZipUtil.java

public static void unzipFile(File zip, File dir) throws IOException {
    InputStream in = null;/*from www  .ja  v a  2s  . c om*/
    OutputStream out = null;
    ZipFile zipFile = new ZipFile(zip);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();

    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        if (!entry.getName().endsWith("/")) {
            File unzippedFile = new File(dir, entry.getName());
            try {
                in = zipFile.getInputStream(entry);
                unzippedFile.getParentFile().mkdirs();

                out = new FileOutputStream(unzippedFile);

                IOUtils.copy(in, out);
            } finally {
                IOUtils.closeQuietly(in);
                IOUtils.closeQuietly(out);
            }
        }
    }
}

From source file:com.taobao.pushit.commons.ClientLoggerInit.java

private static FileAppender getFileAppender(Logger logger) {
    Enumeration<?> allAppenders = logger.getAllAppenders();
    while (allAppenders.hasMoreElements()) {
        Object appender = allAppenders.nextElement();
        if (appender instanceof FileAppender) {
            return (FileAppender) appender;
        }/*from  www  .jav  a2s .  c  om*/
    }
    return null;
}

From source file:com.splout.db.common.CompressorUtil.java

public static void uncompress(File file, File dest) throws IOException {
    ZipFile zipFile = new ZipFile(file);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();

    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        File entryDestination = new File(dest, entry.getName());
        entryDestination.getParentFile().mkdirs();
        InputStream in = zipFile.getInputStream(entry);
        OutputStream out = new FileOutputStream(entryDestination);
        IOUtils.copy(in, out);/*from   w ww .  j a  v  a2s.c o  m*/
        in.close();
        out.close();
    }
}

From source file:Main.java

public static List<File> unzip(File zip, File toDir) throws IOException {
    ZipFile zf = null;/*from   w w  w. jav  a2  s  .c  o  m*/
    List<File> files = null;
    try {
        zf = new ZipFile(zip);
        files = new ArrayList<File>();
        Enumeration<?> entries = zf.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = (ZipEntry) entries.nextElement();
            if (entry.isDirectory()) {
                new File(toDir, entry.getName()).mkdirs();
                continue;
            }

            InputStream input = null;
            OutputStream output = null;
            try {
                File f = new File(toDir, entry.getName());
                input = zf.getInputStream(entry);
                output = new FileOutputStream(f);
                copy(input, output);
                files.add(f);
            } finally {
                closeQuietly(output);
                closeQuietly(input);
            }
        }
    } finally {
        if (zf != null) {
            zf.close();
        }
    }
    return files;
}

From source file:Main.java

/**
 * Adds all elements in the enumeration to the given collection.
 * /*from  www  .j  a va2 s  .  com*/
 * @param collection
 *            the collection to add to
 * @param enumeration
 *            the enumeration of elements to add, may not be null
 * @throws NullPointerException
 *             if the collection or enumeration is null
 */
public static void addAll(Collection collection, Enumeration enumeration) {
    while (enumeration.hasMoreElements()) {
        collection.add(enumeration.nextElement());
    }
}

From source file:mojo.view.util.DebugUtils.java

@SuppressWarnings("rawtypes")
public static void logRequestParameters(HttpServletRequest req) {
    logger.debug("REQUEST PARAMETERS");
    logger.debug("------------------");

    Enumeration enums = req.getParameterNames();

    while (enums.hasMoreElements()) {
        String paramName = (String) enums.nextElement();
        String[] paramValues = req.getParameterValues(paramName);
        StringBuilder sb = new StringBuilder();
        sb.append(paramName).append(": " + paramValues);
        logger.debug(sb.toString());/*from ww w  .  j av  a2 s . co m*/
    }

    logger.debug("");
}

From source file:mojo.view.util.DebugUtils.java

@SuppressWarnings("rawtypes")
public static void logRequestAttributes(HttpServletRequest req) {
    logger.debug("REQUEST ATTRIBUTES");
    logger.debug("------------------");

    Enumeration enums = req.getAttributeNames();

    while (enums.hasMoreElements()) {
        String attrName = (String) enums.nextElement();
        Object attrValue = req.getAttribute(attrName);
        StringBuilder sb = new StringBuilder();
        sb.append(attrName + ": " + attrValue);
        logger.debug(sb.toString());/*from   w  w  w .j av a2 s  .  c  om*/
    }

    logger.debug("");
}

From source file:com.common.utils.NetworkUtils.java

public static String getLocalHostIp() {
    String ips = "";//getString(R.string.ipaddr);
    try {//www .j  a  v  a  2 s.  c om
        Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();

        while (en.hasMoreElements()) {
            NetworkInterface nif = en.nextElement();
            Enumeration<InetAddress> inet = nif.getInetAddresses();

            while (inet.hasMoreElements()) {
                InetAddress ip = inet.nextElement();
                if (!ip.isLoopbackAddress() && InetAddressUtils.isIPv4Address(ip.getHostAddress())) {

                    ips = ips + nif.getName() + ":" + ip.getHostAddress() + "  ";

                }
            }

        }
    } catch (SocketException e) {
        e.printStackTrace();
    }
    return ips;

}

From source file:doc.action.SelectedDocsUtils.java

public static Collection saveSelectedDocsIDs(HttpServletRequest request) {
    //System.out.println("start");
    Collection documents = (Collection) request.getSession().getAttribute(Constant.SELECTED_PRESIDENTS);
    //System.out.println(documents);
    if (documents == null) {
        documents = new ArrayList();
        request.getSession().setAttribute(Constant.SELECTED_PRESIDENTS, documents);
    }//from ww w.  j  ava 2  s . com

    Enumeration parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        String parameterName = (String) parameterNames.nextElement();
        if (parameterName.startsWith("chkbx_")) {
            String docId = StringUtils.substringAfter(parameterName, "chkbx_");
            String parameterValue = request.getParameter(parameterName);
            if (parameterValue.equals(Constant.SELECTED)) {
                if (!documents.contains(docId)) {
                    documents.add(docId);
                }
            } else {
                documents.remove(docId);
            }
        }
    }

    return documents;
}