54 55 package java.lang; 56 57 import java.io.*; 58 import java.util.*; 59 60 61 final class ProcessEnvironment 62 { 63 private static final HashMap<Variable,Value> theEnvironment; 64 private static final Map<String,String> theUnmodifiableEnvironment; 65 static final int MIN_NAME_LENGTH = 0; 66 67 static { 68 // We cache the C environment. This means that subsequent calls 69 // to putenv/setenv from C will not be visible from Java code. 70 byte[][] environ = environ(); 71 theEnvironment = new HashMap<Variable,Value>(environ.length/2 + 3); 72 // Read environment variables back to front, 73 // so that earlier variables override later ones. 74 for (int i = environ.length-1; i > 0; i-=2) 75 theEnvironment.put(Variable.valueOf(environ[i-1]), 76 Value.valueOf(environ[i])); 77 78 theUnmodifiableEnvironment 79 = Collections.unmodifiableMap 80 (new StringEnvironment(theEnvironment)); 81 } 82 83 /* Only for use by System.getenv(String) */ 84 static String getenv(String name) { 85 return theUnmodifiableEnvironment.get(name); 86 } 87 88 /* Only for use by System.getenv() */ 89 static Map<String,String> getenv() { 90 return theUnmodifiableEnvironment; 91 } 92 93 /* Only for use by ProcessBuilder.environment() */ 94 static Map<String,String> environment() { 95 return new StringEnvironment 96 ((Map<Variable,Value>)(theEnvironment.clone())); | 54 55 package java.lang; 56 57 import java.io.*; 58 import java.util.*; 59 60 61 final class ProcessEnvironment 62 { 63 private static final HashMap<Variable,Value> theEnvironment; 64 private static final Map<String,String> theUnmodifiableEnvironment; 65 static final int MIN_NAME_LENGTH = 0; 66 67 static { 68 // We cache the C environment. This means that subsequent calls 69 // to putenv/setenv from C will not be visible from Java code. 70 byte[][] environ = environ(); 71 theEnvironment = new HashMap<Variable,Value>(environ.length/2 + 3); 72 // Read environment variables back to front, 73 // so that earlier variables override later ones. 74 for (int i = environ.length-1; i > 0; i-=2) { 75 final Variable variable = Variable.valueOf(environ[i-1]); 76 if (!variable.toString().equals("DESKTOP_STARTUP_ID")) { 77 theEnvironment.put(variable, 78 Value.valueOf(environ[i])); 79 } 80 } 81 82 theUnmodifiableEnvironment 83 = Collections.unmodifiableMap 84 (new StringEnvironment(theEnvironment)); 85 } 86 87 /* Only for use by System.getenv(String) */ 88 static String getenv(String name) { 89 return theUnmodifiableEnvironment.get(name); 90 } 91 92 /* Only for use by System.getenv() */ 93 static Map<String,String> getenv() { 94 return theUnmodifiableEnvironment; 95 } 96 97 /* Only for use by ProcessBuilder.environment() */ 98 static Map<String,String> environment() { 99 return new StringEnvironment 100 ((Map<Variable,Value>)(theEnvironment.clone())); |