Class Address


  • public class Address
    extends Object
    A representation of network addresses, i.e. host/port pairs, with some utility functions for parsing address strings.
    • Constructor Detail

      • Address

        public Address​(String host,
                       int port)
        Construct an address from a host name and port number.
        Parameters:
        host - the host name
        port - the port number
      • Address

        public Address​(String host)
        Construct an address from a host.
        Parameters:
        host - the host name
    • Method Detail

      • getHost

        public String getHost()
        Get the host name
        Returns:
        the host name
      • getPort

        public int getPort()
        Get the port number
        Returns:
        the port number
      • parseHost

        public static String parseHost​(String addressString)
        Extracts hostname or IP address from a string containing a hostname, IP address, hostname:port pair or IP address:port pair. Note that IPv6 addresses must be quoted with square brackets, e.g. [2001:db8:85a3:8d3:1319:8a2e:370:7348].
        Parameters:
        addressString - the string to extract hostname from
        Returns:
        the hostname or IP address
      • parsePort

        public static int parsePort​(String addressString)
      • isHostWithPort

        public static boolean isHostWithPort​(String addressString)
      • parseAddress

        public static Address parseAddress​(String addressString)
        Factory method: takes a formatted addressString string as construction parameter
        Parameters:
        addressString - an addressString of the form "host[:port]".
        Returns:
        an Address from the given data
      • parseAddresses

        public static Address[] parseAddresses​(String addresses)
        Array-based factory method: takes an array of formatted address strings as construction parameter
        Parameters:
        addresses - array of strings of form "host[:port],..."
        Returns:
        a list of Address values
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object