Class EnvironmentUtils
- java.lang.Object
-
- org.apache.commons.exec.environment.EnvironmentUtils
-
public class EnvironmentUtils extends java.lang.Object
Wrapper for environment variables.- Version:
- $Id: EnvironmentUtils.java 1636056 2014-11-01 21:12:52Z ggregory $
-
-
Field Summary
Fields Modifier and Type Field Description private static DefaultProcessingEnvironment
PROCESSING_ENVIRONMENT_IMPLEMENTATION
-
Constructor Summary
Constructors Modifier Constructor Description private
EnvironmentUtils()
Disable constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addVariableToEnvironment(java.util.Map<java.lang.String,java.lang.String> environment, java.lang.String keyAndValue)
Add a key/value pair to the given environment.static java.util.Map<java.lang.String,java.lang.String>
getProcEnvironment()
Find the list of environment variables for this process.private static java.lang.String[]
parseEnvironmentVariable(java.lang.String keyAndValue)
Split a key/value pair into a String[].static java.lang.String[]
toStrings(java.util.Map<java.lang.String,java.lang.String> environment)
Get the variable list as an array.
-
-
-
Field Detail
-
PROCESSING_ENVIRONMENT_IMPLEMENTATION
private static final DefaultProcessingEnvironment PROCESSING_ENVIRONMENT_IMPLEMENTATION
-
-
Method Detail
-
toStrings
public static java.lang.String[] toStrings(java.util.Map<java.lang.String,java.lang.String> environment)
Get the variable list as an array.- Parameters:
environment
- the environment to use, may benull
- Returns:
- array of key=value assignment strings or
null
if and only if the input map wasnull
-
getProcEnvironment
public static java.util.Map<java.lang.String,java.lang.String> getProcEnvironment() throws java.io.IOException
Find 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
-
addVariableToEnvironment
public static void addVariableToEnvironment(java.util.Map<java.lang.String,java.lang.String> environment, java.lang.String keyAndValue)
Add a key/value pair to the given environment. If the key matches an existing key, the previous setting is replaced.- Parameters:
environment
- the current environmentkeyAndValue
- the key/value pair
-
parseEnvironmentVariable
private static java.lang.String[] parseEnvironmentVariable(java.lang.String keyAndValue)
Split 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
-
-