home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / lang / System.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  32.6 KB  |  795 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)System.java    1.95 98/10/17
  3.  *
  4.  * Copyright 1994-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.lang;
  16.  
  17. import java.io.*;
  18. import java.util.Properties;
  19. import java.util.PropertyPermission;
  20. import java.util.StringTokenizer;
  21. import sun.net.InetAddressCachePolicy;
  22.  
  23. /**
  24.  * The <code>System</code> class contains several useful class fields 
  25.  * and methods. It cannot be instantiated. 
  26.  * <p>
  27.  * Among the facilities provided by the <code>System</code> class 
  28.  * are standard input, standard output, and error output streams; 
  29.  * access to externally defined "properties"; a means of 
  30.  * loading files and libraries; and a utility method for quickly 
  31.  * copying a portion of an array. 
  32.  *
  33.  * @author  Arthur van Hoff 
  34.  * @version 1.95, 10/17/98
  35.  * @since   JDK1.0
  36.  */
  37. public final
  38. class System {
  39.     /* First thing---register the natives */
  40.     private static native void registerNatives();
  41.     static {
  42.         registerNatives();
  43.     }
  44.  
  45.     /** Don't let anyone instantiate this class */
  46.     private System() {
  47.     }
  48.  
  49.     /**
  50.      * The "standard" input stream. This stream is already 
  51.      * open and ready to supply input data. Typically this stream 
  52.      * corresponds to keyboard input or another input source specified by 
  53.      * the host environment or user. 
  54.      */
  55.     public final static InputStream in = nullInputStream();
  56.  
  57.     /**
  58.      * The "standard" output stream. This stream is already 
  59.      * open and ready to accept output data. Typically this stream 
  60.      * corresponds to display output or another output destination 
  61.      * specified by the host environment or user. 
  62.      * <p>
  63.      * For simple stand-alone Java applications, a typical way to write 
  64.      * a line of output data is: 
  65.      * <blockquote><pre>
  66.      *     System.out.println(data)
  67.      * </pre></blockquote>
  68.      * <p>
  69.      * See the <code>println</code> methods in class <code>PrintStream</code>. 
  70.      *
  71.      * @see     java.io.PrintStream#println()
  72.      * @see     java.io.PrintStream#println(boolean)
  73.      * @see     java.io.PrintStream#println(char)
  74.      * @see     java.io.PrintStream#println(char[])
  75.      * @see     java.io.PrintStream#println(double)
  76.      * @see     java.io.PrintStream#println(float)
  77.      * @see     java.io.PrintStream#println(int)
  78.      * @see     java.io.PrintStream#println(long)
  79.      * @see     java.io.PrintStream#println(java.lang.Object)
  80.      * @see     java.io.PrintStream#println(java.lang.String)
  81.      */
  82.     public final static PrintStream out = nullPrintStream();
  83.  
  84.     /**
  85.      * The "standard" error output stream. This stream is already 
  86.      * open and ready to accept output data. 
  87.      * <p>
  88.      * Typically this stream corresponds to display output or another 
  89.      * output destination specified by the host environment or user. By 
  90.      * convention, this output stream is used to display error messages 
  91.      * or other information that should come to the immediate attention 
  92.      * of a user even if the principal output stream, the value of the 
  93.      * variable <code>out</code>, has been redirected to a file or other 
  94.      * destination that is typically not continuously monitored. 
  95.      */
  96.     public final static PrintStream err = nullPrintStream();
  97.  
  98.     /* The security manager for the system.
  99.      */
  100.     private static SecurityManager security = null;
  101.  
  102.     /**
  103.      * Reassigns the "standard" input stream.
  104.      * 
  105.      * <p>First, if there is a security manager, its <code>checkPermission</code> 
  106.      * method is called with a <code>RuntimePermission("setIO")</code> permission
  107.      *  to see if it's ok to reassign the "standard" input stream. 
  108.      * <p>
  109.      * 
  110.      * @param in the new standard input stream.
  111.      * 
  112.      * @throws SecurityException
  113.      *        if a security manager exists and its 
  114.      *        <code>checkPermission</code> method doesn't allow 
  115.      *        reassigning of the standard input stream.
  116.      * 
  117.      * @see SecurityManager#checkPermission
  118.      * @see java.lang.RuntimePermission
  119.      * 
  120.      * @since   JDK1.1
  121.      */
  122.     public static void setIn(InputStream in) {
  123.     checkIO();
  124.     setIn0(in);
  125.     }
  126.  
  127.     /**
  128.      * Reassigns the "standard" output stream.
  129.      *
  130.      * <p>First, if there is a security manager, its <code>checkPermission</code> 
  131.      * method is called with a <code>RuntimePermission("setIO")</code> permission
  132.      *  to see if it's ok to reassign the "standard" output stream. 
  133.      * 
  134.      * @param out the new standard output stream.
  135.      * 
  136.      * @throws SecurityException
  137.      *        if a security manager exists and its 
  138.      *        <code>checkPermission</code> method doesn't allow 
  139.      *        reassigning of the standard output stream.
  140.      * 
  141.      * @see SecurityManager#checkPermission
  142.      * @see java.lang.RuntimePermission
  143.      * 
  144.      * @since   JDK1.1
  145.      */
  146.     public static void setOut(PrintStream out) {
  147.     checkIO();
  148.     setOut0(out);
  149.     }
  150.  
  151.     /**
  152.      * Reassigns the "standard" error output stream.
  153.      *
  154.      * <p>First, if there is a security manager, its <code>checkPermission</code> 
  155.      * method is called with a <code>RuntimePermission("setIO")</code> permission
  156.      *  to see if it's ok to reassign the "standard" error output stream. 
  157.      * 
  158.      * @param out the new standard error output stream.
  159.      * 
  160.      * @throws SecurityException
  161.      *        if a security manager exists and its 
  162.      *        <code>checkPermission</code> method doesn't allow 
  163.      *        reassigning of the standard error output stream.
  164.      * 
  165.      * @see SecurityManager#checkPermission
  166.      * @see java.lang.RuntimePermission
  167.      * 
  168.      * @since   JDK1.1
  169.      */
  170.     public static void setErr(PrintStream err) {
  171.     checkIO();
  172.     setErr0(err);
  173.     }
  174.  
  175.     private static void checkIO() {
  176.         if (security != null)
  177.         security.checkPermission(new RuntimePermission("setIO"));
  178.     }
  179.  
  180.     private static native void setIn0(InputStream in);
  181.     private static native void setOut0(PrintStream out);
  182.     private static native void setErr0(PrintStream err);
  183.  
  184.     /**
  185.      * Sets the System security.
  186.      *
  187.      * <p> If there is a security manager already installed, this method first
  188.      * calls the security manager's <code>checkPermission</code> method
  189.      * with a <code>RuntimePermission("setSecurityManager")</code>
  190.      * permission to ensure it's ok to replace the existing
  191.      * security manager.
  192.      * This may result in throwing a <code>SecurityException</code>.
  193.      *
  194.      * <p> Otherwise, the argument is established as the current 
  195.      * security manager. If the argument is <code>null</code> and no 
  196.      * security manager has been established, then no action is taken and 
  197.      * the method simply returns. 
  198.      *
  199.      * @param      s   the security manager.
  200.      * @exception  SecurityException  if the security manager has already
  201.      *             been set and its <code>checkPermission</code> method doesn't allow
  202.      *             it to be replaced.
  203.      * @see SecurityManager#checkPermission
  204.      * @see java.lang.RuntimePermission
  205.      */
  206.     public static synchronized void setSecurityManager(SecurityManager s) {
  207.     if (security != null) {
  208.          // ask the currently installed security manager if we 
  209.          // can replace it.
  210.          security.checkPermission(new RuntimePermission
  211.                      ("setSecurityManager"));
  212.     }
  213.     security = s;
  214.     InetAddressCachePolicy.setIfNotSet(InetAddressCachePolicy.FOREVER);
  215.     }
  216.  
  217.     /**
  218.      * Gets the system security interface.
  219.      *
  220.      * @return  if a security manager has already been established for the
  221.      *          current application, then that security manager is returned;
  222.      *          otherwise, <code>null</code> is returned.
  223.      */
  224.     public static SecurityManager getSecurityManager() {
  225.     return security;
  226.     }
  227.  
  228.     /**
  229.      * Returns the current time in milliseconds.
  230.      * <p>
  231.      * See the description of the class <code>Date</code> for a discussion 
  232.      * of slight discrepancies that may arise between "computer 
  233.      * time" and coordinated universal time (UTC). 
  234.      *
  235.      * @return  the difference, measured in milliseconds, between the current
  236.      *          time and midnight, January 1, 1970 UTC.
  237.      * @see     java.util.Date
  238.      */
  239.     public static native long currentTimeMillis();
  240.  
  241.     /** 
  242.      * Copies an array from the specified source array, beginning at the
  243.      * specified position, to the specified position of the destination array.
  244.      * A subsequence of array components are copied from the source 
  245.      * array referenced by <code>src</code> to the destination array 
  246.      * referenced by <code>dst</code>. The number of components copied is 
  247.      * equal to the <code>length</code> argument. The components at 
  248.      * positions <code>srcOffset</code> through 
  249.      * <code>srcOffset+length-1</code> in the source array are copied into 
  250.      * positions <code>dstOffset</code> through 
  251.      * <code>dstOffset+length-1</code>, respectively, of the destination 
  252.      * array. 
  253.      * <p>
  254.      * If the <code>src</code> and <code>dst</code> arguments refer to the 
  255.      * same array object, then the copying is performed as if the 
  256.      * components at positions <code>srcOffset</code> through 
  257.      * <code>srcOffset+length-1</code> were first copied to a temporary 
  258.      * array with <code>length</code> components and then the contents of 
  259.      * the temporary array were copied into positions 
  260.      * <code>dstOffset</code> through <code>dstOffset+length-1</code> of the 
  261.      * destination array. 
  262.      * <p>
  263.      * If <code>dst</code> is <code>null</code>, then a 
  264.      * <code>NullPointerException</code> is thrown.
  265.      * <p>
  266.      * If <code>src</code> is <code>null</code>, then a 
  267.      * <code>NullPointerException</code> is thrown and the destination
  268.      * array is not modified.
  269.      * <p>
  270.      * Otherwise, if any of the following is true, an 
  271.      * <code>ArrayStoreException</code> is thrown and the destination is 
  272.      * not modified: 
  273.      * <ul>
  274.      * <li>The <code>src</code> argument refers to an object that is not an 
  275.      *     array. 
  276.      * <li>The <code>dst</code> argument refers to an object that is not an 
  277.      *     array. 
  278.      * <li>The <code>src</code> argument and <code>dst</code> argument refer to 
  279.      *     arrays whose component types are different primitive types. 
  280.      * <li>The <code>src</code> argument refers to an array with a primitive 
  281.      *     component type and the <code>dst</code> argument refers to an array 
  282.      *     with a reference component type. 
  283.      * <li>The <code>src</code> argument refers to an array with a reference 
  284.      *     component type and the <code>dst</code> argument refers to an array 
  285.      *     with a primitive component type. 
  286.      * </ul>
  287.      * <p>
  288.      * Otherwise, if any of the following is true, an 
  289.      * <code>IndexOutOfBoundsException</code> is 
  290.      * thrown and the destination is not modified: 
  291.      * <ul>
  292.      * <li>The <code>srcOffset</code> argument is negative. 
  293.      * <li>The <code>dstOffset</code> argument is negative. 
  294.      * <li>The <code>length</code> argument is negative. 
  295.      * <li><code>srcOffset+length</code> is greater than 
  296.      *     <code>src.length</code>, the length of the source array. 
  297.      * <li><code>dstOffset+length</code> is greater than 
  298.      *     <code>dst.length</code>, the length of the destination array. 
  299.      * </ul>
  300.      * <p>
  301.      * Otherwise, if any actual component of the source array from 
  302.      * position <code>srcOffset</code> through 
  303.      * <code>srcOffset+length-1</code> cannot be converted to the component 
  304.      * type of the destination array by assignment conversion, an 
  305.      * <code>ArrayStoreException</code> is thrown. In this case, let 
  306.      * <b><i>k</i></b> be the smallest nonnegative integer less than 
  307.      * length such that <code>src[srcOffset+</code><i>k</i><code>]</code> 
  308.      * cannot be converted to the component type of the destination 
  309.      * array; when the exception is thrown, source array components from 
  310.      * positions <code>srcOffset</code> through
  311.      * <code>srcOffset+</code><i>k</i><code>-1</code> 
  312.      * will already have been copied to destination array positions 
  313.      * <code>dstOffset</code> through
  314.      * <code>dstOffset+</code><i>k</I><code>-1</code> and no other 
  315.      * positions of the destination array will have been modified. 
  316.      * (Because of the restrictions already itemized, this
  317.      * paragraph effectively applies only to the situation where both 
  318.      * arrays have component types that are reference types.)
  319.      *
  320.      * @param      src:      the source array.
  321.      * @param      srcpos    start position in the source array.
  322.      * @param      dest      the destination array.
  323.      * @param      destpos   start position in the destination data.
  324.      * @param      length    the number of array elements to be copied.
  325.      * @exception  IndexOutOfBoundsException  if copying would cause
  326.      *               access of data outside array bounds.
  327.      * @exception  ArrayStoreException  if an element in the <code>src</code>
  328.      *               array could not be stored into the <code>dest</code> array
  329.      *               because of a type mismatch.
  330.      * @exception  NullPointerException if either <code>src</code> or 
  331.      *               <code>dst</code> is <code>null</code>.
  332.      */
  333.     public static native void arraycopy(Object src, int src_position,
  334.                                         Object dst, int dst_position,
  335.                                         int length);
  336.  
  337.     /**
  338.      * Returns the same hashcode for the given object as
  339.      * would be returned by the default method hashCode(),
  340.      * whether or not the given object's class overrides
  341.      * hashCode().
  342.      * The hashcode for the null reference is zero.
  343.      *
  344.      * @since   JDK1.1
  345.      */
  346.     public static native int identityHashCode(Object x);
  347.  
  348.     /**
  349.      * System properties. The following properties are guaranteed to be defined:
  350.      * <dl>
  351.      * <dt>java.version        <dd>Java version number
  352.      * <dt>java.vendor        <dd>Java vendor specific string
  353.      * <dt>java.vendor.url    <dd>Java vendor URL
  354.      * <dt>java.home        <dd>Java installation directory
  355.      * <dt>java.class.version    <dd>Java class version number
  356.      * <dt>java.class.path    <dd>Java classpath
  357.      * <dt>os.name        <dd>Operating System Name
  358.      * <dt>os.arch        <dd>Operating System Architecture
  359.      * <dt>os.version        <dd>Operating System Version
  360.      * <dt>file.separator    <dd>File separator ("/" on Unix)
  361.      * <dt>path.separator    <dd>Path separator (":" on Unix)
  362.      * <dt>line.separator    <dd>Line separator ("\n" on Unix)
  363.      * <dt>user.name        <dd>User account name
  364.      * <dt>user.home        <dd>User home directory
  365.      * <dt>user.dir        <dd>User's current working directory
  366.      * </dl>
  367.      */
  368.  
  369.     private static Properties props;
  370.     private static native Properties initProperties(Properties props);
  371.  
  372.     /**
  373.      * Determines the current system properties. 
  374.      * <p>
  375.      * First, if there is a security manager, its 
  376.      * <code>checkPropertiesAccess</code> method is called with no 
  377.      * arguments. This may result in a security exception. 
  378.      * <p>
  379.      * The current set of system properties for use by the 
  380.      * {@link #getProperty(String)} method is returned as a 
  381.      * <code>Properties</code> object. If there is no current set of 
  382.      * system properties, a set of system properties is first created and 
  383.      * initialized. This set of system properties always includes values 
  384.      * for the following keys: 
  385.      * <table>
  386.      * <tr><th>Key</th>
  387.      *     <th>Description of Associated Value</th></tr>
  388.      * <tr><td><code>java.version</code></td>
  389.      *     <td>Java Runtime Environment version</td></tr>
  390.      * <tr><td><code>java.vendor</code></td>
  391.      *     <td>Java Runtime Environment vendor</td></tr
  392.      * <tr><td><code>java.vendor.url</code></td>
  393.      *     <td>Java vendor URL</td></tr>
  394.      * <tr><td><code>java.home</code></td>
  395.      *     <td>Java installation directory</td></tr>
  396.      * <tr><td><code>java.vm.specification.version</code></td>
  397.      *     <td>Java Virtual Machine specification version</td></tr>
  398.      * <tr><td><code>java.vm.specification.vendor</code></td>
  399.      *     <td>Java Virtual Machine specification vendor</td></tr>
  400.      * <tr><td><code>java.vm.specification.name</code></td>
  401.      *     <td>Java Virtual Machine specification name</td></tr>
  402.      * <tr><td><code>java.vm.version</code></td>
  403.      *     <td>Java Virtual Machine implementation version</td></tr>
  404.      * <tr><td><code>java.vm.vendor</code></td>
  405.      *     <td>Java Virtual Machine implementation vendor</td></tr>
  406.      * <tr><td><code>java.vm.name</code></td>
  407.      *     <td>Java Virtual Machine implementation name</td></tr>
  408.      * <tr><td><code>java.specification.version</code></td>
  409.      *     <td>Java Runtime Environment specification  version</td></tr>
  410.      * <tr><td><code>java.specification.vendor</code></td>
  411.      *     <td>Java Runtime Environment specification  vendor</td></tr>
  412.      * <tr><td><code>java.specification.name</code></td>
  413.      *     <td>Java Runtime Environment specification  name</td></tr>
  414.      * <tr><td><code>java.class.version</code></td>
  415.      *     <td>Java class format version number</td></tr>
  416.      * <tr><td><code>java.class.path</code></td>
  417.      *     <td>Java class path</td></tr>
  418.      * <tr><td><code>os.name</code></td>
  419.      *     <td>Operating system name</td></tr>
  420.      * <tr><td><code>os.arch</code></td>
  421.      *     <td>Operating system architecture</td></tr>
  422.      * <tr><td><code>os.version</code></td>
  423.      *     <td>Operating system version</td></tr>
  424.      * <tr><td><code>file.separator</code></td>
  425.      *     <td>File separator ("/" on UNIX)</td></tr>
  426.      * <tr><td><code>path.separator</code></td>
  427.      *     <td>Path separator (":" on UNIX)</td></tr>
  428.      * <tr><td><code>line.separator</code></td>
  429.      *     <td>Line separator ("\n" on UNIX)</td></tr>
  430.      * <tr><td><code>user.name</code></td>
  431.      *     <td>User's account name</td></tr>
  432.      * <tr><td><code>user.home</code></td>
  433.      *     <td>User's home directory</td></tr>
  434.      * <tr><td><code>user.dir</code></td>
  435.      *     <td>User's current working directory</td></tr>
  436.      * </table>
  437.      * <p>
  438.      * Note that even if the security manager does not permit the 
  439.      * <code>getProperties</code> operation, it may choose to permit the 
  440.      * {@link #getProperty(String)} operation.
  441.      *
  442.      * @exception  SecurityException  if a security manager exists and its  
  443.      *             <code>checkPropertiesAccess</code> method doesn't allow access 
  444.      *              to the system properties.
  445.      * @see        java.lang.SecurityException
  446.      * @see        java.lang.SecurityManager#checkPropertiesAccess()
  447.      * @see        java.util.Properties
  448.      */
  449.     public static Properties getProperties() {
  450.     if (security != null) {
  451.         security.checkPropertiesAccess();
  452.     }
  453.     return props;
  454.     }
  455.  
  456.     /**
  457.      * Sets the system properties to the <code>Properties</code> 
  458.      * argument. 
  459.      * <p>
  460.      * First, if there is a security manager, its 
  461.      * <code>checkPropertiesAccess</code> method is called with no 
  462.      * arguments. This may result in a security exception. 
  463.      * <p>
  464.      * The argument becomes the current set of system properties for use 
  465.      * by the {@link #getProperty(String)} method. If the argument is 
  466.      * <code>null</code>, then the current set of system properties is 
  467.      * forgotten. 
  468.      *
  469.      * @param      props   the new system properties.
  470.      * @exception  SecurityException  if a security manager exists and its  
  471.      *             <code>checkPropertiesAccess</code> method doesn't allow access 
  472.      *              to the system properties.
  473.      * @see        java.lang.Properties
  474.      * @see        java.lang.SecurityException
  475.      * @see        java.lang.SecurityManager#checkPropertiesAccess()
  476.      */
  477.     public static void setProperties(Properties props) {
  478.     if (security != null) {
  479.         security.checkPropertiesAccess();
  480.     }
  481.     System.props = props;
  482.     }
  483.     
  484.     /**
  485.      * Gets the system property indicated by the specified key. 
  486.      * <p>
  487.      * First, if there is a security manager, its 
  488.      * <code>checkPropertyAccess</code> method is called with the key as 
  489.      * its argument. This may result in a SecurityException. 
  490.      * <p>
  491.      * If there is no current set of system properties, a set of system 
  492.      * properties is first created and initialized in the same manner as 
  493.      * for the <code>getProperties</code> method. 
  494.      *
  495.      * @param      key   the name of the system property.
  496.      * @return     the string value of the system property,
  497.      *             or <code>null</code> if there is no property with that key.
  498.      * @exception  SecurityException  if a security manager exists and its  
  499.      *             <code>checkPropertyAccess</code> method doesn't allow access 
  500.      *              to the specified system property.
  501.      * @see        java.lang.SecurityException
  502.      * @see        java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
  503.      * @see        java.lang.System#getProperties()
  504.      */
  505.     public static String getProperty(String key) {
  506.     if (security != null) {
  507.         security.checkPropertyAccess(key);
  508.     }
  509.     return props.getProperty(key);
  510.     }
  511.     
  512.     /**
  513.      * Gets the system property indicated by the specified key. 
  514.      * <p>
  515.      * First, if there is a security manager, its 
  516.      * <code>checkPropertyAccess</code> method is called with the 
  517.      * <code>key</code> as its argument. 
  518.      * <p>
  519.      * If there is no current set of system properties, a set of system 
  520.      * properties is first created and initialized in the same manner as 
  521.      * for the <code>getProperties</code> method. 
  522.      *
  523.      * @param      key   the name of the system property.
  524.      * @param      def   a default value.
  525.      * @return     the string value of the system property,
  526.      *             or the default value if there is no property with that key.
  527.      * @exception  SecurityException  if a security manager exists and its  
  528.      *             <code>checkPropertyAccess</code> method doesn't allow access 
  529.      *              to the specified system property.
  530.      * @see        java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
  531.      * @see        java.lang.System#getProperties()
  532.      */
  533.     public static String getProperty(String key, String def) {
  534.     if (security != null) {
  535.         security.checkPropertyAccess(key); 
  536.     }
  537.     return props.getProperty(key, def);
  538.     }
  539.     
  540.     /**
  541.      * Sets the system property indicated by the specified key. 
  542.      * <p>
  543.      * First, if a security manager exists, its 
  544.      * <code>SecurityManager.checkPermission</code> method
  545.      * is called with a <code>PropertyPermission(key, "write")</code>
  546.      * permission. This may result in a SecurityException being thrown.
  547.      * If no exception is thrown, the specified property is set to the given
  548.      * value.
  549.      * <p>
  550.      *
  551.      * @param      key   the name of the system property.
  552.      * @param      value the value of the system property.
  553.      * @return     the previous value of the system property,
  554.      *             or <code>null</code> if it did not have one.
  555.      * @exception  SecurityException  if a security manager exists and its  
  556.      *             <code>checkPermission</code> method doesn't allow 
  557.      *             setting of the specified property.
  558.      * @see        java.lang.System#getProperty(java.lang.String)
  559.      * @see        java.lang.System#getProperty(java.lang.String, java.lang.String)
  560.      * @see        java.util.PropertyPermission
  561.      * @see        SecurityManager#checkPermission
  562.      * @since      JDK1.2
  563.      */
  564.     public static String setProperty(String key, String value) {
  565.     if (security != null)
  566.         security.checkPermission(new PropertyPermission(key, "write"));
  567.     return (String) props.put(key, value);
  568.     }
  569.     
  570.     /**
  571.      * Gets an environment variable. An environment variable is a
  572.      * system-dependent external variable that has a string value.
  573.      *
  574.      * @deprecated The preferred way to extract system-dependent information
  575.      *             is the system properties of the
  576.      *             <code>java.lang.System.getProperty</code> methods and the
  577.      *             corresponding <code>get</code><em>TypeName</em> methods of
  578.      *             the <code>Boolean</code>, <code>Integer</code>, and
  579.      *             <code>Long</code> primitive types.  For example:
  580.      * <blockquote><pre>
  581.      *     String classPath = System.getProperty("java.class.path",".");
  582.      * <br>
  583.      *     if (Boolean.getBoolean("myapp.exper.mode"))
  584.      *         enableExpertCommands();
  585.      * </pre></blockquote>
  586.      * 
  587.      * @param  the name of the environment variable.
  588.      * @return the value of the variable, or <code>null</code> if the variable
  589.      *           is not defined.
  590.      * @see    java.lang.Boolean#getBoolean(java.lang.String)
  591.      * @see    java.lang.Integer#getInteger(java.lang.String)
  592.      * @see    java.lang.Integer#getInteger(java.lang.String, int)
  593.      * @see    java.lang.Integer#getInteger(java.lang.String, java.lang.Integer)
  594.      * @see    java.lang.Long#getLong(java.lang.String)
  595.      * @see    java.lang.Long#getLong(java.lang.String, long)
  596.      * @see    java.lang.Long#getLong(java.lang.String, java.lang.Long)
  597.      * @see    java.lang.System#getProperties()
  598.      * @see    java.lang.System#getProperty(java.lang.String)
  599.      * @see    java.lang.System#getProperty(java.lang.String, java.lang.String)
  600.      */
  601.     public static String getenv(String name) {
  602.     throw new Error("getenv no longer supported, use properties and -D instead: " + name);
  603.     }
  604.  
  605.     /**
  606.      * Terminates the currently running Java Virtual Machine. The 
  607.      * argument serves as a status code; by convention, a nonzero status 
  608.      * code indicates abnormal termination. 
  609.      * <p>
  610.      * This method calls the <code>exit</code> method in class 
  611.      * <code>Runtime</code>. This method never returns normally. 
  612.      * <p>
  613.      * The call <code>System.exit(n)</code> is effectively equivalent to 
  614.      * the call:
  615.      * <blockquote><pre>
  616.      * Runtime.getRuntime().exit(n)
  617.      * </pre></blockquote>
  618.      *
  619.      * @param      status   exit status.
  620.      * @throws  SecurityException
  621.      *        if a security manager exists and its <code>checkExit</code> 
  622.      *        method doesn't allow exit with the specified status.
  623.      * @see        java.lang.Runtime#exit(int)
  624.      */
  625.     public static void exit(int status) {
  626.     Runtime.getRuntime().exit(status);
  627.     }
  628.  
  629.     /**
  630.      * Runs the garbage collector.
  631.      * <p>
  632.      * Calling the <code>gc</code> method suggests that the Java Virtual 
  633.      * Machine expend effort toward recycling unused objects in order to 
  634.      * make the memory they currently occupy available for quick reuse. 
  635.      * When control returns from the method call, the Java Virtual 
  636.      * Machine has made a best effort to reclaim space from all discarded 
  637.      * objects.
  638.      * <p>
  639.      * The call <code>System.gc()</code> is effectively equivalent to the 
  640.      * call:
  641.      * <blockquote><pre>
  642.      * Runtime.getRuntime().gc()
  643.      * </pre></blockquote>
  644.      *
  645.      * @see     java.lang.Runtime#gc()
  646.      */
  647.     public static void gc() {
  648.     Runtime.getRuntime().gc();
  649.     }
  650.  
  651.     /**
  652.      * Runs the finalization methods of any objects pending finalization.
  653.      * <p>
  654.      * Calling this method suggests that the Java Virtual Machine expend 
  655.      * effort toward running the <code>finalize</code> methods of objects 
  656.      * that have been found to be discarded but whose <code>finalize</code> 
  657.      * methods have not yet been run. When control returns from the 
  658.      * method call, the Java Virtual Machine has made a best effort to 
  659.      * complete all outstanding finalizations. 
  660.      * <p>
  661.      * The call <code>System.runFinalization()</code> is effectively 
  662.      * equivalent to the call:
  663.      * <blockquote><pre>
  664.      * Runtime.getRuntime().runFinalization()
  665.      * </pre></blockquote>
  666.      *
  667.      * @see     java.lang.Runtime#runFinalization()
  668.      */
  669.     public static void runFinalization() {
  670.     Runtime.getRuntime().runFinalization();
  671.     }
  672.  
  673.     /**
  674.      * Enable or disable finalization on exit; doing so specifies that the
  675.      * finalizers of all objects that have finalizers that have not yet been
  676.      * automatically invoked are to be run before the Java runtime exits.
  677.      * By default, finalization on exit is disabled.
  678.      * 
  679.      * <p>If there is a security manager, 
  680.      * its <code>checkExit</code> method is first called
  681.      * with 0 as its argument to ensure the exit is allowed. 
  682.      * This could result in a SecurityException.
  683.      *
  684.      * @deprecated  This method is inherently unsafe.  It may result in
  685.      *         finalizers being called on live objects while other threads are
  686.      *      concurrently manipulating those objects, resulting in erratic
  687.      *        behavior or deadlock.
  688.      * 
  689.      * @throws  SecurityException
  690.      *        if a security manager exists and its <code>checkExit</code> 
  691.      *        method doesn't allow the exit.
  692.      *
  693.      * @see     java.lang.Runtime#exit(int)
  694.      * @see     java.lang.Runtime#gc()
  695.      * @see     java.lang.SecurityManager#checkExit(int)
  696.      * @since   JDK1.1
  697.      */
  698.     public static void runFinalizersOnExit(boolean value) {
  699.     Runtime.getRuntime().runFinalizersOnExit(value);
  700.     }
  701.  
  702.     /**
  703.      * Loads a code file with the specified filename from the local file 
  704.      * system as a dynamic library. The filename 
  705.      * argument must be a complete pathname. 
  706.      * <p>
  707.      * The call <code>System.load(name)</code> is effectively equivalent 
  708.      * to the call:
  709.      * <blockquote><pre>
  710.      * Runtime.getRuntime().load(name)
  711.      * </pre></blockquote>
  712.      *
  713.      * @param      filename   the file to load.
  714.      * @exception  SecurityException  if a security manager exists and its  
  715.      *             <code>checkLink</code> method doesn't allow 
  716.      *             loading of the specified dynamic library
  717.      * @exception  UnsatisfiedLinkError  if the file does not exist.
  718.      * @see        java.lang.Runtime#load(java.lang.String)
  719.      * @see        java.lang.SecurityManager#checkLink(java.lang.String)
  720.      */
  721.     public static void load(String filename) {
  722.     Runtime.getRuntime().load0(getCallerClass(), filename);
  723.     }
  724.  
  725.     /**
  726.      * Loads the system library specified by the <code>libname</code> 
  727.      * argument. The manner in which a library name is mapped to the 
  728.      * actual system library is system dependent.
  729.      * <p>
  730.      * The call <code>System.loadLibrary(name)</code> is effectively 
  731.      * equivalent to the call
  732.      * <blockquote><pre>
  733.      * Runtime.getRuntime().loadLibrary(name)
  734.      * </pre></blockquote>
  735.      *
  736.      * @param      libname   the name of the library.
  737.      * @exception  SecurityException  if a security manager exists and its  
  738.      *             <code>checkLink</code> method doesn't allow 
  739.      *             loading of the specified dynamic library
  740.      * @exception  UnsatisfiedLinkError  if the library does not exist.
  741.      * @see        java.lang.Runtime#loadLibrary(java.lang.String)
  742.      * @see        java.lang.SecurityManager#checkLink(java.lang.String)
  743.      */
  744.     public static void loadLibrary(String libname) {
  745.     Runtime.getRuntime().loadLibrary0(getCallerClass(), libname);
  746.     }
  747.  
  748.     /**
  749.      * Maps a library name into a platform-specific string representing
  750.      * a native library.
  751.      *
  752.      * @param      libname the name of the library.
  753.      * @return     a platform-dependent native library name.
  754.      * @see        java.lang.System#loadLibrary(java.lang.String)
  755.      * @see        java.lang.ClassLoader#findLibrary(java.lang.String)
  756.      * @since      JDK1.2
  757.      */
  758.     public static native String mapLibraryName(String libname);
  759.  
  760.     /**
  761.      * The following two methods exist because in, out, and err must be
  762.      * initialized to null.  The compiler, however, cannot be permitted to
  763.      * inline access to them, since they are later set to more sensible values
  764.      * by initializeSystemClass().
  765.      */
  766.     private static InputStream nullInputStream() throws NullPointerException {
  767.     if (currentTimeMillis() > 0)
  768.         return null;
  769.     throw new NullPointerException();
  770.     }
  771.  
  772.     private static PrintStream nullPrintStream() throws NullPointerException {
  773.     if (currentTimeMillis() > 0)
  774.         return null;
  775.     throw new NullPointerException();
  776.     }
  777.  
  778.     /**
  779.      * Initialize the system class.  Called after thread initialization.
  780.      */
  781.     private static void initializeSystemClass() {
  782.     props = new Properties();
  783.     initProperties(props);
  784.     FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
  785.     FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
  786.     FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
  787.     setIn0(new BufferedInputStream(fdIn));
  788.     setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true));
  789.     setErr0(new PrintStream(new BufferedOutputStream(fdErr, 128), true));
  790.     }
  791.  
  792.     /* returns the class of the caller. */ 
  793.     static native Class getCallerClass();
  794. }
  795.