Here you can find the source of resolveHostName(String hostname)
Parameter | Description |
---|---|
hostname | the input hostname, which could be an alias |
Parameter | Description |
---|---|
UnknownHostException | if the given hostname cannot be resolved |
public static String resolveHostName(String hostname) throws UnknownHostException
//package com.java2s; /*// w w w . ja v a 2 s .c om * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 * (the ?License??). You may not use this work except in compliance with the License, which is * available at www.apache.org/licenses/LICENSE-2.0 * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied, as more fully set forth in the License. * * See the NOTICE file distributed with this work for information regarding copyright ownership. */ import java.net.InetAddress; import java.net.UnknownHostException; public class Main { /** * Resolves a given hostname by a canonical hostname. When a hostname alias (e.g., those specified * in /etc/hosts) is given, the alias may not be resolvable on other hosts in a cluster unless the * same alias is defined there. In this situation, loadufs would break. * * @param hostname the input hostname, which could be an alias * @return the canonical form of the hostname, or null if it is null or empty * @throws UnknownHostException if the given hostname cannot be resolved */ public static String resolveHostName(String hostname) throws UnknownHostException { if (hostname == null || hostname.isEmpty()) { return null; } return InetAddress.getByName(hostname).getCanonicalHostName(); } }