Package org.fife.rsta.ac
Class IOUtil
- java.lang.Object
-
- org.fife.rsta.ac.IOUtil
-
public final class IOUtil extends java.lang.ObjectI/O related utility methods. We should think of a better location for these methods.- Version:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.String,java.lang.String>defaultEnv
-
Constructor Summary
Constructors Modifier Constructor Description privateIOUtil()Private constructor to prevent instantiation.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.util.Map<java.lang.String,java.lang.String>getDefaultEnvMap()Gets the environment of the current process.static java.lang.String[]getEnvironmentSafely(java.lang.String[] toAdd)Returns the environment of the current process, with some variables possibly added/overwritten.static java.lang.StringgetEnvSafely(java.lang.String var)Returns the value of an environment variable.static voidmain(java.lang.String[] args)Utility testing method.static intwaitForProcess(java.lang.Process p, java.lang.StringBuilder stdout, java.lang.StringBuilder stderr)Runs a process, possibly capturing its stdout and/or stderr.
-
-
-
Method Detail
-
getDefaultEnvMap
private static java.util.Map<java.lang.String,java.lang.String> getDefaultEnvMap()
Gets the environment of the current process.- Returns:
- A mapping of environment variable names to values.
-
getEnvSafely
public static java.lang.String getEnvSafely(java.lang.String var)
Returns the value of an environment variable. This method is here so we don't get an exception when calling System.getenv() in Java 1.4 (which we support).- Parameters:
var- The environment variable.- Returns:
- The value of the variable, or
nullif it is not defined.
-
getEnvironmentSafely
public static java.lang.String[] getEnvironmentSafely(java.lang.String[] toAdd)
Returns the environment of the current process, with some variables possibly added/overwritten. This method works even with Java 1.4.- Parameters:
toAdd- The environment variables to add/overwrite in the returned array. This array should have an even length, with even indices containing variable names and odd indices containing the variable values.- Returns:
- The environment variables. This array's entries will be of the
form "
name=value", so it can be passed directly intoRuntime.exec().
-
waitForProcess
public static int waitForProcess(java.lang.Process p, java.lang.StringBuilder stdout, java.lang.StringBuilder stderr) throws java.io.IOExceptionRuns a process, possibly capturing its stdout and/or stderr.- Parameters:
p- The process.stdout- A buffer in which to put stdout, ornullif you don't want to keep it.stderr- A buffer in which to keep stderr, ornullif you don't want to keep it.- Returns:
- The return code of the process.
- Throws:
java.io.IOException- If an IO error occurs.
-
main
public static void main(java.lang.String[] args)
Utility testing method.- Parameters:
args- Command line arguments.
-
-