public class NetUtils extends Object
| Constructor and Description | 
|---|
NetUtils()  | 
| Modifier and Type | Method and Description | 
|---|---|
static int | 
getAvailablePort()
Find a non-occupied port. 
 | 
static URL | 
getCorrectHostnamePort(String hostPort)
Method to validate if the given String represents a hostname:port. 
 | 
static String | 
getHostnameFromFQDN(String fqdn)
Turn a fully qualified domain name (fqdn) into a hostname. 
 | 
static String | 
hostAndPortToUrlString(String host,
                      int port)
Normalizes and encodes a hostname and port to be included in URL. 
 | 
static String | 
ipAddressAndPortToUrlString(InetAddress address,
                           int port)
Encodes an IP address and port to be included in URL. 
 | 
static String | 
ipAddressToUrlString(InetAddress address)
Encodes an IP address properly as a URL string. 
 | 
static String | 
socketAddressToUrlString(InetSocketAddress address)
Encodes an IP address and port to be included in URL. 
 | 
public static String getHostnameFromFQDN(String fqdn)
fqdn - The fully qualified domain name.public static URL getCorrectHostnamePort(String hostPort)
public static int getAvailablePort()
public static String ipAddressToUrlString(InetAddress address)
This method internally uses Guava's functionality to properly encode IPv6 addresses.
address - The IP address to encode.public static String ipAddressAndPortToUrlString(InetAddress address, int port)
address - The address to be included in the URL.port - The port for the URL address.public static String socketAddressToUrlString(InetSocketAddress address)
address - The socket address with the IP address and port.public static String hostAndPortToUrlString(String host, int port) throws UnknownHostException
host - The address to be included in the URL.port - The port for the URL address.UnknownHostException - Thrown, if the hostname cannot be translated into a URL.Copyright © 2014–2016 The Apache Software Foundation. All rights reserved.