All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tngtech.propertyloader.impl.helpers.HostsHelper Maven / Gradle / Ivy

There is a newer version: 1.5.1
Show newest version
package com.tngtech.propertyloader.impl.helpers;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class HostsHelper {

    public List getLocalHostNames() {
        Set hostSet = new HashSet();

        for (InetAddress host : getLocalHosts()) {
            hostSet.add(host.getHostName());
        }

        List hostNames = new ArrayList(hostSet);
        Collections.sort(hostNames);

        return hostNames;
    }

    private InetAddress[] getLocalHosts() {
        InetAddress in;

        try {
            in = InetAddress.getLocalHost();
        } catch (UnknownHostException uE) {
            return new InetAddress[0];
        }

        try {
            return InetAddress.getAllByName(in.getHostName());
        } catch (UnknownHostException uE) {
            return new InetAddress[]{in};
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy