public final class AddressUtils extends Object
NetUtil.createByteArrayFromIpAddressString(java.lang.String)
utility method and the
InetSocketAddress instances will be 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 |
parseAddress(String address,
int defaultPort,
boolean strict)
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(Supplier<? extends SocketAddress> address,
String host)
Update the provided address with the new host string.
|
static SocketAddress |
updatePort(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 portInetSocketAddress
for given parameters, only numeric IP addresses will be resolvedpublic static InetSocketAddress parseAddress(String address, int defaultPort, boolean strict)
address
- ip-address or hostnamedefaultPort
- is used if the address does not contain a port,
or if the port cannot be parsed in non-strict modestrict
- if true throws an exception when the address cannot be parsed,
otherwise an unresolved InetSocketAddress
is returned. It can include the case of the host
having been parsed but not the port (replaced by defaultPort
)InetSocketAddress
for given parameters, only numeric IP addresses will be resolvedpublic 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 Supplier<? extends SocketAddress> address, String host)
address
- the address supplierhost
- the new host stringpublic static SocketAddress updatePort(@Nullable Supplier<? extends SocketAddress> address, int port)
address
- the address supplierport
- the new port