Modifier and Type | Class and Description |
---|---|
static interface |
NetUtils.SocketFactory
A factory for a local socket from port number.
|
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 |
getWildcardIPAddress()
Returns the wildcard address to listen on all interfaces.
|
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.
|
static String |
unresolvedHostAndPortToNormalizedString(String host,
int port)
Returns a valid address for Akka.
|
static String |
unresolvedHostToNormalizedString(String host)
Returns an address in a normalized format for Akka.
|
public static String getHostnameFromFQDN(String fqdn)
fqdn
- The fully qualified domain name.public static URL getCorrectHostnamePort(String hostPort)
Works also for ipv6.
See: http://stackoverflow.com/questions/2345063/java-common-way-to-validate-and-convert-hostport-to-inetsocketaddress
public static int getAvailablePort()
public static String unresolvedHostToNormalizedString(String host)
host
- The hostname, IPv4 or IPv6 addresspublic static String unresolvedHostAndPortToNormalizedString(String host, int port)
host
- The hostname, IPv4 or IPv6 addressport
- The portpublic static String ipAddressToUrlString(InetAddress address)
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)
portsIterator
- A set of ports to choose from.factory
- A factory for creating the SocketServerpublic static String getWildcardIPAddress()
Copyright © 2014–2019 The Apache Software Foundation. All rights reserved.