Module xaos.core

Class SystemUtils


  • public class SystemUtils
    extends Object
    Some system utilities.
    Author:
    claudio.rosati@esss.se
    • Method Detail

      • build

        public static ProcessBuilder build​(String module,
                                           Class<?> clazz,
                                           List<String> jvmArgs,
                                           List<String> args)
        Creates a ProcessBuilder ready to execute the given class (that needs to have a main method) as a detached sub-process. Current module-path will be used to find the given module and class and its dependencies.
        Parameters:
        module - The name of the module containing the class to be executed.
        clazz - The class to be executed.
        jvmArgs - The JVM arguments.
        args - The class arguments.
        Returns:
        The ProcessBuilder ready to run the given class.
      • execute

        public static String execute​(String... command)
        Execute the given command and return its output as a string.
        Parameters:
        command - The command (and parameters) to be executed.
        Returns:
        The output from the executed process.
      • execute

        public static String execute​(File workingDirectory,
                                     String... command)
        Execute the given command and return its output as a string.
        Parameters:
        workingDirectory - The directory where the execution must be performed. Can be null to inherit the working directory from the current process.
        command - The command (and parameters) to be executed.
        Returns:
        The output from the executed process, or null if an exception was thrown (and logged).
      • execute

        public static int execute​(Class<?> clazz,
                                  List<String> jvmArgs,
                                  List<String> args)
                           throws IOException,
                                  InterruptedException
        Executes the given class (that needs to have a main method) as a detached sub-process, returning its exit value. Current class-path will be used to find the given class and its dependencies. Standard input and output will be the same of the calling application.
        Parameters:
        clazz - The class to be executed.
        jvmArgs - The JVM arguments.
        args - The class arguments.
        Returns:
        The class execution exist status.
        Throws:
        IOException - If an I/O error occurs.
        InterruptedException - If the execution is interrupted.
        See Also:
        Running a Java Class as a Subprocess
      • execute

        public static int execute​(String module,
                                  Class<?> clazz,
                                  List<String> jvmArgs,
                                  List<String> args)
                           throws IOException,
                                  InterruptedException
        Executes the given class (that needs to have a main method) as a detached sub-process, returning its exit value. Current module-path will be used to find the given module and class and its dependencies. Standard input and output will be the same of the calling application.
        Parameters:
        module - The name of the module containing the class to be executed.
        clazz - The class to be executed.
        jvmArgs - The JVM arguments.
        args - The class arguments.
        Returns:
        The class execution exist status.
        Throws:
        IOException - If an I/O error occurs.
        InterruptedException - If the execution is interrupted.
      • freeDiskSpace

        public static double freeDiskSpace​(File path)
        Returns the percentage of available space to this virtual machine on the partition named by the given abstract pathname.
        Parameters:
        path - A file identifying the partition to be queried.
        Returns:
        The percentage of available space to this virtual machine, as a double in the [0.0, 1.0] range.