com.tngtech.propertyloader.impl.helpers.HostsHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of property-loader Show documentation
Show all versions of property-loader Show documentation
The property loader is a java library for managing property configurations.
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};
}
}
}