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:io.apiman.servers.gateway_es.Starter.java

/**
 * Loads properties from a file and puts them into system properties.
 *//*from  w w w.  j  ava2s.  c  o m*/
@SuppressWarnings({ "nls", "unchecked" })
protected static void loadProperties() {
    URL configUrl = Starter.class.getClassLoader().getResource("gateway_es-apiman.properties");
    if (configUrl == null) {
        throw new RuntimeException(
                "Failed to find properties file (see README.md): gateway_es-apiman.properties");
    }
    InputStream is = null;
    try {
        is = configUrl.openStream();
        Properties props = new Properties();
        props.load(is);
        Enumeration<String> names = (Enumeration<String>) props.propertyNames();
        while (names.hasMoreElements()) {
            String name = names.nextElement();
            String value = props.getProperty(name);
            System.setProperty(name, value);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:Main.java

public static String getLocalIpAddress() throws Exception {
    String ipAddress = null;/*www . ja  v a2  s .co m*/

    Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();

    while (en.hasMoreElements()) {
        NetworkInterface e = en.nextElement();
        Enumeration<InetAddress> addresses = e.getInetAddresses();
        while (addresses.hasMoreElements()) {
            InetAddress address = addresses.nextElement();
            if (!address.isLoopbackAddress() && address.isSiteLocalAddress()) {
                ipAddress = address.getHostName();
                break;
            }
        }
    }

    if (ipAddress == null) {
        ipAddress = InetAddress.getLocalHost().getHostAddress();
    }

    return ipAddress;
}

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.
 * //from www .  j  av  a  2s .c  om
 * 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

/**
 * Create a Hashtable from a key, value, key, value... style
 * Enumeration./*  w  w  w  . java  2  s.  c om*/
 */
public static Hashtable createHashtable(Enumeration e) {
    Hashtable result = new Hashtable();
    while (e.hasMoreElements())
        result.put(e.nextElement(), e.nextElement());
    return result;
}

From source file:Main.java

public static Vector createVector(Enumeration e) {
    Vector result = new Vector();
    while (e.hasMoreElements())
        result.addElement(e.nextElement());
    return result;
}

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.
 *//*  w ww. j a v  a  2  s. co m*/
public static <A, E extends A> A[] toArray(Enumeration<E> enumeration, A[] array) {
    ArrayList<A> elements = new ArrayList<>();
    while (enumeration.hasMoreElements()) {
        elements.add(enumeration.nextElement());
    }
    return elements.toArray(array);
}

From source file:EnumerationIterator1.java

public static Iterator iterator(final Enumeration e) {
    return new Iterator() {
        public boolean hasNext() {
            return e.hasMoreElements();
        }// ww  w  . ja v a  2 s. c  o m

        public Object next() {
            return e.nextElement();
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}

From source file:Main.java

/**
 * Saves an index (Hashtable) to a file.
 * //w ww .  ja  v a  2s  .  c  o m
 * @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:Main.java

public static String getLocalIpAddress() {
    try {//from   w  w  w . j a  v  a  2s. co m
        Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
        while (en.hasMoreElements()) {
            NetworkInterface intf = en.nextElement();
            String name = intf.getName();
            if (name.compareTo("eth0") == 0 || name.compareTo("wlan0") == 0) {
                Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses();
                while (enumIpAddr.hasMoreElements()) {
                    InetAddress inetAddress = enumIpAddr.nextElement();
                    if (inetAddress.getClass() == Inet4Address.class) {
                        return inetAddress.getHostAddress();
                    }
                }
            }
        }
    } catch (SocketException ex) {
        Log.e("MY", ex.toString());
    }
    return null;
}

From source file:Main.java

public static String getIpAddress() {
    try {//w w  w  .j  a v  a 2  s  . c o m
        Enumeration en = NetworkInterface.getNetworkInterfaces();

        while (en.hasMoreElements()) {
            NetworkInterface ex = (NetworkInterface) en.nextElement();
            Enumeration enumIpAddr = ex.getInetAddresses();

            while (enumIpAddr.hasMoreElements()) {
                InetAddress inetAddress = (InetAddress) enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress()) {
                    return inetAddress.getHostAddress().toString();
                }
            }
        }

        return null;
    } catch (SocketException var4) {
        var4.printStackTrace();
        return null;
    }
}