FileDocCategorySizeDatePackage
ProcessEnvironment.javaAPI DocJava SE 6 API10497Tue Jun 10 00:32:44 BST 2008java.lang

ProcessEnvironment

public final class ProcessEnvironment extends HashMap

Fields Summary
static final int
MIN_NAME_LENGTH
private static final NameComparator
nameComparator
private static final EntryComparator
entryComparator
private static final ProcessEnvironment
theEnvironment
private static final Map
theUnmodifiableEnvironment
private static final Map
theCaseInsensitiveEnvironment
Constructors Summary
private ProcessEnvironment()


     
	nameComparator  = new NameComparator();
	entryComparator = new EntryComparator();
	theEnvironment  = new ProcessEnvironment();
	theUnmodifiableEnvironment
	    = Collections.unmodifiableMap(theEnvironment);

	String envblock = environmentBlock();
	int beg, end, eql;
	for (beg = 0;
	     ((end = envblock.indexOf('\u0000", beg  )) != -1 &&
	      // An initial `=' indicates a magic Windows variable name -- OK
	      (eql = envblock.indexOf('="     , beg+1)) != -1);
	     beg = end + 1) {
	    // Ignore corrupted environment strings.
	    if (eql < end)
		theEnvironment.put(envblock.substring(beg, eql),
				   envblock.substring(eql+1,end));
	}

	theCaseInsensitiveEnvironment
	    = new TreeMap<String,String>(nameComparator);
	theCaseInsensitiveEnvironment.putAll(theEnvironment);
    
	super();
    
private ProcessEnvironment(int capacity)

	super(capacity);
    
Methods Summary
public booleancontainsKey(java.lang.Object key)

	return super.containsKey(nonNullString(key));
    
public booleancontainsValue(java.lang.Object value)

	return super.containsValue(nonNullString(value));
    
static java.util.MapemptyEnvironment(int capacity)

	return new ProcessEnvironment(capacity);
    
public java.util.SetentrySet()

	return new CheckedEntrySet(super.entrySet());
    
static java.util.Mapenvironment()

	return (Map<String,String>) theEnvironment.clone();
    
private static native java.lang.StringenvironmentBlock()

public java.lang.Stringget(java.lang.Object key)

	return super.get(nonNullString(key));
    
static java.lang.Stringgetenv(java.lang.String name)

	// The original implementation used a native call to _wgetenv,
	// but it turns out that _wgetenv is only consistent with
	// GetEnvironmentStringsW (for non-ASCII) if `wmain' is used
	// instead of `main', even in a process created using
	// CREATE_UNICODE_ENVIRONMENT.  Instead we perform the
	// case-insensitive comparison ourselves.  At least this
	// guarantees that System.getenv().get(String) will be
	// consistent with System.getenv(String).
	return theCaseInsensitiveEnvironment.get(name);
    
static java.util.Mapgetenv()

	return theUnmodifiableEnvironment;
    
public java.util.SetkeySet()

	return new CheckedKeySet(super.keySet());
    
private static java.lang.StringnonNullString(java.lang.Object o)

	if (o == null)
	    throw new NullPointerException();
	return (String) o;
    
public java.lang.Stringput(java.lang.String key, java.lang.String value)

	return super.put(validateName(key), validateValue(value));
    
public java.lang.Stringremove(java.lang.Object key)

	return super.remove(nonNullString(key));
    
java.lang.StringtoEnvironmentBlock()

	// Sort Unicode-case-insensitively by name
	List<Map.Entry<String,String>> list
	    = new ArrayList<Map.Entry<String,String>>(entrySet());
	Collections.sort(list, entryComparator);

	StringBuilder sb = new StringBuilder(size()*30);
	for (Map.Entry<String,String> e : list)
	    sb.append(e.getKey())
	      .append('=")
	      .append(e.getValue())
	      .append('\u0000");
	// Ensure double NUL termination,
	// even if environment is empty.
	if (sb.length() == 0)
	    sb.append('\u0000");
	sb.append('\u0000");
	return sb.toString();
    
static java.lang.StringtoEnvironmentBlock(java.util.Map map)

	return map == null ? null :
	    ((ProcessEnvironment)map).toEnvironmentBlock();
    
private static java.lang.StringvalidateName(java.lang.String name)

	// An initial `=' indicates a magic Windows variable name -- OK
	if (name.indexOf('=", 1)   != -1 ||
	    name.indexOf('\u0000") != -1)
	    throw new IllegalArgumentException
		("Invalid environment variable name: \"" + name + "\"");
	return name;
    
private static java.lang.StringvalidateValue(java.lang.String value)

	if (value.indexOf('\u0000") != -1)
	    throw new IllegalArgumentException
		("Invalid environment variable value: \"" + value + "\"");
	return value;
    
public java.util.Collectionvalues()

	return new CheckedValues(super.values());