Class SystemUtils


  • public class SystemUtils
    extends Object
    Miscellanous utilities for getting system resources.
    • Field Detail

      • LOCALHOST

        public static final String LOCALHOST
        Hostname for this machine used when no name can be found, or when the actual name doesn't matter.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SystemUtils

        public SystemUtils()
    • Method Detail

      • getLocalIP

        public static String getLocalIP()
        Looks up the IP number of the local host. Note that Java does not guarantee that the result is IPv4 or IPv6.
        Returns:
        the found IP; returns "UNKNOWNIP" if it could not be found.
      • getLocalHostName

        public static String getLocalHostName()
        Get the first hostname available for this machine, or "localhost" if none are available.
        Returns:
        A hostname, as returned by InetAddress.getLocalHost().getCanonicalHostName()()
      • checkPortNotUsed

        public static void checkPortNotUsed​(int port)
        Check that a given port is not in use. If this method returns normally, the port is safe to bind.
        Parameters:
        port - Port to check
        Throws:
        IOFailure - if the port cannot be bound.
      • getCurrentClasspath

        public static List<String> getCurrentClasspath()
        Get the current class path entries. Note that this does not work if we've been invoked with java -jar, as that option silently ignores classpaths.
        Returns:
        List of directories/jar files in the current class path.