Class NetUtil


  • public final class NetUtil
    extends Object
    A class that holds a number of network-related constants.

    This class borrowed some of its methods from a modified fork of the Inet6Util class which was part of Apache Harmony.

    • Method Detail

      • createByteArrayFromIpAddressString

        public static byte[] createByteArrayFromIpAddressString​(String ipAddressString)
        Creates an byte[] based on an ipAddressString. No error handling is performed here.
      • isValidIpV6Address

        public static boolean isValidIpV6Address​(String ipAddress)
      • isValidIp4Word

        public static boolean isValidIp4Word​(String word)
      • isValidIpV4Address

        public static boolean isValidIpV4Address​(String value)
        Takes a string and parses it to see if it is a valid IPV4 address.
        Returns:
        true, if the string represents an IPV4 address in dotted notation, false otherwise
      • getByName

        public static Inet6Address getByName​(CharSequence ip,
                                             boolean ipv4Mapped)
        Returns the Inet6Address representation of a CharSequence IP address.

        The ipv4Mapped parameter specifies how IPv4 addresses should be treated. "IPv4 mapped" format as defined in rfc 4291 section 2 is supported.

        Parameters:
        ip - CharSequence IP address to be converted to a Inet6Address
        ipv4Mapped -
        • true To allow IPv4 mapped inputs to be translated into Inet6Address
        • false Don't turn IPv4 addressed to mapped addresses
        Returns:
        Inet6Address representation of the ip or null if not a valid IP address.
      • toAddressString

        public static String toAddressString​(InetAddress ip,
                                             boolean ipv4Mapped)
        Returns the String representation of an InetAddress.

        The output does not include Scope ID.

        Parameters:
        ip - InetAddress to be converted to an address string
        ipv4Mapped -
        • true to stray from strict rfc 5952 and support the "IPv4 mapped" format defined in rfc 4291 section 2 while still following the updated guidelines in rfc 5952 section 4
        • false to strictly follow rfc 5952
        Returns:
        String containing the text-formatted IP address