jlibs.core.lang
Class RuntimeUtil

java.lang.Object
  extended by jlibs.core.lang.RuntimeUtil

public class RuntimeUtil
extends Object

The class contains Runtime related utilities

Author:
Santhosh Kumar T

Constructor Summary
RuntimeUtil()
           
 
Method Summary
static void gc()
          This method guarantees that garbage collection is done unlike System.gc()
static void gc(int count)
          calls gc() count times
static void gcOnExit()
          This method guarantees that garbage colleciton is done after JVM shutdown is initialized
static String getPID()
          Returns the PID of the current process.
static void redirectStreams(Process process, OutputStream output, OutputStream error)
          Redirects given process's input and error streams to the specified streams.
static String runCommand(String command)
          Runs the specified command in terminal (sh in *nix/cmd in windows) and returns the command output.
static String runCommand(String command, String[] envp, File workingDir)
          Runs the specified command in terminal (sh in *nix/cmd in windows) and returns the command output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RuntimeUtil

public RuntimeUtil()
Method Detail

redirectStreams

public static void redirectStreams(Process process,
                                   OutputStream output,
                                   OutputStream error)
Redirects given process's input and error streams to the specified streams. the streams specified are not closed automatically. The streams passed can be null, if you don't want to redirect them.

Parameters:
process - process whose streams to be redirected
output - outputStream to which process's inputStream is redirected.
null if you don't want to redirect.
error - outputStream to which process's errorStream is redirected.
null if you don't want to redirect.

runCommand

public static String runCommand(String command,
                                String[] envp,
                                File workingDir)
                         throws IOException
Runs the specified command in terminal (sh in *nix/cmd in windows) and returns the command output.

Parameters:
command - complete command to be executed
envp - array of strings, each element of which has environment variable settings in the format name=value, or null if the subprocess should inherit the environment of the current process.
workingDir - the working directory of the subprocess, or null if the subprocess should inherit the working directory of the current process.
Returns:
output of the command.
Throws:
IOException - If an I/O error occurs
See Also:
runCommand(String)

runCommand

public static String runCommand(String command)
                         throws IOException
Runs the specified command in terminal (sh in *nix/cmd in windows) and returns the command output. The subprocess created inherits environment and working directory from the current process

Parameters:
command - complete command to be executed
Returns:
output of the command.
Throws:
IOException - If an I/O error occurs
See Also:
runCommand(String, String[], java.io.File)

getPID

public static String getPID()
                     throws IOException
Returns the PID of the current process. The PID will also be saved in system property "pid"

Returns:
PID of current progress
Throws:
IOException - If an I/O error occurs

gc

public static void gc()
This method guarantees that garbage collection is done unlike System.gc()


gc

public static void gc(int count)
calls gc() count times


gcOnExit

public static void gcOnExit()
This method guarantees that garbage colleciton is done after JVM shutdown is initialized



Copyright © 2018. All rights reserved.