Java Host Name Get getFullyQualifiedDomainName(String unqualifiedHostname)

Here you can find the source of getFullyQualifiedDomainName(String unqualifiedHostname)

Description

Converts a hostname into a canonical hostname.

License

Open Source License

Parameter

Parameter Description
unqualifiedHostname hostname to be fully qualified

Return

canonical hostname that can be compared with DataNode.getHostname()

Declaration

static String getFullyQualifiedDomainName(String unqualifiedHostname) 

Method Source Code


//package com.java2s;
/*// w  ww.j a  va  2 s.  com
 * Copyright 2017 LinkedIn Corp. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 */

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Main {
    /**
     * Converts a hostname into a canonical hostname.
     *
     * @param unqualifiedHostname hostname to be fully qualified
     * @return canonical hostname that can be compared with DataNode.getHostname()
     */
    static String getFullyQualifiedDomainName(String unqualifiedHostname) {
        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) {
            throw new IllegalStateException("Host (" + unqualifiedHostname
                    + ") is unknown so cannot determine fully qualified domain name.");
        }
    }
}

Related

  1. getCasServerHostName()
  2. getCurrentHost()
  3. getDefaultHostName()
  4. getFile(String host, String savePath)
  5. getFullHostname()
  6. getFullyQualifiedHostName()
  7. getHost()
  8. getHost()
  9. getHost(String host)