jdk/src/share/classes/java/lang/System.java
author martin
Mon, 10 Mar 2008 14:32:51 -0700
changeset 48 dc5744ca15ea
parent 2 90ce3da70b43
child 2277 445a331b4a8b
permissions -rw-r--r--
4960438: (process) Need IO redirection API for subprocesses Reviewed-by: alanb, iris
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1994-2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.PropertyPermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.AllPermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.nio.channels.Channel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.nio.channels.spi.SelectorProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.nio.ch.Interruptible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.net.InetAddressCachePolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.reflect.Reflection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.security.util.SecurityConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.reflect.annotation.AnnotationType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * The <code>System</code> class contains several useful class fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * and methods. It cannot be instantiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>Among the facilities provided by the <code>System</code> class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * are standard input, standard output, and error output streams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * access to externally defined properties and environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * variables; a means of loading files and libraries; and a utility
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * method for quickly copying a portion of an array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @author  unascribed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @since   JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public final class System {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /* First thing---register the natives */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static native void registerNatives();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        registerNatives();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /** Don't let anyone instantiate this class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private System() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * The "standard" input stream. This stream is already
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * open and ready to supply input data. Typically this stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * corresponds to keyboard input or another input source specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * the host environment or user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public final static InputStream in = nullInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * The "standard" output stream. This stream is already
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * open and ready to accept output data. Typically this stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * corresponds to display output or another output destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * specified by the host environment or user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * For simple stand-alone Java applications, a typical way to write
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * a line of output data is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *     System.out.println(data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * See the <code>println</code> methods in class <code>PrintStream</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @see     java.io.PrintStream#println()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @see     java.io.PrintStream#println(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @see     java.io.PrintStream#println(char)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @see     java.io.PrintStream#println(char[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @see     java.io.PrintStream#println(double)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @see     java.io.PrintStream#println(float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @see     java.io.PrintStream#println(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @see     java.io.PrintStream#println(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @see     java.io.PrintStream#println(java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @see     java.io.PrintStream#println(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public final static PrintStream out = nullPrintStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * The "standard" error output stream. This stream is already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * open and ready to accept output data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Typically this stream corresponds to display output or another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * output destination specified by the host environment or user. By
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * convention, this output stream is used to display error messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * or other information that should come to the immediate attention
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * of a user even if the principal output stream, the value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * variable <code>out</code>, has been redirected to a file or other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * destination that is typically not continuously monitored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public final static PrintStream err = nullPrintStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /* The security manager for the system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private static volatile SecurityManager security = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Reassigns the "standard" input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * <p>First, if there is a security manager, its <code>checkPermission</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * method is called with a <code>RuntimePermission("setIO")</code> permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *  to see if it's ok to reassign the "standard" input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @param in the new standard input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *        if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *        <code>checkPermission</code> method doesn't allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *        reassigning of the standard input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @see SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @see java.lang.RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @since   JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public static void setIn(InputStream in) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        checkIO();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        setIn0(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * Reassigns the "standard" output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * <p>First, if there is a security manager, its <code>checkPermission</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * method is called with a <code>RuntimePermission("setIO")</code> permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *  to see if it's ok to reassign the "standard" output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @param out the new standard output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *        if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *        <code>checkPermission</code> method doesn't allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *        reassigning of the standard output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @see SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @see java.lang.RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @since   JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public static void setOut(PrintStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        checkIO();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        setOut0(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Reassigns the "standard" error output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * <p>First, if there is a security manager, its <code>checkPermission</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * method is called with a <code>RuntimePermission("setIO")</code> permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *  to see if it's ok to reassign the "standard" error output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @param err the new standard error output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *        if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *        <code>checkPermission</code> method doesn't allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *        reassigning of the standard error output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @see SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @see java.lang.RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @since   JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public static void setErr(PrintStream err) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        checkIO();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        setErr0(err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    private static volatile Console cons = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Returns the unique {@link java.io.Console Console} object associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * with the current Java virtual machine, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @return  The system console, if any, otherwise <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @since   1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     public static Console console() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
         if (cons == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
             synchronized (System.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                 cons = sun.misc.SharedSecrets.getJavaIOAccess().console();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
         return cons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Returns the channel inherited from the entity that created this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * <p> This method returns the channel obtained by invoking the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * inheritedChannel} method of the system-wide default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * {@link java.nio.channels.spi.SelectorProvider} object. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <p> In addition to the network-oriented channels described in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * inheritedChannel}, this method may return other kinds of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * channels in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @return  The inherited channel, if any, otherwise <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *          If a security manager is present and it does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *          permit access to the channel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public static Channel inheritedChannel() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return SelectorProvider.provider().inheritedChannel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    private static void checkIO() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            sm.checkPermission(new RuntimePermission("setIO"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    private static native void setIn0(InputStream in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    private static native void setOut0(PrintStream out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    private static native void setErr0(PrintStream err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Sets the System security.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * <p> If there is a security manager already installed, this method first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * calls the security manager's <code>checkPermission</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * with a <code>RuntimePermission("setSecurityManager")</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * permission to ensure it's ok to replace the existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * security manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * This may result in throwing a <code>SecurityException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * <p> Otherwise, the argument is established as the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * security manager. If the argument is <code>null</code> and no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * security manager has been established, then no action is taken and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * the method simply returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @param      s   the security manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @exception  SecurityException  if the security manager has already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *             been set and its <code>checkPermission</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *             doesn't allow it to be replaced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @see #getSecurityManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @see SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @see java.lang.RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    void setSecurityManager(final SecurityManager s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            s.checkPackageAccess("java.lang");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            // no-op
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        setSecurityManager0(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    private static synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    void setSecurityManager0(final SecurityManager s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            // ask the currently installed security manager if we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            // can replace it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            sm.checkPermission(new RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                                     ("setSecurityManager"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if ((s != null) && (s.getClass().getClassLoader() != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            // New security manager class is not on bootstrap classpath.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            // Cause policy to get initialized before we install the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            // security manager, in order to prevent infinite loops when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            // trying to initialize the policy (which usually involves
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            // accessing some security and/or system properties, which in turn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            // calls the installed security manager's checkPermission method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            // which will loop infinitely if there is a non-system class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            // (in this case: the new security manager class) on the stack).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            AccessController.doPrivileged(new PrivilegedAction<Object>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                    s.getClass().getProtectionDomain().implies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                        (SecurityConstants.ALL_PERMISSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        security = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        InetAddressCachePolicy.setIfNotSet(InetAddressCachePolicy.FOREVER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * Gets the system security interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @return  if a security manager has already been established for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *          current application, then that security manager is returned;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *          otherwise, <code>null</code> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @see     #setSecurityManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public static SecurityManager getSecurityManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        return security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * Returns the current time in milliseconds.  Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * while the unit of time of the return value is a millisecond,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * the granularity of the value depends on the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * operating system and may be larger.  For example, many
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * operating systems measure time in units of tens of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * milliseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * <p> See the description of the class <code>Date</code> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * a discussion of slight discrepancies that may arise between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * "computer time" and coordinated universal time (UTC).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @return  the difference, measured in milliseconds, between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *          the current time and midnight, January 1, 1970 UTC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @see     java.util.Date
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public static native long currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * Returns the current value of the running Java Virtual Machine's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * high-resolution time source, in nanoseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * <p>This method can only be used to measure elapsed time and is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * not related to any other notion of system or wall-clock time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * The value returned represents nanoseconds since some fixed but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * arbitrary <i>origin</i> time (perhaps in the future, so values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * may be negative).  The same origin is used by all invocations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * this method in an instance of a Java virtual machine; other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * virtual machine instances are likely to use a different origin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * <p>This method provides nanosecond precision, but not necessarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * nanosecond resolution (that is, how frequently the value changes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * - no guarantees are made except that the resolution is at least as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * good as that of {@link #currentTimeMillis()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * <p>Differences in successive calls that span greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * approximately 292 years (2<sup>63</sup> nanoseconds) will not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * correctly compute elapsed time due to numerical overflow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * <p>The values returned by this method become meaningful only when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * the difference between two such values, obtained within the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * instance of a Java virtual machine, is computed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * <p> For example, to measure how long some code takes to execute:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *  <pre> {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * long startTime = System.nanoTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * // ... the code being measured ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * long estimatedTime = System.nanoTime() - startTime;}</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * <p>To compare two nanoTime values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     *  <pre> {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * long t0 = System.nanoTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * long t1 = System.nanoTime();}</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * one should use {@code t1 - t0 < 0}, not {@code t1 < t0},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * because of the possibility of numerical overflow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @return the current value of the running Java Virtual Machine's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *         high-resolution time source, in nanoseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    public static native long nanoTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * Copies an array from the specified source array, beginning at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * specified position, to the specified position of the destination array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * A subsequence of array components are copied from the source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * array referenced by <code>src</code> to the destination array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * referenced by <code>dest</code>. The number of components copied is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * equal to the <code>length</code> argument. The components at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * positions <code>srcPos</code> through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * <code>srcPos+length-1</code> in the source array are copied into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * positions <code>destPos</code> through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * <code>destPos+length-1</code>, respectively, of the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * If the <code>src</code> and <code>dest</code> arguments refer to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * same array object, then the copying is performed as if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * components at positions <code>srcPos</code> through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * <code>srcPos+length-1</code> were first copied to a temporary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * array with <code>length</code> components and then the contents of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * the temporary array were copied into positions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * <code>destPos</code> through <code>destPos+length-1</code> of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * destination array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * If <code>dest</code> is <code>null</code>, then a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * <code>NullPointerException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * If <code>src</code> is <code>null</code>, then a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * <code>NullPointerException</code> is thrown and the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * array is not modified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * Otherwise, if any of the following is true, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * <code>ArrayStoreException</code> is thrown and the destination is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * not modified:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * <li>The <code>src</code> argument refers to an object that is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *     array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * <li>The <code>dest</code> argument refers to an object that is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *     array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * <li>The <code>src</code> argument and <code>dest</code> argument refer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *     to arrays whose component types are different primitive types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * <li>The <code>src</code> argument refers to an array with a primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *    component type and the <code>dest</code> argument refers to an array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *     with a reference component type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * <li>The <code>src</code> argument refers to an array with a reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *    component type and the <code>dest</code> argument refers to an array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *     with a primitive component type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * Otherwise, if any of the following is true, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * <code>IndexOutOfBoundsException</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * thrown and the destination is not modified:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * <li>The <code>srcPos</code> argument is negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * <li>The <code>destPos</code> argument is negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * <li>The <code>length</code> argument is negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * <li><code>srcPos+length</code> is greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *     <code>src.length</code>, the length of the source array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * <li><code>destPos+length</code> is greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *     <code>dest.length</code>, the length of the destination array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * Otherwise, if any actual component of the source array from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * position <code>srcPos</code> through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * <code>srcPos+length-1</code> cannot be converted to the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * type of the destination array by assignment conversion, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * <code>ArrayStoreException</code> is thrown. In this case, let
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * <b><i>k</i></b> be the smallest nonnegative integer less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * length such that <code>src[srcPos+</code><i>k</i><code>]</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * cannot be converted to the component type of the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * array; when the exception is thrown, source array components from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * positions <code>srcPos</code> through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * <code>srcPos+</code><i>k</i><code>-1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * will already have been copied to destination array positions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * <code>destPos</code> through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * <code>destPos+</code><i>k</I><code>-1</code> and no other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * positions of the destination array will have been modified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * (Because of the restrictions already itemized, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * paragraph effectively applies only to the situation where both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * arrays have component types that are reference types.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @param      src      the source array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * @param      srcPos   starting position in the source array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @param      dest     the destination array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * @param      destPos  starting position in the destination data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @param      length   the number of array elements to be copied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * @exception  IndexOutOfBoundsException  if copying would cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     *               access of data outside array bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * @exception  ArrayStoreException  if an element in the <code>src</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     *               array could not be stored into the <code>dest</code> array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     *               because of a type mismatch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @exception  NullPointerException if either <code>src</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *               <code>dest</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    public static native void arraycopy(Object src,  int  srcPos,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                                        Object dest, int destPos,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                                        int length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * Returns the same hash code for the given object as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * would be returned by the default method hashCode(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * whether or not the given object's class overrides
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * hashCode().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * The hash code for the null reference is zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @param x object for which the hashCode is to be calculated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @return  the hashCode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @since   JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    public static native int identityHashCode(Object x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * System properties. The following properties are guaranteed to be defined:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * <dt>java.version         <dd>Java version number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * <dt>java.vendor          <dd>Java vendor specific string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * <dt>java.vendor.url      <dd>Java vendor URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * <dt>java.home            <dd>Java installation directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * <dt>java.class.version   <dd>Java class version number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * <dt>java.class.path      <dd>Java classpath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * <dt>os.name              <dd>Operating System Name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * <dt>os.arch              <dd>Operating System Architecture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * <dt>os.version           <dd>Operating System Version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * <dt>file.separator       <dd>File separator ("/" on Unix)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * <dt>path.separator       <dd>Path separator (":" on Unix)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * <dt>line.separator       <dd>Line separator ("\n" on Unix)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * <dt>user.name            <dd>User account name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * <dt>user.home            <dd>User home directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * <dt>user.dir             <dd>User's current working directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    private static Properties props;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    private static native Properties initProperties(Properties props);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * Determines the current system properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * First, if there is a security manager, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * <code>checkPropertiesAccess</code> method is called with no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * arguments. This may result in a security exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * The current set of system properties for use by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * {@link #getProperty(String)} method is returned as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * <code>Properties</code> object. If there is no current set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * system properties, a set of system properties is first created and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * initialized. This set of system properties always includes values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * for the following keys:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * <table summary="Shows property keys and associated values">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * <tr><th>Key</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     *     <th>Description of Associated Value</th></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * <tr><td><code>java.version</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     *     <td>Java Runtime Environment version</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * <tr><td><code>java.vendor</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     *     <td>Java Runtime Environment vendor</td></tr
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * <tr><td><code>java.vendor.url</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     *     <td>Java vendor URL</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * <tr><td><code>java.home</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     *     <td>Java installation directory</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * <tr><td><code>java.vm.specification.version</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     *     <td>Java Virtual Machine specification version</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * <tr><td><code>java.vm.specification.vendor</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     *     <td>Java Virtual Machine specification vendor</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * <tr><td><code>java.vm.specification.name</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     *     <td>Java Virtual Machine specification name</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * <tr><td><code>java.vm.version</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     *     <td>Java Virtual Machine implementation version</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * <tr><td><code>java.vm.vendor</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     *     <td>Java Virtual Machine implementation vendor</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * <tr><td><code>java.vm.name</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     *     <td>Java Virtual Machine implementation name</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * <tr><td><code>java.specification.version</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *     <td>Java Runtime Environment specification  version</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * <tr><td><code>java.specification.vendor</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     *     <td>Java Runtime Environment specification  vendor</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * <tr><td><code>java.specification.name</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     *     <td>Java Runtime Environment specification  name</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * <tr><td><code>java.class.version</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     *     <td>Java class format version number</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * <tr><td><code>java.class.path</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     *     <td>Java class path</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * <tr><td><code>java.library.path</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     *     <td>List of paths to search when loading libraries</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * <tr><td><code>java.io.tmpdir</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     *     <td>Default temp file path</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * <tr><td><code>java.compiler</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     *     <td>Name of JIT compiler to use</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * <tr><td><code>java.ext.dirs</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     *     <td>Path of extension directory or directories</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * <tr><td><code>os.name</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     *     <td>Operating system name</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * <tr><td><code>os.arch</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     *     <td>Operating system architecture</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * <tr><td><code>os.version</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     *     <td>Operating system version</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * <tr><td><code>file.separator</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     *     <td>File separator ("/" on UNIX)</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * <tr><td><code>path.separator</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     *     <td>Path separator (":" on UNIX)</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * <tr><td><code>line.separator</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     *     <td>Line separator ("\n" on UNIX)</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * <tr><td><code>user.name</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     *     <td>User's account name</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * <tr><td><code>user.home</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     *     <td>User's home directory</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * <tr><td><code>user.dir</code></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     *     <td>User's current working directory</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * Multiple paths in a system property value are separated by the path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * separator character of the platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * Note that even if the security manager does not permit the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * <code>getProperties</code> operation, it may choose to permit the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * {@link #getProperty(String)} operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * @return     the system properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * @exception  SecurityException  if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     *             <code>checkPropertiesAccess</code> method doesn't allow access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     *              to the system properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * @see        #setProperties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * @see        java.lang.SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @see        java.lang.SecurityManager#checkPropertiesAccess()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @see        java.util.Properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    public static Properties getProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            sm.checkPropertiesAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        return props;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * Sets the system properties to the <code>Properties</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * First, if there is a security manager, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * <code>checkPropertiesAccess</code> method is called with no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * arguments. This may result in a security exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * The argument becomes the current set of system properties for use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * by the {@link #getProperty(String)} method. If the argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * <code>null</code>, then the current set of system properties is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * forgotten.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * @param      props   the new system properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * @exception  SecurityException  if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     *             <code>checkPropertiesAccess</code> method doesn't allow access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     *              to the system properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * @see        #getProperties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * @see        java.util.Properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * @see        java.lang.SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * @see        java.lang.SecurityManager#checkPropertiesAccess()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    public static void setProperties(Properties props) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            sm.checkPropertiesAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        if (props == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            props = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            initProperties(props);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        System.props = props;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * Gets the system property indicated by the specified key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * First, if there is a security manager, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * <code>checkPropertyAccess</code> method is called with the key as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * its argument. This may result in a SecurityException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * If there is no current set of system properties, a set of system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * properties is first created and initialized in the same manner as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * for the <code>getProperties</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * @param      key   the name of the system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * @return     the string value of the system property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     *             or <code>null</code> if there is no property with that key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * @exception  SecurityException  if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     *             <code>checkPropertyAccess</code> method doesn't allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     *              access to the specified system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * @exception  NullPointerException if <code>key</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * @exception  IllegalArgumentException if <code>key</code> is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * @see        #setProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * @see        java.lang.SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * @see        java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * @see        java.lang.System#getProperties()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    public static String getProperty(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        checkKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            sm.checkPropertyAccess(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        return props.getProperty(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * Gets the system property indicated by the specified key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * First, if there is a security manager, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * <code>checkPropertyAccess</code> method is called with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * <code>key</code> as its argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * If there is no current set of system properties, a set of system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * properties is first created and initialized in the same manner as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * for the <code>getProperties</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * @param      key   the name of the system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * @param      def   a default value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * @return     the string value of the system property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     *             or the default value if there is no property with that key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * @exception  SecurityException  if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     *             <code>checkPropertyAccess</code> method doesn't allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     *             access to the specified system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * @exception  NullPointerException if <code>key</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * @exception  IllegalArgumentException if <code>key</code> is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * @see        #setProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * @see        java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * @see        java.lang.System#getProperties()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    public static String getProperty(String key, String def) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        checkKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            sm.checkPropertyAccess(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        return props.getProperty(key, def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * Sets the system property indicated by the specified key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * First, if a security manager exists, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * <code>SecurityManager.checkPermission</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * is called with a <code>PropertyPermission(key, "write")</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * permission. This may result in a SecurityException being thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * If no exception is thrown, the specified property is set to the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * @param      key   the name of the system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * @param      value the value of the system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * @return     the previous value of the system property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     *             or <code>null</code> if it did not have one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * @exception  SecurityException  if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     *             <code>checkPermission</code> method doesn't allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     *             setting of the specified property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * @exception  NullPointerException if <code>key</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     *             <code>value</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * @exception  IllegalArgumentException if <code>key</code> is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * @see        #getProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * @see        java.lang.System#getProperty(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * @see        java.lang.System#getProperty(java.lang.String, java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * @see        java.util.PropertyPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * @see        SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * @since      1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    public static String setProperty(String key, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        checkKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            sm.checkPermission(new PropertyPermission(key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                SecurityConstants.PROPERTY_WRITE_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        return (String) props.setProperty(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * Removes the system property indicated by the specified key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * First, if a security manager exists, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * <code>SecurityManager.checkPermission</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * is called with a <code>PropertyPermission(key, "write")</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * permission. This may result in a SecurityException being thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * If no exception is thrown, the specified property is removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * @param      key   the name of the system property to be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * @return     the previous string value of the system property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     *             or <code>null</code> if there was no property with that key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * @exception  SecurityException  if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     *             <code>checkPropertyAccess</code> method doesn't allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     *              access to the specified system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * @exception  NullPointerException if <code>key</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * @exception  IllegalArgumentException if <code>key</code> is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * @see        #getProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * @see        #setProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * @see        java.util.Properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * @see        java.lang.SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * @see        java.lang.SecurityManager#checkPropertiesAccess()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    public static String clearProperty(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        checkKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            sm.checkPermission(new PropertyPermission(key, "write"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        return (String) props.remove(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    private static void checkKey(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        if (key == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            throw new NullPointerException("key can't be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        if (key.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            throw new IllegalArgumentException("key can't be empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * Gets the value of the specified environment variable. An
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * environment variable is a system-dependent external named
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * <p>If a security manager exists, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * {@link SecurityManager#checkPermission checkPermission}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * method is called with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * <code>{@link RuntimePermission}("getenv."+name)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * permission.  This may result in a {@link SecurityException}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * being thrown.  If no exception is thrown the value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * variable <code>name</code> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * <p><a name="EnvironmentVSSystemProperties"><i>System
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * properties</i> and <i>environment variables</i></a> are both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * conceptually mappings between names and values.  Both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * mechanisms can be used to pass user-defined information to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * Java process.  Environment variables have a more global effect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * because they are visible to all descendants of the process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * which defines them, not just the immediate Java subprocess.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * They can have subtly different semantics, such as case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * insensitivity, on different operating systems.  For these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * reasons, environment variables are more likely to have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * unintended side effects.  It is best to use system properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * where possible.  Environment variables should be used when a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * global effect is desired, or when an external system interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * requires an environment variable (such as <code>PATH</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * <p>On UNIX systems the alphabetic case of <code>name</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * typically significant, while on Microsoft Windows systems it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * typically not.  For example, the expression
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * <code>System.getenv("FOO").equals(System.getenv("foo"))</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * is likely to be true on Microsoft Windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * @param  name the name of the environment variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * @return the string value of the variable, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     *         if the variable is not defined in the system environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * @throws NullPointerException if <code>name</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * @throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     *         if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     *         {@link SecurityManager#checkPermission checkPermission}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     *         method doesn't allow access to the environment variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     *         <code>name</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * @see    #getenv()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * @see    ProcessBuilder#environment()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    public static String getenv(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            sm.checkPermission(new RuntimePermission("getenv."+name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        return ProcessEnvironment.getenv(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * Returns an unmodifiable string map view of the current system environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * The environment is a system-dependent mapping from names to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * values which is passed from parent to child processes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * <p>If the system does not support environment variables, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * empty map is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * <p>The returned map will never contain null keys or values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * Attempting to query the presence of a null key or value will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * throw a {@link NullPointerException}.  Attempting to query
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * the presence of a key or value which is not of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * {@link String} will throw a {@link ClassCastException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * <p>The returned map and its collection views may not obey the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * general contract of the {@link Object#equals} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * {@link Object#hashCode} methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * <p>The returned map is typically case-sensitive on all platforms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * <p>If a security manager exists, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * {@link SecurityManager#checkPermission checkPermission}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * method is called with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * <code>{@link RuntimePermission}("getenv.*")</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * permission.  This may result in a {@link SecurityException} being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * <p>When passing information to a Java subprocess,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * <a href=#EnvironmentVSSystemProperties>system properties</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * are generally preferred over environment variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * @return the environment as a map of variable names to values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     * @throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     *         if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     *         {@link SecurityManager#checkPermission checkPermission}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     *         method doesn't allow access to the process environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * @see    #getenv(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * @see    ProcessBuilder#environment()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    public static java.util.Map<String,String> getenv() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            sm.checkPermission(new RuntimePermission("getenv.*"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        return ProcessEnvironment.getenv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * Terminates the currently running Java Virtual Machine. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * argument serves as a status code; by convention, a nonzero status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * code indicates abnormal termination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * This method calls the <code>exit</code> method in class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * <code>Runtime</code>. This method never returns normally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * The call <code>System.exit(n)</code> is effectively equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * the call:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * Runtime.getRuntime().exit(n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * @param      status   exit status.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     *        if a security manager exists and its <code>checkExit</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     *        method doesn't allow exit with the specified status.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * @see        java.lang.Runtime#exit(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    public static void exit(int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        Runtime.getRuntime().exit(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * Runs the garbage collector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * Calling the <code>gc</code> method suggests that the Java Virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * Machine expend effort toward recycling unused objects in order to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * make the memory they currently occupy available for quick reuse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * When control returns from the method call, the Java Virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * Machine has made a best effort to reclaim space from all discarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     * The call <code>System.gc()</code> is effectively equivalent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     * call:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * Runtime.getRuntime().gc()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * @see     java.lang.Runtime#gc()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    public static void gc() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        Runtime.getRuntime().gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * Runs the finalization methods of any objects pending finalization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * Calling this method suggests that the Java Virtual Machine expend
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * effort toward running the <code>finalize</code> methods of objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * that have been found to be discarded but whose <code>finalize</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * methods have not yet been run. When control returns from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     * method call, the Java Virtual Machine has made a best effort to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * complete all outstanding finalizations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * The call <code>System.runFinalization()</code> is effectively
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * equivalent to the call:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * Runtime.getRuntime().runFinalization()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * @see     java.lang.Runtime#runFinalization()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    public static void runFinalization() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        Runtime.getRuntime().runFinalization();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * Enable or disable finalization on exit; doing so specifies that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * finalizers of all objects that have finalizers that have not yet been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * automatically invoked are to be run before the Java runtime exits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * By default, finalization on exit is disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * <p>If there is a security manager,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * its <code>checkExit</code> method is first called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * with 0 as its argument to ensure the exit is allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * This could result in a SecurityException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * @deprecated  This method is inherently unsafe.  It may result in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     *      finalizers being called on live objects while other threads are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     *      concurrently manipulating those objects, resulting in erratic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     *      behavior or deadlock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * @param value indicating enabling or disabling of finalization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     *        if a security manager exists and its <code>checkExit</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     *        method doesn't allow the exit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * @see     java.lang.Runtime#exit(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * @see     java.lang.Runtime#gc()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * @see     java.lang.SecurityManager#checkExit(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * @since   JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    public static void runFinalizersOnExit(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        Runtime.getRuntime().runFinalizersOnExit(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * Loads a code file with the specified filename from the local file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * system as a dynamic library. The filename
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * argument must be a complete path name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * The call <code>System.load(name)</code> is effectively equivalent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * to the call:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * Runtime.getRuntime().load(name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * @param      filename   the file to load.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * @exception  SecurityException  if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     *             <code>checkLink</code> method doesn't allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     *             loading of the specified dynamic library
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * @exception  UnsatisfiedLinkError  if the file does not exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * @exception  NullPointerException if <code>filename</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     *             <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     * @see        java.lang.Runtime#load(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * @see        java.lang.SecurityManager#checkLink(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
    public static void load(String filename) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        Runtime.getRuntime().load0(getCallerClass(), filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * Loads the system library specified by the <code>libname</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     * argument. The manner in which a library name is mapped to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * actual system library is system dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * The call <code>System.loadLibrary(name)</code> is effectively
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     * equivalent to the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * Runtime.getRuntime().loadLibrary(name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     * @param      libname   the name of the library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * @exception  SecurityException  if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     *             <code>checkLink</code> method doesn't allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     *             loading of the specified dynamic library
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * @exception  UnsatisfiedLinkError  if the library does not exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * @exception  NullPointerException if <code>libname</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     *             <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * @see        java.lang.Runtime#loadLibrary(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * @see        java.lang.SecurityManager#checkLink(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    public static void loadLibrary(String libname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        Runtime.getRuntime().loadLibrary0(getCallerClass(), libname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * Maps a library name into a platform-specific string representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * a native library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * @param      libname the name of the library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * @return     a platform-dependent native library name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * @exception  NullPointerException if <code>libname</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     *             <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * @see        java.lang.System#loadLibrary(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * @see        java.lang.ClassLoader#findLibrary(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     * @since      1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    public static native String mapLibraryName(String libname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     * The following two methods exist because in, out, and err must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     * initialized to null.  The compiler, however, cannot be permitted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * inline access to them, since they are later set to more sensible values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * by initializeSystemClass().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
    private static InputStream nullInputStream() throws NullPointerException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        if (currentTimeMillis() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    private static PrintStream nullPrintStream() throws NullPointerException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        if (currentTimeMillis() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     * Initialize the system class.  Called after thread initialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    private static void initializeSystemClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        props = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        initProperties(props);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        sun.misc.Version.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        setIn0(new BufferedInputStream(fdIn));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        setErr0(new PrintStream(new BufferedOutputStream(fdErr, 128), true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        // Load the zip library now in order to keep java.util.zip.ZipFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        // from trying to use itself to load this library later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        loadLibrary("zip");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        // Setup Java signal handlers for HUP, TERM, and INT (where available).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        Terminator.setup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        // The order in with the hooks are added here is important as it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        // determines the order in which they are run.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        // (1)Console restore hook needs to be called first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        // (2)Application hooks must be run before calling deleteOnExitHook.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        Shutdown.add(sun.misc.SharedSecrets.getJavaIOAccess().consoleRestoreHook());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        Shutdown.add(ApplicationShutdownHooks.hook());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        Shutdown.add(sun.misc.SharedSecrets.getJavaIODeleteOnExitAccess());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        // Initialize any miscellenous operating system settings that need to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        // set for the class libraries. Currently this is no-op everywhere except
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        // for Windows where the process-wide error mode is set before the java.io
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        // classes are used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        sun.misc.VM.initializeOSEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        // Set the maximum amount of direct memory.  This value is controlled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        // by the vm option -XX:MaxDirectMemorySize=<size>.  This method acts
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        // as an initializer only if it is called before sun.misc.VM.booted().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        sun.misc.VM.maxDirectMemory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        // Set a boolean to determine whether ClassLoader.loadClass accepts
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        // array syntax.  This value is controlled by the system property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        // "sun.lang.ClassLoader.allowArraySyntax".  This method acts as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        // an initializer only if it is called before sun.misc.VM.booted().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        sun.misc.VM.allowArraySyntax();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        // Subsystems that are invoked during initialization can invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        // sun.misc.VM.isBooted() in order to avoid doing things that should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        // wait until the application class loader has been set up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        sun.misc.VM.booted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        // The main thread is not added to its thread group in the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        // way as other threads; we must do it ourselves here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        Thread current = Thread.currentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        current.getThreadGroup().add(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        // Allow privileged classes outside of java.lang
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        sun.misc.SharedSecrets.setJavaLangAccess(new sun.misc.JavaLangAccess(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            public sun.reflect.ConstantPool getConstantPool(Class klass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                return klass.getConstantPool();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            public void setAnnotationType(Class klass, AnnotationType type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                klass.setAnnotationType(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            public AnnotationType getAnnotationType(Class klass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                return klass.getAnnotationType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            public <E extends Enum<E>>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                    E[] getEnumConstantsShared(Class<E> klass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                return klass.getEnumConstantsShared();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            public void blockedOn(Thread t, Interruptible b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                t.blockedOn(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    /* returns the class of the caller. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
    static Class getCallerClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        // NOTE use of more generic Reflection.getCallerClass()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        return Reflection.getCallerClass(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
}