Class HostPort


  • public class HostPort
    extends java.lang.Object

    Parse an authority string (in the form host:port) into host and port, handling IPv4 and IPv6 host formats as defined in https://www.ietf.org/rfc/rfc2732.txt

    • Constructor Summary

      Constructors 
      Constructor Description
      HostPort​(java.lang.String authority)  
      HostPort​(java.lang.String host, int port)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getHost()
      Get the host.
      int getPort()
      Get the port.
      int getPort​(int defaultPort)
      Get the port or the given default port.
      boolean hasHost()  
      boolean hasPort()  
      static java.lang.String normalizeHost​(java.lang.String host)
      Normalizes IPv6 address as per https://tools.ietf.org/html/rfc2732 and https://tools.ietf.org/html/rfc6874, surrounding with square brackets if they are absent.
      static int parsePort​(java.lang.String rawPort)
      Parse a string representing a port validating it is a valid port value.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • HostPort

        public HostPort​(java.lang.String host,
                        int port)
      • HostPort

        public HostPort​(java.lang.String authority)
                 throws java.lang.IllegalArgumentException
        Throws:
        java.lang.IllegalArgumentException
    • Method Detail

      • getHost

        @ManagedAttribute("host")
        public java.lang.String getHost()
        Get the host.
        Returns:
        the host
      • getPort

        @ManagedAttribute("port")
        public int getPort()
        Get the port.
        Returns:
        the port
      • getPort

        public int getPort​(int defaultPort)
        Get the port or the given default port.
        Parameters:
        defaultPort - , the default port to return if a port is not specified
        Returns:
        the port
      • hasHost

        public boolean hasHost()
      • hasPort

        public boolean hasPort()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • normalizeHost

        public static java.lang.String normalizeHost​(java.lang.String host)
        Normalizes IPv6 address as per https://tools.ietf.org/html/rfc2732 and https://tools.ietf.org/html/rfc6874, surrounding with square brackets if they are absent.
        Parameters:
        host - a host name, IPv4 address, IPv6 address or IPv6 literal
        Returns:
        a host name or an IPv4 address or an IPv6 literal (not an IPv6 address)
      • parsePort

        public static int parsePort​(java.lang.String rawPort)
                             throws java.lang.IllegalArgumentException
        Parse a string representing a port validating it is a valid port value.
        Parameters:
        rawPort - the port string.
        Returns:
        the integer value for the port.
        Throws:
        java.lang.IllegalArgumentException - if the port is invalid