org.sandev.basics.util
Class EnvGrabber

java.lang.Object
  extended byorg.sandev.basics.util.EnvGrabber

public class EnvGrabber
extends java.lang.Object

Provides a utility to return the value of something set as an environment variable. Why there is no reasonable way of getting this in standard Java is beyond me. After some frustrating attempts, the core of this code was nicked from http://www.rgagnon.com/javadetails/java-0150.html. Our thanks to Real Gagnon for posting it and making it available.

The core access was wrapped in a singleton to avoid unnecessary repeat calls.


Field Summary
protected static java.util.Properties envVars
          The single reference copy.
 
Constructor Summary
EnvGrabber()
           
 
Method Summary
static void dumpProperties(java.util.Properties props)
          Go through all the property keys and dump out the corresponding values WITHOUT TRUNCATING.
static void envDump()
          This method takes its best shot at dumping out a whole bunch of properties to stdout.
static java.lang.String getEnvVar(java.lang.String envVarName)
          Given the name of an environment variable, return its value.
protected static java.util.Properties getEnvVars()
          Code adapted from www.rgagnon.com
static java.lang.String safeGetEnvVar(java.lang.String envVarName)
          Catches any thrown IOException and simply returns null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

envVars

protected static java.util.Properties envVars
The single reference copy.

Constructor Detail

EnvGrabber

public EnvGrabber()
Method Detail

getEnvVars

protected static java.util.Properties getEnvVars()
                                          throws java.io.IOException
Code adapted from www.rgagnon.com

Throws:
java.io.IOException

getEnvVar

public static java.lang.String getEnvVar(java.lang.String envVarName)
                                  throws java.io.IOException
Given the name of an environment variable, return its value. This throws an IOException if anything goes wrong.

Throws:
java.io.IOException

safeGetEnvVar

public static java.lang.String safeGetEnvVar(java.lang.String envVarName)
Catches any thrown IOException and simply returns null.


envDump

public static void envDump()
This method takes its best shot at dumping out a whole bunch of properties to stdout. Useful when you are trying to figure out what's around. This method does not make use of the properties list method since that truncates the displayed values (typically right where you wanted to see it).


dumpProperties

public static void dumpProperties(java.util.Properties props)
Go through all the property keys and dump out the corresponding values WITHOUT TRUNCATING.