Java Utililty Methods Host Name Get

List of utility methods to do Host Name Get

Description

The list of methods to do Host Name Get are organized into topic(s).

Method

StringgetFile(String host, String savePath)
Get a file from a host uri, and save it into the save path
InputStream input = null;
FileOutputStream writeFile = null;
String path = new String();
try {
    URL url = new URL(host);
    URLConnection connection = url.openConnection();
    int fileLength = connection.getContentLength();
    if (fileLength == -1) {
...
StringgetFullHostname()
get Full Hostname
String hostname = "unknown";
try {
    final InetAddress host = InetAddress.getLocalHost();
    hostname = host.getHostName();
} catch (Exception ignore) {
return hostname;
StringgetFullyQualifiedDomainName(String unqualifiedHostname)
Converts a hostname into a canonical hostname.
if (unqualifiedHostname == null) {
    throw new IllegalStateException("Hostname cannot be null.");
} else if (unqualifiedHostname.length() == 0) {
    throw new IllegalStateException("Hostname cannot be zero length.");
try {
    return InetAddress.getByName(unqualifiedHostname).getCanonicalHostName().toLowerCase();
} catch (UnknownHostException e) {
...
StringgetFullyQualifiedHostName()
get Fully Qualified Host Name
String localhost = null;
try {
    localhost = InetAddress.getLocalHost().getCanonicalHostName().toLowerCase();
} catch (UnknownHostException e) {
    e.printStackTrace();
    localhost = "Unknown Host";
return localhost;
...
StringgetHost()
Gets the hostname of the machine running the code, foregoing the need for exception handling in-line when this information is needed.
String host = "unknown";
try {
    host = InetAddress.getLocalHost().getHostName();
} catch (final UnknownHostException ex) {
    ex.printStackTrace();
return host;
StringgetHost()
get Host
try {
    Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
    while (interfaces.hasMoreElements()) {
        NetworkInterface current = interfaces.nextElement();
        if (!current.isUp() || current.isLoopback() || current.isVirtual())
            continue;
        if (current.getName().contains("lxc"))
            continue; 
...
StringgetHost(String host)
Returns the host address, if the supplied host is localhost, else returns it, unchanged.
if (host.equals("localhost")) {
    try {
        host = InetAddress.getLocalHost().getHostAddress();
    } catch (UnknownHostException ignore) {
return host;
StringgetHost(String link)
get Host
URL url;
String host = "";
try {
    url = new URL(link);
    host = url.getHost();
} catch (MalformedURLException e) {
return host;
...
StringgetHost(String s)
get Host
if (s == null) {
    return null;
try {
    InetAddress address = InetAddress.getByName(s);
    return address.getHostName();
} catch (UnknownHostException ex) {
    System.out.println("Could not find server hostname " + s);
...
StringgetHostCore(final String quadGraph)
This method should be used over others because it -safely- and accurately trims the host name by 1.
final String[] graphurisplit = quadGraph.split("\\.");
StringBuilder host = new StringBuilder();
try {
    Integer.valueOf(graphurisplit[graphurisplit.length - 1]);
    host.append(quadGraph);
} catch (NumberFormatException e) {
    for (int i = Math.min(1, Math.max(graphurisplit.length - 2, 0)); i < graphurisplit.length; i++) {
        host.append(graphurisplit[i] + ".");
...