Class SystemUtil

java.lang.Object
com.itextpdf.commons.utils.SystemUtil

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

    • 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 String getPropertyOrEnvironmentVariable (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 (String exec, String params) throws IOException, 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:
      IOException - if any I/O error occurs.
      InterruptedException - if process was interrupted.
    • runProcessAndWait

      public static boolean runProcessAndWait (String exec, String params, String workingDirPath) throws IOException, 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:
      IOException - if any I/O error occurs.
      InterruptedException - if process was interrupted.
    • runProcessAndGetExitCode

      public static int runProcessAndGetExitCode (String exec, String params) throws IOException, 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:
      IOException - if any I/O error occurs.
      InterruptedException - if process was interrupted.
    • runProcessAndGetExitCode

      public static int runProcessAndGetExitCode (String exec, String params, String workingDirPath) throws IOException, 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:
      IOException - if any I/O error occurs.
      InterruptedException - if process was interrupted.
    • runProcessAndGetOutput

      public static String runProcessAndGetOutput (String command, String params) throws 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:
      IOException - if any I/O error occurs.
    • runProcessAndCollectErrors

      public static StringBuilder runProcessAndCollectErrors (String execPath, String params) throws 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:
      IOException - if any I/O error occurs.
    • runProcessAndGetProcessInfo

      public static ProcessInfo runProcessAndGetProcessInfo (String command, String params) throws IOException, 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:
      IOException - if any I/O error occurs.
      InterruptedException - if process was interrupted.