home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / lang / System.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  26.1 KB  |  655 lines

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