Class Host


  • public abstract class Host
    extends java.lang.Object
    A host component of a URI.

    RFC 3986 specifies four forms of host - registered name, IP version 4 address, IP version 6 address, and a future IP version address. Note that as pointed out in the RFC, there is an overlap between what is considered a valid IP version 4 address, and what is considered a valid registered name - for example, Host.registeredName("127.0.0.1") renders identically in a URI to ipV4Address(octet(127), octet(0), octet(0), octet(1)). In keeping with the RFC, such a registered name is considered to be an equivalent IP version 4 address.

    Immutable and thread safe.

    See Also:
    RFC 3986 - Host
    • Field Detail

      • LOCAL_HOST

        public static final Host LOCAL_HOST
        The registered name "localhost".
      • LOOPBACK_ADDRESS_IP_V4

        public static final Host LOOPBACK_ADDRESS_IP_V4
        The loopback address in IP v4 format, in other words 127.0.0.1
      • LOOPBACK_ADDRESS_IP_V6

        public static final Host LOOPBACK_ADDRESS_IP_V6
        The loopback address in IP v6 format, in other words ::1
      • UNSPECIFIED_ADDRESS_IP_V6

        public static final Host UNSPECIFIED_ADDRESS_IP_V6
    • Method Detail

      • registeredName

        public static Host registeredName​(java.lang.String registeredName)
        Factory method for creating registered name type Hosts.
        Parameters:
        registeredName - any String to represent as a Host.
        Returns:
        a Host representing the given String as a registered name.
      • ipV4Address

        public static Host ipV4Address​(Octet firstOctet,
                                       Octet secondOctet,
                                       Octet thirdOctet,
                                       Octet fourthOctet)
        Factory method for creating IP version 4 type Hosts. IP version 4 Hosts are made up of four Octets.
        Parameters:
        firstOctet - the first octet
        secondOctet - the second octet
        thirdOctet - the third octet
        fourthOctet - the fourth octet
        Returns:
        a Host representing the given Octets as an IP version 4 address.
      • ipV4Address

        public static Host ipV4Address​(int firstOctet,
                                       int secondOctet,
                                       int thirdOctet,
                                       int fourthOctet)
        Factory method for creating IP version 4 type Hosts. IP version 4 Hosts are made up of four Octets, which are created from the given ints.
        Parameters:
        firstOctet - the first octet
        secondOctet - the second octet
        thirdOctet - the third octet
        fourthOctet - the fourth octet
        Returns:
        a Host representing the given ints as an IP version 4 address.
      • ipV6Address

        public static Host ipV6Address​(Hexadectet firstHexadectet,
                                       Hexadectet secondHexadectet,
                                       Hexadectet thirdHexadectet,
                                       Hexadectet fourthHexadectet,
                                       Hexadectet fifthHexadectet,
                                       Hexadectet sixthHexadectet,
                                       Hexadectet seventhHexadectet,
                                       Hexadectet eighthHexadectet)
        Factory method for creating IP version 6 type Hosts with all parts specified as Hexadectets.
        Parameters:
        firstHexadectet - the first hexadectet
        secondHexadectet - the second hexadectet
        thirdHexadectet - the third hexadectet
        fourthHexadectet - the fourth hexadectet
        fifthHexadectet - the fifth hexadectet
        sixthHexadectet - the sixth hexadectet
        seventhHexadectet - the seventh hexadectet
        eighthHexadectet - the eighth hexadectet
        Returns:
        a Host representing the given Hexadectets as an IP version 6 address.
      • ipV6Address

        public static Host ipV6Address​(Hexadectet firstHexadectet,
                                       Hexadectet secondHexadectet,
                                       Hexadectet thirdHexadectet,
                                       Hexadectet fourthHexadectet,
                                       Hexadectet fifthHexadectet,
                                       Hexadectet sixthHexadectet,
                                       Octet firstOctet,
                                       Octet secondOctet,
                                       Octet thirdOctet,
                                       Octet fourthOctet)
        Factory method for creating IP version 6 type Hosts with the least significant 32 bits specified as in IP version 4 address format.
        Parameters:
        firstHexadectet - the first hexadectet
        secondHexadectet - the second hexadectet
        thirdHexadectet - the third hexadectet
        fourthHexadectet - the fourth hexadectet
        fifthHexadectet - the fifth hexadectet
        sixthHexadectet - the sixth hexadectet
        firstOctet - the first octet
        secondOctet - the second octet
        thirdOctet - the third octet
        fourthOctet - the fourth octet
        Returns:
        a Host representing the given Hexadectets and Octets as an IP version 6 address.
      • ipVFutureAddress

        public static Host ipVFutureAddress​(java.lang.String version,
                                            java.lang.String address)
        Factory method for creating IP version future type Hosts.
        Parameters:
        version - a String consisting of at least one character, made up solely of hexadecimal digits, namely 0-9 and A-F.
        address - a String consisting of at least one character, made up solely of characters from the Latin alphabet, the digits, and any of '-', '.', '_' , '~' , '!' , '$' , '&' , ''' , '(' , ')' , '*' , '+' , ',' , ';' , '=' , ':'.
        Returns:
        a Host representing the given Hexadectets and Octets as an IP version 6 address.
        Throws:
        java.lang.IllegalArgumentException - if the given version or address are empty of contain characters outside the valid set.