Class AddressUtils

java.lang.Object
reactor.netty.transport.AddressUtils

public final class AddressUtils extends Object
Internal class that creates unresolved or resolved InetSocketAddress instances Numeric IPv4 and IPv6 addresses will be detected and parsed by using Netty's 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.
  • Method Details

    • createInetSocketAddress

      public static InetSocketAddress createInetSocketAddress(String hostname, int port, boolean resolve)
      Creates InetSocketAddress instance. Numeric IP addresses will be detected and resolved without doing reverse DNS lookups.
      Parameters:
      hostname - ip-address or hostname
      port - port number
      resolve - when true, resolve given hostname at instance creation time
      Returns:
      InetSocketAddress for given parameters
    • createResolved

      public static InetSocketAddress createResolved(String hostname, int port)
      Creates InetSocketAddress that is always resolved. Numeric IP addresses will be detected and resolved without doing reverse DNS lookups.
      Parameters:
      hostname - ip-address or hostname
      port - port number
      Returns:
      InetSocketAddress for given parameters
    • createUnresolved

      public static InetSocketAddress createUnresolved(String hostname, int port)
      Creates unresolved InetSocketAddress. Numeric IP addresses will be detected and resolved.
      Parameters:
      hostname - ip-address or hostname
      port - port number
      Returns:
      InetSocketAddress for given parameters
    • parseAddress

      public static InetSocketAddress parseAddress(String address, int defaultPort)
      Parse unresolved InetSocketAddress. Numeric IP addresses will be detected and resolved.
      Parameters:
      address - ip-address or hostname
      defaultPort - the default port
      Returns:
      InetSocketAddress for given parameters, only numeric IP addresses will be resolved
    • parseAddress

      public static InetSocketAddress parseAddress(String address, int defaultPort, boolean strict)
      Parse unresolved InetSocketAddress. Numeric IP addresses will be detected and resolved.
      Parameters:
      address - ip-address or hostname
      defaultPort - is used if the address does not contain a port, or if the port cannot be parsed in non-strict mode
      strict - 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)
      Returns:
      InetSocketAddress for given parameters, only numeric IP addresses will be resolved
    • replaceUnresolvedNumericIp

      public 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).
      Parameters:
      inetSocketAddress - socket address instance to process
      Returns:
      processed socket address instance
    • replaceWithResolved

      public static InetSocketAddress replaceWithResolved(InetSocketAddress inetSocketAddress)
      Replaces an unresolved InetSocketAddress with a resolved instance in the case that the passed address is unresolved.
      Parameters:
      inetSocketAddress - socket address instance to process
      Returns:
      resolved instance with same host string and port
    • updateHost

      public static SocketAddress updateHost(@Nullable Supplier<? extends SocketAddress> address, String host)
      Update the provided address with the new host string.
      Parameters:
      address - the address supplier
      host - the new host string
      Returns:
      the updated address
    • updatePort

      public static SocketAddress updatePort(@Nullable Supplier<? extends SocketAddress> address, int port)
      Update the provided address with the new port.
      Parameters:
      address - the address supplier
      port - the new port
      Returns:
      the updated address