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.baomidou.framework.common.JarHelper.java

public static List<String> listFiles(JarFile jarFile, String endsWith) {
    if (jarFile == null || StringUtils.isEmpty(endsWith)) {
        return null;
    }/* w  ww.  jav  a2s. com*/
    List<String> files = new ArrayList<String>();
    Enumeration<JarEntry> entries = jarFile.entries();
    while (entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();
        String name = entry.getName();
        if (name.endsWith(endsWith)) {
            files.add(name);
        }
    }
    return files;
}

From source file:irille.pub.verify.RandomImageServlet.java

public static String getHeader(HttpServletRequest req, String name) {
    String value = req.getHeader(name);
    if (value != null)
        return value;
    Enumeration names = req.getHeaderNames();
    while (names.hasMoreElements()) {
        String n = (String) names.nextElement();
        if (n.equalsIgnoreCase(name)) {
            return req.getHeader(n);
        }// www .  j  a va2  s  .c  om
    }
    return null;
}

From source file:Main.java

/**
 * Saves an index (Hashtable) to a file.
 * //from w  ww  .j  av a 2  s.  c  om
 * @param root_
 *            The file where the index is stored in.
 * @param index
 *            The indextable.
 * @exception IOException
 *                If an internal error prevents the file from being written.
 */
public static void saveIndex(File root_, String name, Hashtable index) throws IOException {
    File indexfile = new File(root_, name);
    PrintWriter out = new PrintWriter(new FileWriter(indexfile));
    Enumeration keys = index.keys();
    String key = null;
    while (keys.hasMoreElements()) {
        key = (String) keys.nextElement();
        out.println(key);
        out.println((Long) index.get(key));
    }
    out.close();
}

From source file:com.bluexml.tools.miscellaneous.Translate.java

protected static TreeMap<String, String> loadProperties(File input) throws FileNotFoundException, IOException {
    TreeMap<String, String> map = new TreeMap<String, String>();
    Properties props = new Properties();
    FileInputStream fin = new FileInputStream(input);
    props.load(fin);//from  ww w  .j  a va 2s.  c  o m
    Enumeration<Object> keys = props.keys();
    while (keys.hasMoreElements()) {
        String nextElement = (String) keys.nextElement();
        String property = props.getProperty(nextElement);

        map.put(nextElement, property);
    }
    return map;
}

From source file:Main.java

/**
 * Get channel from META-INF directory.// w  w  w  .  ja  v a2s .  c o m
 *
 * @return the channel name if success,otherwise return "none"
 */
public static String getChannel(Context context) {
    ApplicationInfo appinfo = context.getApplicationInfo();
    String sourceDir = appinfo.sourceDir;
    String ret = "";
    ZipFile zipfile = null;
    try {
        zipfile = new ZipFile(sourceDir);
        Enumeration<?> entries = zipfile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = ((ZipEntry) entries.nextElement());
            String entryName = entry.getName();
            if (entryName.startsWith("META-INF/channel")) {
                ret = entryName;
                break;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (zipfile != null) {
            try {
                zipfile.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    String[] split = ret.split("_");
    if (split != null && split.length >= 2) {
        return ret.substring(split[0].length() + 1);

    } else {
        return "none";
    }
}

From source file:Main.java

/**
 * Return a Dictionary object which is a subset of the given Dictionary,
 * where the tags all <b>begin</b> with the given tag.
 * /* w w w .  java2  s .c  o  m*/
 * Hastables and Properties can be used as they are Dictionaries.
 * 
 * @param superset
 *            .
 * 
 * 
 * @param tag
 *            String
 * @param result
 *            Dictionary<String,Object>
 */
public static void getSubset(Dictionary<String, Object> superset, String tag,
        Dictionary<String, Object> result) {
    if ((result == null) || (tag == null) || (superset == null)) {
        throw new IllegalArgumentException("Invalid arguments specified : superset = " + superset + " tag = "
                + tag + " result = " + result);
    }

    String key;
    Enumeration<String> enumKey = superset.keys();

    while (enumKey.hasMoreElements()) {
        key = enumKey.nextElement();

        if (key.startsWith(tag)) {
            result.put(key, superset.get(key));
        }
    }
}

From source file:Main.java

public static <T> Iterable<T> iterate(Enumeration<T> enumeration) {
    List<T> list = new ArrayList<T>();
    while (enumeration.hasMoreElements()) {
        list.add(enumeration.nextElement());
    }/*  ww  w . ja  v  a 2s .c om*/
    return list;
}

From source file:Main.java

public static String[] getXmlFiles(String path) {
    List<String> xmlFiles = new ArrayList<>();
    ZipFile zipFile = null;//from w ww.  j av  a2  s.c  o m
    try {
        zipFile = new ZipFile(path);
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            String name = entry.getName();
            if (name.endsWith(".xml") && !name.equals("AndroidManifest.xml")) {
                xmlFiles.add(name);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (zipFile != null) {
            try {
                zipFile.close();
            } catch (IOException ignored) {
            }
        }
    }
    Collections.sort(xmlFiles);
    return xmlFiles.toArray(new String[xmlFiles.size()]);
}

From source file:Main.java

/** 
 * Sets all used fonts for displaying to the specified font df
 * <br>Use with care! //from   w  w w.j a v  a  2 s  . com
 */
public static void setUIFont(final Font df) {

    setUIFontSize(df.getSize());
    final Enumeration<Object> keys = UIManager.getLookAndFeelDefaults().keys();
    while (keys.hasMoreElements()) {
        final Object key = keys.nextElement();
        final Object value = UIManager.get(key);
        if (value instanceof Font) {
            final Font ifont = (Font) value;
            final Font ofont = new FontUIResource(df.getName(), ifont.getStyle(), df.getSize());
            UIManager.put(key, ofont);
        }
    }
}

From source file:Main.java

public static String getChannel(Context context) {
    ApplicationInfo appinfo = context.getApplicationInfo();
    String sourceDir = appinfo.sourceDir;
    ZipFile zipfile = null;/*from  w w w  .j  ava 2  s. c  om*/
    String ret = null;
    try {
        zipfile = new ZipFile(sourceDir);
        Enumeration<?> entries = zipfile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = ((ZipEntry) entries.nextElement());
            String entryName = entry.getName();
            if (entryName.startsWith(FOLDER_NAME) && entryName.contains(CHANNEL_SCHEME)) {
                ret = entryName;
                break;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (zipfile != null) {
            try {
                zipfile.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    try {
        if (ret != null) {
            String[] split = ret.split(CHANNEL_SCHEME_SPIT);
            if (split.length >= 2) {
                return ret.substring(split[0].length() + 1);
            }
        }
    } catch (Exception e) {

    }

    return null;
}