dk.netarkivet.common.utils
Class SystemUtils

java.lang.Object
  extended by dk.netarkivet.common.utils.SystemUtils

public class SystemUtils
extends java.lang.Object

Miscellanous utilities for getting system resources.


Field Summary
static java.lang.String LOCALHOST
          Hostname for this machine used when no name can be found, or when the actual name doesn't matter.
 
Constructor Summary
SystemUtils()
           
 
Method Summary
static void checkPortNotUsed(int port)
          Check that a given port is not in use.
static java.util.List<java.lang.String> getCurrentClasspath()
          Get the current class path entries.
static java.lang.String getLocalHostName()
          Get the first hostname available for this machine, or "localhost" if none are available.
static java.lang.String getLocalIP()
          Looks up the IP number of the local host.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALHOST

public static final java.lang.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 java.lang.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 java.lang.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 java.util.List<java.lang.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.