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:ZipFileUtil.java

/**
 * @param zipFile/*  ww w  .  j av  a  2  s  . c  om*/
 * @param jiniHomeParentDir
 */
public static void unzipFileIntoDirectory(ZipFile zipFile, File jiniHomeParentDir) {
    Enumeration files = zipFile.entries();
    File f = null;
    FileOutputStream fos = null;

    while (files.hasMoreElements()) {
        try {
            ZipEntry entry = (ZipEntry) files.nextElement();
            InputStream eis = zipFile.getInputStream(entry);
            byte[] buffer = new byte[1024];
            int bytesRead = 0;

            f = new File(jiniHomeParentDir.getAbsolutePath() + File.separator + entry.getName());

            if (entry.isDirectory()) {
                f.mkdirs();
                continue;
            } else {
                f.getParentFile().mkdirs();
                f.createNewFile();
            }

            fos = new FileOutputStream(f);

            while ((bytesRead = eis.read(buffer)) != -1) {
                fos.write(buffer, 0, bytesRead);
            }
        } catch (IOException e) {
            e.printStackTrace();
            continue;
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    // ignore
                }
            }
        }
    }
}

From source file:Main.java

/**
 * Check whether the given Enumeration contains the given element.
 *
 * @param enumeration the Enumeration to check
 * @param element     the element to look for
 * @return {@code true} if found, {@code false} else
 *///  w  w  w  . j a v a 2 s  . c  om
public static boolean contains(Enumeration<?> enumeration, Object element) {
    if (enumeration != null) {
        while (enumeration.hasMoreElements()) {
            Object candidate = enumeration.nextElement();
            if (ObjectUtils.nullSafeEquals(candidate, element)) {
                return true;
            }
        }
    }
    return false;
}

From source file:Main.java

/**
 * convert to List<T> from Enumeration<T>
 * //  www .  j  a v a  2  s. c  o m
 * @param enumeration
 * @return
 */
public static <T> List<T> convert(Enumeration<T> enumeration) {
    if (enumeration == null) {
        return Collections.emptyList();
    }
    ArrayList<T> result = new ArrayList<T>();
    while (enumeration.hasMoreElements()) {
        result.add(enumeration.nextElement());
    }
    return result;
}

From source file:com.dragome.compiler.utils.FileManager.java

private static List<String> findClassesInJar(JarFile jarFile) {
    ArrayList<String> result = new ArrayList<String>();

    final Enumeration<JarEntry> entries = jarFile.entries();
    while (entries.hasMoreElements()) {
        final JarEntry entry = entries.nextElement();
        final String entryName = entry.getName();
        if (entryName.endsWith(".class"))
            result.add(entryName.replace('/', File.separatorChar).replace(".class", ""));
    }/*  www  . j  av  a 2  s.com*/

    return result;
}

From source file:com.frostwire.util.VPNs.java

public static void printNetworkInterfaces() {
    try {/*ww w  .j a va  2  s  . c  om*/
        Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
        while (networkInterfaces.hasMoreElements()) {
            NetworkInterface iface = networkInterfaces.nextElement();
            System.out.println(iface.getIndex() + ":" + iface.getDisplayName() + ":" + "virtual="
                    + iface.isVirtual() + ":" + "mtu=" + iface.getMTU() + ":mac="
                    + (iface.getHardwareAddress() != null
                            ? "0x" + ByteUtils.encodeHex(iface.getHardwareAddress())
                            : "n/a"));
        }
    } catch (SocketException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:Main.java

public static String toString(Enumeration/*<String>*/ enumer, String separator) {
    if (separator == null)
        separator = ","; //NOI18N
    StringBuffer buf = new StringBuffer();
    while (enumer.hasMoreElements()) {
        if (buf.length() != 0)
            buf.append(separator);//from  ww  w.j  av a2  s  .  c om
        buf.append(enumer.nextElement());
    }
    return buf.toString();
}

From source file:Main.java

/**
 * Returns a semicolumn separated list of keys and values in the dictionary.
 * /*  w  w w.  ja  va 2s  .co m*/
 * Here is an example of returned String "key1 = value1; key2 = value2;"
 * 
 * 
 * 
 * @param dict
 *            Dictionary<Object,Object>
 * @return : String.
 */
public static String dictionaryToString(Dictionary<Object, Object> dict) {
    Enumeration<Object> keys = dict.keys();
    Object key, value;
    StringBuffer result = new StringBuffer();

    while (keys.hasMoreElements()) {
        key = keys.nextElement();
        value = dict.get(key);

        result.append(key.toString());
        result.append(" = ");
        result.append(value.toString());
        result.append("; ");
    }

    return result.toString();
}

From source file:com.frostwire.util.VPNs.java

private static boolean isAnyNetworkInterfaceATunnel() {
    boolean result = false;
    try {//from   w ww . j av  a 2 s  . c o m
        Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
        while (networkInterfaces.hasMoreElements()) {
            NetworkInterface iface = networkInterfaces.nextElement();
            if (iface.getDisplayName().contains("tun")) {
                result = true;
                break;
            }
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }

    return result;
}

From source file:eurecom.constrained.devices.ReadZipFile.java

public static void unzip(final ZipFile zipfile, final File directory) throws IOException {

    final Enumeration<? extends ZipEntry> entries = zipfile.entries();
    while (entries.hasMoreElements()) {
        final ZipEntry entry = entries.nextElement();
        final File file = file(directory, entry);
        if (entry.isDirectory()) {
            continue;
        }/*www. jav  a 2s  .  c om*/
        final InputStream input = zipfile.getInputStream(entry);
        try {
            // copy bytes from input to file
        } finally {
            input.close();
        }
    }
}

From source file:info.magnolia.cms.filters.CosMultipartRequestFilter.java

/**
 * Adds all request paramaters as request attributes.
 * @param request HttpServletRequest//from  w  w w. j  a v  a2  s. com
 */
private static MultipartForm parseParameters(HttpServletRequest request) throws IOException {
    MultipartForm form = new MultipartForm();
    String encoding = StringUtils.defaultString(request.getCharacterEncoding(), "UTF-8");
    MultipartRequest multi = new MultipartRequest(request, Path.getTempDirectoryPath(), MAX_FILE_SIZE, encoding,
            null);
    Enumeration params = multi.getParameterNames();
    while (params.hasMoreElements()) {
        String name = (String) params.nextElement();
        String value = multi.getParameter(name);
        form.addParameter(name, value);
        String[] s = multi.getParameterValues(name);
        if (s != null) {
            form.addparameterValues(name, s);
        }
    }
    Enumeration files = multi.getFileNames();
    while (files.hasMoreElements()) {
        String name = (String) files.nextElement();
        form.addDocument(name, multi.getFilesystemName(name), multi.getContentType(name), multi.getFile(name));
    }
    request.setAttribute(MultipartForm.REQUEST_ATTRIBUTE_NAME, form);
    return form;
}