@Internal public class NetUtils extends Object
| Modifier and Type | Class and Description | 
|---|---|
| static interface  | NetUtils.SocketFactory | 
| Constructor and Description | 
|---|
| NetUtils() | 
| Modifier and Type | Method and Description | 
|---|---|
| static ServerSocket | createSocketFromPorts(Iterator<Integer> portsIterator,
                     NetUtils.SocketFactory factory)Tries to allocate a socket from the given sets of ports. | 
| 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 Iterator<Integer> | getPortRangeFromString(String rangeDefinition)Returns an iterator over available ports defined by the range definition. | 
| 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.public static Iterator<Integer> getPortRangeFromString(String rangeDefinition) throws NumberFormatException
rangeDefinition - String describing a single port, a range of ports or multiple ranges.NumberFormatException - If an invalid string is passed.public static ServerSocket createSocketFromPorts(Iterator<Integer> portsIterator, NetUtils.SocketFactory factory) throws IOException
portsIterator - A set of ports to choose from.factory - A factory for creating the SocketServerIOExceptionCopyright © 2014–2016 The Apache Software Foundation. All rights reserved.