JavaScript is disabled on your browser.
Skip navigation links
io.netty.util

Class NetUtil



  • public final class NetUtil
    extends java.lang.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.

    • Field Summary

      Fields
      Modifier and Type Field and Description
      static java.net.InetAddress LOCALHOST
      The InetAddress that represents the loopback address.
      static java.net.Inet4Address LOCALHOST4
      The Inet4Address that represents the IPv4 loopback address '127.0.0.1'
      static java.net.Inet6Address LOCALHOST6
      The Inet6Address that represents the IPv6 loopback address '::1'
      static java.net.NetworkInterface LOOPBACK_IF
      The loopback NetworkInterface of the current machine
      static int SOMAXCONN
      The SOMAXCONN value of the current machine.
    • Method Summary

      All Methods
      Modifier and Type Method and Description
      static byte[] createByteArrayFromIpAddressString (java.lang.String ipAddressString)
      Creates an byte[] based on an ipAddressString.
      static java.net.Inet6Address getByName (java.lang.CharSequence ip)
      Returns the Inet6Address representation of a CharSequence IP address.
      static java.net.Inet6Address getByName (java.lang.CharSequence ip, boolean ipv4Mapped)
      Returns the Inet6Address representation of a CharSequence IP address.
      static boolean isIpV4StackPreferred ()
      Returns true if ipv4 should be prefered on a system that supports ipv4 and ipv6.
      static boolean isValidIpV4Address (java.lang.String ip)
      Takes a string and parses it to see if it is a valid IPV4 address.
      static boolean isValidIpV6Address (java.lang.String ip)
      static java.lang.String toAddressString (java.net.InetAddress ip)
      Returns the String representation of an InetAddress.
      static java.lang.String toAddressString (java.net.InetAddress ip, boolean ipv4Mapped)
      Returns the String representation of an InetAddress.
      static java.lang.String toSocketAddressString (java.net.InetSocketAddress addr)
      Returns the String representation of an InetSocketAddress.
      static java.lang.String toSocketAddressString (java.lang.String host, int port)
      Returns the String representation of a host port combo.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOCALHOST4

        public static final java.net.Inet4Address LOCALHOST4
        The Inet4Address that represents the IPv4 loopback address '127.0.0.1'
      • LOCALHOST6

        public static final java.net.Inet6Address LOCALHOST6
        The Inet6Address that represents the IPv6 loopback address '::1'
      • LOCALHOST

        public static final java.net.InetAddress LOCALHOST
        The InetAddress that represents the loopback address. If IPv6 stack is available, it will refer to LOCALHOST6. Otherwise, LOCALHOST4.
      • LOOPBACK_IF

        public static final java.net.NetworkInterface LOOPBACK_IF
        The loopback NetworkInterface of the current machine
      • SOMAXCONN

        public static final int SOMAXCONN
        The SOMAXCONN value of the current machine. If failed to get the value, 200 is used as a default value for Windows or 128 for others.
    • Method Detail

      • isIpV4StackPreferred

        public static boolean isIpV4StackPreferred()
        Returns true if ipv4 should be prefered on a system that supports ipv4 and ipv6.
      • createByteArrayFromIpAddressString

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

        public static boolean isValidIpV6Address(java.lang.String ip)
      • isValidIpV4Address

        public static boolean isValidIpV4Address(java.lang.String ip)
        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 java.net.Inet6Address getByName(java.lang.CharSequence ip)
        Returns the Inet6Address representation of a CharSequence IP address.

        This method will treat all IPv4 type addresses as "IPv4 mapped" (see getByName(CharSequence, boolean))

        Parameters:
        ip - CharSequence IP address to be converted to a Inet6Address
        Returns:
        Inet6Address representation of the ip or null if not a valid IP address.
      • getByName

        public static java.net.Inet6Address getByName(java.lang.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 Consider IPv4 mapped addresses as invalid.
        Returns:
        Inet6Address representation of the ip or null if not a valid IP address.
      • toSocketAddressString

        public static java.lang.String toSocketAddressString(java.net.InetSocketAddress addr)
        Returns the String representation of an InetSocketAddress.

        The output does not include Scope ID.

        Parameters:
        addr - InetSocketAddress to be converted to an address string
        Returns:
        String containing the text-formatted IP address
      • toSocketAddressString

        public static java.lang.String toSocketAddressString(java.lang.String host,
         int port)
        Returns the String representation of a host port combo.
      • toAddressString

        public static java.lang.String toAddressString(java.net.InetAddress ip)
        Returns the String representation of an InetAddress.
        • Inet4Address results are identical to InetAddress.getHostAddress()
        • Inet6Address results adhere to rfc 5952 section 4

        The output does not include Scope ID.

        Parameters:
        ip - InetAddress to be converted to an address string
        Returns:
        String containing the text-formatted IP address
      • toAddressString

        public static java.lang.String toAddressString(java.net.InetAddress ip,
         boolean ipv4Mapped)
        Returns the String representation of an InetAddress.
        • Inet4Address results are identical to InetAddress.getHostAddress()
        • Inet6Address results adhere to rfc 5952 section 4 if ipv4Mapped is false. If ipv4Mapped is true then "IPv4 mapped" format from rfc 4291 section 2 will be supported. The compressed result will always obey the compression rules defined in rfc 5952 section 4

        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
Skip navigation links

Copyright © 2008–2018 The Netty Project. All rights reserved.

AltStyle によって変換されたページ (->オリジナル) /