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.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   w ww . j  a  v a  2s  . com
    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:com.bank.manager.configs.ContextCleanupListener.java

/**
 * Find all ServletContext attributes which implement {@link DisposableBean}
 * and destroy them, removing all affected ServletContext attributes eventually.
 * @param sc the ServletContext to check
 *///from   ww w  . j a va  2  s. c  o  m
static void cleanupAttributes(ServletContext sc) {
    Enumeration<String> attrNames = sc.getAttributeNames();
    while (attrNames.hasMoreElements()) {
        String attrName = attrNames.nextElement();
        if (attrName.startsWith("org.springframework.")) {
            Object attrValue = sc.getAttribute(attrName);
            if (attrValue instanceof DisposableBean) {
                try {
                    ((DisposableBean) attrValue).destroy();
                } catch (Throwable ex) {
                    logger.error("Couldn't invoke destroy method of attribute with name '" + attrName + "'",
                            ex);
                }
            }
        }
    }
}

From source file:Main.java

/** 
 * Adjust all fonts for displaying to the given size.
 * <br>Use with care!/* w  ww. j a  v a  2s  .c o m*/
 */
public static void setUIFontSize(final int size) {

    final java.util.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 = ifont.deriveFont((float) size);
            UIManager.put(key, ofont);
        }
    }
}

From source file:Main.java

public static InetAddress getHostAddress() {
    try {//  ww  w.ja  va2s. com
        Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
        while (interfaces.hasMoreElements()) {
            NetworkInterface iface = interfaces.nextElement();
            // filters out 127.0.0.1 and inactive interfaces
            if (iface.isLoopback() || !iface.isUp())
                continue;

            Enumeration<InetAddress> addresses = iface.getInetAddresses();
            while (addresses.hasMoreElements()) {
                InetAddress addr = addresses.nextElement();
                if (addr instanceof Inet4Address)
                    return addr;
            }
        }
    } catch (SocketException e) {
        throw new RuntimeException(e);
    }
    return null;
}

From source file:Main.java

/**
 * Marshal the elements from the given enumeration into an array of the given type. Enumeration elements must be assignable to the type
 * of the given array. The array returned will be a different instance than the array given.
 * /*  www.ja  va2s. c  o  m*/
 * @param enumeration
 *            the enumeration
 * @param array
 *            the array
 * @return the array representation of the enumeration
 * @param <A>
 *            the type of the array
 * @param <E>
 *            the type of th enumeration
 */
public static <A, E extends A> A[] toArray(Enumeration<E> enumeration, A[] array) {
    final ArrayList<A> elements = new ArrayList<A>();
    while (enumeration.hasMoreElements()) {
        elements.add(enumeration.nextElement());
    }
    return elements.toArray(array);
}

From source file:com.ironiacorp.persistence.SqlUtil.java

/**
 * Unload the database driver (if it's loaded).
 */// www . j av  a  2  s.c  o  m
public static void unloadDriver(String driver) {
    if (!SqlUtil.isDriverLoaded(driver)) {
        return;
    }

    Enumeration<Driver> drivers = DriverManager.getDrivers();
    while (drivers.hasMoreElements()) {
        Driver d = drivers.nextElement();
        if (d.getClass().getName().equals(driver)) {
            try {
                DriverManager.deregisterDriver(d);
            } catch (SQLException e) {
            }
        }
    }
}

From source file:Main.java

/**
 * Iterates over APK (jar entries) to populate
 * //from w w w.  j  av  a  2 s. co  m
 * @param projectFile
 * @return
 * @throws IOException
 * @throws CertificateException
 */
public static List<Certificate> populateCertificate(File projectFile) throws IOException, CertificateException {
    List<Certificate> certList = new ArrayList<Certificate>();
    JarFile jar = new JarFile(projectFile);
    Enumeration<JarEntry> jarEntries = jar.entries();
    while (jarEntries.hasMoreElements()) {
        JarEntry entry = jarEntries.nextElement();
        if (entry.getName().toLowerCase().contains(DSA) || entry.getName().toLowerCase().contains(RSA)) {
            certList.addAll(extractCertificate(jar, entry));
        }
    }
    return certList;
}

From source file:Main.java

/**
 * Get channel from META-INF directory.//from   w ww . j  a  v a2s . co 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

public static Iterable<String> iterateAsStrings(Enumeration<?> enumeration) {
    List<String> list = new ArrayList<String>();
    while (enumeration.hasMoreElements()) {
        list.add(valueOf(enumeration.nextElement()));
    }/*  w  w w.ja  va 2 s .  co  m*/
    return list;
}

From source file:Main.java

/**
 * Convert the enumeration to a collection.
 *
 * @param enumeration The enumeration to convert to Collection.
 * @param <T>         The type of object stored in the enumeration.
 *
 * @return A Collection containing all the elements of the enumeration.
 *///  w w  w .  ja  va2 s  . c o  m
public static <T> Collection<T> toCollection(Enumeration<T> enumeration) {
    Collection<T> collection = newList(25);

    while (enumeration.hasMoreElements()) {
        collection.add(enumeration.nextElement());
    }

    return collection;
}