org.elasticsearch.hadoop.rest.NetworkUtils Maven / Gradle / Ivy
                 Go to download
                
        
                    Show more of this group  Show more artifacts with this name
Show all versions of elasticsearch-spark-20_2.10 Show documentation
                Show all versions of elasticsearch-spark-20_2.10 Show documentation
Elasticsearch Spark (for Spark 2.X)
                
            package org.elasticsearch.hadoop.rest;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public abstract class NetworkUtils {
    private NetworkUtils() {
    }
    /** Helper for getInterfaces, recursively adds subinterfaces to {@code target} */
    private static void addAllInterfaces(List target, List level) {
        if (!level.isEmpty()) {
            target.addAll(level);
            for (NetworkInterface intf : level) {
                addAllInterfaces(target, Collections.list(intf.getSubInterfaces()));
            }
        }
    }
    /** Return all interfaces (and subinterfaces) on the system */
    static List getInterfaces() throws SocketException {
        List all = new ArrayList();
        addAllInterfaces(all, Collections.list(NetworkInterface.getNetworkInterfaces()));
        return all;
    }
    /** Returns all global scope addresses for interfaces that are up. */
    static InetAddress[] getGlobalInterfaces() throws SocketException {
        List list = new ArrayList ();
        for (NetworkInterface intf : getInterfaces()) {
            if (intf.isUp()) {
                for (InetAddress address : Collections.list(intf.getInetAddresses())) {
                    if (address.isLoopbackAddress() == false &&
                            address.isSiteLocalAddress() == false &&
                            address.isLinkLocalAddress() == false) {
                        list.add(address);
                    }
                }
            }
        }
        return list.toArray(new InetAddress[list.size()]);
    }
}
           © 2015 - 2025 Weber Informatics LLC | Privacy Policy