Class NetUtils


  • public final class NetUtils
    extends java.lang.Object
    Networking-related convenience methods.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private NetUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getLocalHostname()
      This method gets the network name of the machine we are running on.
      static byte[] getMacAddress()
      Returns the local network interface's MAC address if possible.
      static java.lang.String getMacAddressString()
      Returns the mac address, if it is available, as a string with each byte separated by a ":" character.
      private static boolean isUpAndNotLoopback​(java.net.NetworkInterface ni)  
      static java.net.URI toURI​(java.lang.String path)
      Converts a URI string or file path to a URI object.
      • Methods inherited from class java.lang.Object

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

      • LOGGER

        private static final Logger LOGGER
      • UNKNOWN_LOCALHOST

        private static final java.lang.String UNKNOWN_LOCALHOST
        See Also:
        Constant Field Values
    • Constructor Detail

      • NetUtils

        private NetUtils()
    • Method Detail

      • getLocalHostname

        public static java.lang.String getLocalHostname()
        This method gets the network name of the machine we are running on. Returns "UNKNOWN_LOCALHOST" in the unlikely case where the host name cannot be found.
        Returns:
        String the name of the local host
      • getMacAddress

        public static byte[] getMacAddress()
        Returns the local network interface's MAC address if possible. The local network interface is defined here as the NetworkInterface that is both up and not a loopback interface.
        Returns:
        the MAC address of the local network interface or null if no MAC address could be determined.
      • getMacAddressString

        public static java.lang.String getMacAddressString()
        Returns the mac address, if it is available, as a string with each byte separated by a ":" character.
        Returns:
        the mac address String or null.
      • isUpAndNotLoopback

        private static boolean isUpAndNotLoopback​(java.net.NetworkInterface ni)
                                           throws java.net.SocketException
        Throws:
        java.net.SocketException
      • toURI

        public static java.net.URI toURI​(java.lang.String path)
        Converts a URI string or file path to a URI object.
        Parameters:
        path - the URI string or path
        Returns:
        the URI object