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:org.nebula.service.core.HostAddress.java

public static String getLocalHost() throws Exception {

    Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
    while (interfaces.hasMoreElements()) {
        NetworkInterface current = interfaces.nextElement();

        if (!current.isUp() || current.isLoopback() || current.isVirtual()) {
            continue;
        }//from w  w  w . j  a v a2 s .  com
        Enumeration<InetAddress> addresses = current.getInetAddresses();
        while (addresses.hasMoreElements()) {
            InetAddress current_addr = addresses.nextElement();
            if (current_addr.isLoopbackAddress()
                    || !InetAddressUtils.isIPv4Address(current_addr.getHostAddress())) {
                continue;
            }
            return current_addr.getHostName();
        }
    }

    throw new Exception("Failed to get local hostname");
}

From source file:com.zb.app.common.file.FileUtils.java

public static void unJar(File jarFile, File toDir) throws IOException {
    JarFile jar = new JarFile(jarFile);
    try {/*from  w  w w. ja  v a2 s .c  o m*/
        Enumeration<JarEntry> entries = jar.entries();
        while (entries.hasMoreElements()) {
            JarEntry entry = (JarEntry) entries.nextElement();
            if (!entry.isDirectory()) {
                InputStream in = jar.getInputStream(entry);
                try {
                    File file = new File(toDir, entry.getName());
                    if (!file.getParentFile().mkdirs()) {
                        if (!file.getParentFile().isDirectory()) {
                            throw new IOException("Mkdirs failed to create " + file.getParentFile().toString());
                        }
                    }
                    OutputStream out = new FileOutputStream(file);
                    try {
                        byte[] buffer = new byte[8192];
                        int i;
                        while ((i = in.read(buffer)) != -1) {
                            out.write(buffer, 0, i);
                        }
                    } finally {
                        out.close();
                    }
                } finally {
                    in.close();
                }
            }
        }
    } finally {
        jar.close();
    }
}

From source file:gov.nih.nci.protexpress.util.ConfigurationHelper.java

/**
 * @return the ldap context parameters./*from  w ww  . ja  v  a 2s  . c  om*/
 */
public static Hashtable<String, String> getLdapContextParameters() {
    if (ldapContextParams == null) {
        ldapContextParams = new Hashtable<String, String>();

        ServletContext context = ServletActionContext.getServletContext();
        Enumeration<String> e = context.getInitParameterNames();
        while (e.hasMoreElements()) {
            String param = e.nextElement();
            if (param.startsWith("ldap")) {
                ldapContextParams.put(param, context.getInitParameter(param));
            }
        }
    }
    return ldapContextParams;
}

From source file:Main.java

public static <T> List<T> toList(Enumeration<? extends T> things) {
    AbstractList<T> list = new ArrayList<T>();
    while (things.hasMoreElements()) {
        list.add(things.nextElement());
    }/*  w  ww  .  j  ava  2  s  .  c  o m*/
    return list;
}

From source file:Main.java

/**
 * Adds all elements in the enumeration to the given collection.
 * //from w w  w . j  ava2s.  c  om
 * @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:Main.java

public static String getIpAddress(boolean alwaysGetWifi) {

    try {/*  ww w. j a va  2s.  c  o  m*/
        Enumeration<NetworkInterface> enmNetI = NetworkInterface.getNetworkInterfaces();
        while (enmNetI.hasMoreElements()) {
            NetworkInterface networkInterface = enmNetI.nextElement();
            boolean b = alwaysGetWifi
                    ? networkInterface.getDisplayName().equals("wlan0")
                            || networkInterface.getDisplayName().equals("eth0")
                    : true;
            if (b) {
                Enumeration<InetAddress> inetAddressEnumeration = networkInterface.getInetAddresses();
                while (inetAddressEnumeration.hasMoreElements()) {
                    InetAddress inetAddress = inetAddressEnumeration.nextElement();
                    if (inetAddress instanceof Inet4Address && !inetAddress.isLoopbackAddress()) {
                        return "net name is " + networkInterface.getDisplayName() + ",ip is "
                                + inetAddress.getHostAddress();
                    }
                }
            }
        }
    } catch (SocketException e) {
        e.printStackTrace();
    }

    return "";
}

From source file:Main.java

public static File UpdateZipFromPath(String sZipFile, String sPath) throws Exception {
    File tmpFile = File.createTempFile("z4zip-tmp-", ".zip");
    tmpFile.deleteOnExit();//from  w w w  .  j av a2s .  c o m
    ZipFile inZip = new ZipFile(sZipFile);
    ZipOutputStream outZip = new ZipOutputStream(new FileOutputStream(tmpFile.getPath()));

    Enumeration<? extends ZipEntry> entries = inZip.entries();
    while (entries.hasMoreElements()) {
        ZipEntry e = entries.nextElement();
        outZip.putNextEntry(e);
        if (!e.isDirectory()) {
            File f = new File(sPath + "/" + e.getName());
            if (f.exists()) {
                copy(new FileInputStream(f.getPath()), outZip);
            } else {
                copy(inZip.getInputStream(e), outZip);
            }
        }
        outZip.closeEntry();
    }
    inZip.close();
    outZip.close();
    return tmpFile;
}

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  w ww.  j  a  v a  2 s.c o  m*/
    }
    return null;
}

From source file:Main.java

public static String readChannelString(String path, String prefixString) {
    String ret = null;/*from  w  w  w .j a  v a2s.c  o  m*/
    ZipFile zipfile = null;
    try {
        zipfile = new ZipFile(path);
        Enumeration<?> entries = zipfile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = ((ZipEntry) entries.nextElement());
            String entryName = entry.getName();
            if (debug) {
                System.out.println(entryName);
            }
            if (entryName.contains(prefixString)) {
                ret = entryName;

                break;
            }
        }

        if (ret != null) {
            String[] split = ret.split("_");
            if (split != null && split.length >= 2) {
                String substring = ret.substring(split[0].length() + 1);
                if (debug) {
                    System.out.println(String.format("find channel string:%s", substring));
                }
                return substring;

            }
        } else {
            if (debug) {
                System.out.println("not find channel");
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (zipfile != null) {
            try {
                zipfile.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    return ret;

}

From source file:com.doculibre.constellio.wicket.utils.SimpleParamsUtils.java

@SuppressWarnings("unchecked")
public static SimpleParams toSimpleParams(HttpServletRequest request) {
    SimpleParams params = new SimpleParams();
    Enumeration<String> paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
        String paramName = (String) paramNames.nextElement();
        List<String> paramValues = Arrays.asList(request.getParameterValues(paramName));
        params.add(paramName, paramValues);
    }/*  w ww.  j  ava 2 s  .  c o  m*/
    return params;
}