public final class AddressUtils extends Object
NetUtil.createByteArrayFromIpAddressString(java.lang.String) utility method and the
InetSocketAddress instances will created in a way that these instances are resolved
initially. This removes the need to do unnecessary reverse DNS lookups.| Modifier and Type | Method and Description |
|---|---|
static InetSocketAddress |
createInetSocketAddress(String hostname,
int port,
boolean resolve)
Creates InetSocketAddress instance.
|
static InetSocketAddress |
createResolved(String hostname,
int port)
Creates InetSocketAddress that is always resolved.
|
static InetSocketAddress |
createUnresolved(String hostname,
int port)
Creates unresolved InetSocketAddress.
|
static InetSocketAddress |
parseAddress(String address,
int defaultPort)
Parse unresolved InetSocketAddress.
|
static InetSocketAddress |
replaceUnresolvedNumericIp(InetSocketAddress inetSocketAddress)
Replaces an unresolved InetSocketAddress with a resolved instance in the case that
the passed address is a numeric IP address (both IPv4 and IPv6 are supported).
|
static InetSocketAddress |
replaceWithResolved(InetSocketAddress inetSocketAddress)
Replaces an unresolved InetSocketAddress with a resolved instance in the case that
the passed address is unresolved.
|
static SocketAddress |
updateHost(java.util.function.Supplier<? extends SocketAddress> address,
String host)
Update the provided address with the new host string.
|
static SocketAddress |
updatePort(java.util.function.Supplier<? extends SocketAddress> address,
int port)
Update the provided address with the new port.
|
public static InetSocketAddress createInetSocketAddress(String hostname, int port, boolean resolve)
hostname - ip-address or hostnameport - port numberresolve - when true, resolve given hostname at instance creation timepublic static InetSocketAddress createResolved(String hostname, int port)
hostname - ip-address or hostnameport - port numberpublic static InetSocketAddress createUnresolved(String hostname, int port)
hostname - ip-address or hostnameport - port numberpublic static InetSocketAddress parseAddress(String address, int defaultPort)
address - ip-address or hostnamedefaultPort - the default portpublic static InetSocketAddress replaceUnresolvedNumericIp(InetSocketAddress inetSocketAddress)
inetSocketAddress - socket address instance to processpublic static InetSocketAddress replaceWithResolved(InetSocketAddress inetSocketAddress)
inetSocketAddress - socket address instance to processpublic static SocketAddress updateHost(@Nullable java.util.function.Supplier<? extends SocketAddress> address, String host)
address - the address supplierhost - the new host stringpublic static SocketAddress updatePort(@Nullable java.util.function.Supplier<? extends SocketAddress> address, int port)
address - the address supplierport - the new port