Class EnvironmentUtils
- java.lang.Object
-
- org.apache.commons.exec.environment.EnvironmentUtils
-
public class EnvironmentUtils extends java.lang.ObjectWraps environment variables.
-
-
Field Summary
Fields Modifier and Type Field Description private static DefaultProcessingEnvironmentENVIRONMENTDefault environment.
-
Constructor Summary
Constructors Modifier Constructor Description privateEnvironmentUtils()Hides constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddVariableToEnvironment(java.util.Map<java.lang.String,java.lang.String> environment, java.lang.String keyAndValue)Adds a key/value pair to the given environment.static java.util.Map<java.lang.String,java.lang.String>getProcEnvironment()Gets the list of environment variables for this process.private static java.lang.String[]parseEnvironmentVariable(java.lang.String keyAndValue)Parses a key/value pair into a String[].private static java.lang.StringtoString(java.lang.String value)static java.lang.String[]toStrings(java.util.Map<java.lang.String,java.lang.String> environment)Converts a variable map as an array.
-
-
-
Field Detail
-
ENVIRONMENT
private static final DefaultProcessingEnvironment ENVIRONMENT
Default environment.
-
-
Method Detail
-
addVariableToEnvironment
public static void addVariableToEnvironment(java.util.Map<java.lang.String,java.lang.String> environment, java.lang.String keyAndValue)Adds a key/value pair to the given environment. If the key matches an existing key, the previous setting is replaced.- Parameters:
environment- the current environment.keyAndValue- the key/value pair.
-
getProcEnvironment
public static java.util.Map<java.lang.String,java.lang.String> getProcEnvironment() throws java.io.IOExceptionGets the list of environment variables for this process. The returned map preserves the casing of a variable's name on all platforms but obeys the casing rules of the current platform during lookup, e.g. key names will be case-insensitive on Windows platforms.- Returns:
- a map containing the environment variables, may be empty but never
null. - Throws:
java.io.IOException- the operation failed.
-
parseEnvironmentVariable
private static java.lang.String[] parseEnvironmentVariable(java.lang.String keyAndValue)
Parses a key/value pair into a String[]. It is assumed that the ky/value pair contains a '=' character.- Parameters:
keyAndValue- the key/value pair.- Returns:
- a String[] containing the key and value.
-
toString
private static java.lang.String toString(java.lang.String value)
-
toStrings
public static java.lang.String[] toStrings(java.util.Map<java.lang.String,java.lang.String> environment)
Converts a variable map as an array.- Parameters:
environment- the environment to use, may benull.- Returns:
- array of key=value assignment strings or
nullif and only if the input map wasnull.
-
-