Class SystemUtil


  • public final class SystemUtil
    extends java.lang.Object
    This file is a helper class for internal usage only. Be aware that its API and functionality may be changed in future.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String SPLIT_REGEX  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private SystemUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long getFreeMemory()
      Gets free available memory for JDK.
      (package private) static java.lang.String getProcessOutput​(java.lang.Process p)  
      static java.lang.String getPropertyOrEnvironmentVariable​(java.lang.String name)
      Gets either java property or environment variable with given name.
      static long getRelativeTimeMillis()
      Should be used in relative constructs (for example to check how many milliseconds have passed).
      static int getTimeBasedIntSeed()
      Gets seed as int value of current time in milliseconds.
      static long getTimeBasedSeed()
      Gets seed as long value of current time in milliseconds.
      (package private) static java.util.List<java.lang.String> prepareProcessArguments​(java.lang.String exec, java.lang.String params)  
      (package private) static java.lang.StringBuilder printProcessErrorsOutput​(java.lang.Process p)  
      private static java.lang.StringBuilder printProcessOutput​(java.io.InputStream processStream)  
      (package private) static java.lang.StringBuilder printProcessStandardOutput​(java.lang.Process p)  
      (package private) static java.lang.Process runProcess​(java.lang.String execPath, java.lang.String params, java.lang.String workingDirPath)  
      static java.lang.StringBuilder runProcessAndCollectErrors​(java.lang.String execPath, java.lang.String params)
      Executes the specified command and arguments in a separate process with the specified environment and working directory and returns output errors as a string.
      static int runProcessAndGetExitCode​(java.lang.String exec, java.lang.String params)
      Executes the specified command and arguments in a separate process with the specified environment and working directory.
      static int runProcessAndGetExitCode​(java.lang.String exec, java.lang.String params, java.lang.String workingDirPath)
      Executes the specified command and arguments in a separate process with the specified environment and working directory.
      static java.lang.String runProcessAndGetOutput​(java.lang.String command, java.lang.String params)
      Executes the specified command and arguments in a separate process with the specified environment and working directory and returns output as a string.
      static ProcessInfo runProcessAndGetProcessInfo​(java.lang.String command, java.lang.String params)
      Executes the specified command and arguments in a separate process with the specified environment and working directory and returns process info.
      static boolean runProcessAndWait​(java.lang.String exec, java.lang.String params)
      Executes the specified command and arguments in a separate process with the specified environment and working directory.
      static boolean runProcessAndWait​(java.lang.String exec, java.lang.String params, java.lang.String workingDirPath)
      Executes the specified command and arguments in a separate process with the specified environment and working directory.
      (package private) static java.util.List<java.lang.String> splitIntoProcessArguments​(java.lang.String line)  
      • Methods inherited from class java.lang.Object

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

      • SystemUtil

        private SystemUtil()
    • Method Detail

      • getTimeBasedSeed

        public static long getTimeBasedSeed()
        Gets seed as long value of current time in milliseconds.
        Returns:
        current time in millis as long.
      • getTimeBasedIntSeed

        public static int getTimeBasedIntSeed()
        Gets seed as int value of current time in milliseconds.
        Returns:
        current time in millis as int.
      • getRelativeTimeMillis

        public static long getRelativeTimeMillis()
        Should be used in relative constructs (for example to check how many milliseconds have passed).

        Shouldn't be used in the Date creation since the value returned by this method is different in ะก#. For getting current time consistently use DateTimeUtil.getCurrentTimeDate().

        Returns:
        relative time in milliseconds.
      • getFreeMemory

        public static long getFreeMemory()
        Gets free available memory for JDK.
        Returns:
        available memory in bytes.
      • getPropertyOrEnvironmentVariable

        public static java.lang.String getPropertyOrEnvironmentVariable​(java.lang.String name)
        Gets either java property or environment variable with given name.
        Parameters:
        name - the name of either java property or environment variable.
        Returns:
        property or variable value or null if there is no such.
      • runProcessAndWait

        public static boolean runProcessAndWait​(java.lang.String exec,
                                                java.lang.String params)
                                         throws java.io.IOException,
                                                java.lang.InterruptedException
        Executes the specified command and arguments in a separate process with the specified environment and working directory. This method checks that exec is a valid operating system command. Which commands are valid is system-dependent, but at the very least the command must be a non-empty and non-null. The subprocess inherits the environment settings of the current process. A minimal set of system dependent environment variables may be required to start a process on some operating systems. The working directory of the new subprocess is the current working directory of the current process.
        Parameters:
        exec - a specified system command.
        params - a parameters for the specifed system command.
        Returns:
        true if subprocess was successfully executed, false otherwise.
        Throws:
        java.io.IOException - if any I/O error occurs.
        java.lang.InterruptedException - if process was interrupted.
      • runProcessAndWait

        public static boolean runProcessAndWait​(java.lang.String exec,
                                                java.lang.String params,
                                                java.lang.String workingDirPath)
                                         throws java.io.IOException,
                                                java.lang.InterruptedException
        Executes the specified command and arguments in a separate process with the specified environment and working directory. This method checks that exec is a valid operating system command. Which commands are valid is system-dependent, but at the very least the command must be a non-empty and non-null. The subprocess inherits the environment settings of the current process. A minimal set of system dependent environment variables may be required to start a process on some operating systems. The working directory of the new subprocess is specified by workingDirPath. If dir is null, the subprocess inherits the current working directory of the current process.
        Parameters:
        exec - a specified system command.
        params - a parameters for the specifed system command.
        workingDirPath - working dir for subprocess.
        Returns:
        true if subprocess was successfully executed, false otherwise.
        Throws:
        java.io.IOException - if any I/O error occurs.
        java.lang.InterruptedException - if process was interrupted.
      • runProcessAndGetExitCode

        public static int runProcessAndGetExitCode​(java.lang.String exec,
                                                   java.lang.String params)
                                            throws java.io.IOException,
                                                   java.lang.InterruptedException
        Executes the specified command and arguments in a separate process with the specified environment and working directory. This method checks that exec is a valid operating system command. Which commands are valid is system-dependent, but at the very least the command must be a non-empty and non-null. The subprocess inherits the environment settings of the current process. A minimal set of system dependent environment variables may be required to start a process on some operating systems. The working directory of the new subprocess is the current working directory of the current process.
        Parameters:
        exec - a specified system command.
        params - a parameters for the specifed system command.
        Returns:
        exit code.
        Throws:
        java.io.IOException - if any I/O error occurs.
        java.lang.InterruptedException - if process was interrupted.
      • runProcessAndGetExitCode

        public static int runProcessAndGetExitCode​(java.lang.String exec,
                                                   java.lang.String params,
                                                   java.lang.String workingDirPath)
                                            throws java.io.IOException,
                                                   java.lang.InterruptedException
        Executes the specified command and arguments in a separate process with the specified environment and working directory. This method checks that exec is a valid operating system command. Which commands are valid is system-dependent, but at the very least the command must be a non-empty and non-null. The subprocess inherits the environment settings of the current process. A minimal set of system dependent environment variables may be required to start a process on some operating systems. The working directory of the new subprocess is specified by workingDirPath. If dir is null, the subprocess inherits the current working directory of the current process.
        Parameters:
        exec - a specified system command.
        params - a parameters for the specifed system command.
        workingDirPath - working dir for subprocess.
        Returns:
        exit code.
        Throws:
        java.io.IOException - if any I/O error occurs.
        java.lang.InterruptedException - if process was interrupted.
      • runProcessAndGetOutput

        public static java.lang.String runProcessAndGetOutput​(java.lang.String command,
                                                              java.lang.String params)
                                                       throws java.io.IOException
        Executes the specified command and arguments in a separate process with the specified environment and working directory and returns output as a string. This method checks that exec is a valid operating system command. Which commands are valid is system-dependent, but at the very least the command must be a non-empty and non-null. The subprocess inherits the environment settings of the current process. A minimal set of system dependent environment variables may be required to start a process on some operating systems. The working directory of the new subprocess is specified by workingDirPath. If dir is null, the subprocess inherits the current working directory of the current process.
        Parameters:
        command - a specified system command.
        params - a parameters for the specifed system command.
        Returns:
        subprocess output result.
        Throws:
        java.io.IOException - if any I/O error occurs.
      • runProcessAndCollectErrors

        public static java.lang.StringBuilder runProcessAndCollectErrors​(java.lang.String execPath,
                                                                         java.lang.String params)
                                                                  throws java.io.IOException
        Executes the specified command and arguments in a separate process with the specified environment and working directory and returns output errors as a string. This method checks that exec is a valid operating system command. Which commands are valid is system-dependent, but at the very least the command must be a non-empty and non-null. The subprocess inherits the environment settings of the current process. A minimal set of system dependent environment variables may be required to start a process on some operating systems. The working directory of the new subprocess is specified by workingDirPath. If dir is null, the subprocess inherits the current working directory of the current process.
        Parameters:
        execPath - a specified system command.
        params - a parameters for the specifed system command.
        Returns:
        subprocess errors as StringBuilder.
        Throws:
        java.io.IOException - if any I/O error occurs.
      • runProcessAndGetProcessInfo

        public static ProcessInfo runProcessAndGetProcessInfo​(java.lang.String command,
                                                              java.lang.String params)
                                                       throws java.io.IOException,
                                                              java.lang.InterruptedException
        Executes the specified command and arguments in a separate process with the specified environment and working directory and returns process info. This method checks that exec is a valid operating system command. Which commands are valid is system-dependent, but at the very least the command must be a non-empty and non-null. The subprocess inherits the environment settings of the current process. A minimal set of system dependent environment variables may be required to start a process on some operating systems. The working directory of the new subprocess is specified by workingDirPath. If dir is null, the subprocess inherits the current working directory of the current process.
        Parameters:
        command - a specified system command.
        params - a parameters for the specifed system command.
        Returns:
        process info instance.
        Throws:
        java.io.IOException - if any I/O error occurs.
        java.lang.InterruptedException - if process was interrupted.
      • runProcess

        static java.lang.Process runProcess​(java.lang.String execPath,
                                            java.lang.String params,
                                            java.lang.String workingDirPath)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • prepareProcessArguments

        static java.util.List<java.lang.String> prepareProcessArguments​(java.lang.String exec,
                                                                        java.lang.String params)
      • splitIntoProcessArguments

        static java.util.List<java.lang.String> splitIntoProcessArguments​(java.lang.String line)
      • getProcessOutput

        static java.lang.String getProcessOutput​(java.lang.Process p)
                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • printProcessErrorsOutput

        static java.lang.StringBuilder printProcessErrorsOutput​(java.lang.Process p)
                                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • printProcessStandardOutput

        static java.lang.StringBuilder printProcessStandardOutput​(java.lang.Process p)
                                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • printProcessOutput

        private static java.lang.StringBuilder printProcessOutput​(java.io.InputStream processStream)
                                                           throws java.io.IOException
        Throws:
        java.io.IOException