ProcessEnvironment.java revision 3909
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* We use APIs that access the standard Unix environ array, which
* is defined by UNIX98 to look like:
*
* char **environ;
*
* These are unsorted, case-sensitive, null-terminated arrays of bytes
* of the form FOO=BAR\000 which are usually encoded in the user's
* default encoding (file.encoding is an excellent choice for
* directly access the underlying byte representation, we take pains
* to pass on the child the exact byte representation we inherit from
* the parent process for any environment name or value not created by
* Javaland. So we keep track of all the byte representations.
*
* Internally, we define the types Variable and Value that exhibit
* environment then looks like a Map<Variable,Value>. But we don't
* expose this to the user -- we only provide a Map<String,String>
* view, although we could also provide a Map<byte[],byte[]> view.
*
* The non-private methods in this class are not for general use even
* within this package. Instead, they are the system-dependent parts
* of the system-independent method of the same name. Don't even
* think of using this class unless your method's name appears below.
*
* @author Martin Buchholz
* @since 1.5
*/
final class ProcessEnvironment
{
static final int MIN_NAME_LENGTH = 0;
static {
// We cache the C environment. This means that subsequent calls
// Read environment variables back to front,
// so that earlier variables override later ones.
(new StringEnvironment(theEnvironment));
}
/* Only for use by System.getenv(String) */
}
/* Only for use by System.getenv() */
return theUnmodifiableEnvironment;
}
/* Only for use by ProcessBuilder.environment() */
return new StringEnvironment
}
/* Only for use by Runtime.exec(...String[]envp...) */
}
private static native byte[][] environ();
// This class is not instantiable.
private ProcessEnvironment() {}
// Check that name is suitable for insertion into Environment map
throw new IllegalArgumentException
}
// Check that value is suitable for insertion into Environment map
throw new IllegalArgumentException
}
// A class hiding the byteArray-String duality of
// text data on Unixoid operating systems.
private static abstract class ExternalData {
protected final byte[] bytes;
}
public byte[] getBytes() {
return bytes;
}
return str;
}
return o instanceof ExternalData
}
public int hashCode() {
}
}
private static class Variable
{
}
}
}
return valueOfQueryOnly(str);
}
}
}
}
}
private static class Value
{
}
}
}
return valueOfQueryOnly(str);
}
}
}
}
}
// This implements the String map view the user sees.
private static class StringEnvironment
{
}
}
}
}
}
}
return new StringKeySet(m.keySet());
}
return new StringEntrySet(m.entrySet());
}
return new StringValues(m.values());
}
// It is technically feasible to provide a byte-oriented view
// as follows:
// public Map<byte[],byte[]> asByteArrayMap() {
// return new ByteArrayEnvironment(m);
// }
// Convert to Unix style environ as a monolithic byte array
// inspired by the Windows Environment Block, except we work
// exclusively with bytes instead of chars, and we need only
// one trailing NUL on Unix.
// This keeps the JNI as simple and efficient as possible.
public byte[] toEnvironmentBlock(int[]envc) {
}
int i = 0;
block[i++] = (byte) '=';
// No need to write NUL byte explicitly
//block[i++] = (byte) '\u0000';
}
return block;
}
}
}
private static class StringEntry
{
}
return o instanceof StringEntry
&& e.equals(((StringEntry)o).e);
}
}
private static class StringEntrySet
{
return new StringEntry(i.next());
}
};
}
if (o instanceof StringEntry)
return ((StringEntry)o).e;
}
}
throw new UnsupportedOperationException();
}
};
}
return o instanceof StringEntrySet
&& s.equals(((StringEntrySet) o).s);
}
}
private static class StringValues
extends AbstractCollection<String>
{
private final Collection<Value> c;
};
}
}
}
return o instanceof StringValues
&& c.equals(((StringValues)o).c);
}
}
};
}
}
}
}
// Replace with general purpose method someday
private static int arrayCompare(byte[]x, byte[] y) {
for (int i = 0; i < min; i++)
if (x[i] != y[i])
return x[i] - y[i];
}
// Replace with general purpose method someday
private static boolean arrayEquals(byte[] x, byte[] y) {
return false;
for (int i = 0; i < x.length; i++)
if (x[i] != y[i])
return false;
return true;
}
// Replace with general purpose method someday
private static int arrayHash(byte[] x) {
int hash = 0;
for (int i = 0; i < x.length; i++)
return hash;
}
}