⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 system.java

📁 《移动Agent技术》一书的所有章节源代码。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * <dt>user.name		<dd>User account name
     * <dt>user.home		<dd>User home directory
     * <dt>user.dir		<dd>User's current working directory
     * </dl>
     */

    private static Properties props;
    private static native Properties initProperties(Properties props);

    /**
     * Determines the current system properties. 
     * <p>
     * If there is a security manager, its 
     * <code>checkPropertiesAccess</code> method is called with no 
     * arguments. This may result in a security exception. 
     * <p>
     * The current set of system properties is returned as a 
     * <code>Properties</code> object. If there is no current set of 
     * system properties, a set of system properties is first created and 
     * initialized. 
     * <p>
     * This set of system properties always includes values for the 
     * following keys: 
     * <table>
     * <tr><th>Key</th>
     *     <th>Description of Associated Value</th></tr>
     * <tr><td><code>java.version</code></td>
     *     <td>Java version number</td></tr>
     * <tr><td><code>java.vendor</code></td>
     *     <td>Java vendor-specific string</td></tr>
     * <tr><td><code>java.vendor.url</code></td>
     *     <td>Java vendor URL</td></tr>
     * <tr><td><code>java.home</code></td>
     *     <td>Java installation directory</td></tr>
     * <tr><td><code>java.class.version</code></td>
     *     <td>Java class format version number</td></tr>
     * <tr><td><code>java.class.path</code></td>
     *     <td>Java class path</td></tr>
     * <tr><td><code>os.name</code></td>
     *     <td>Operating system name</td></tr>
     * <tr><td><code>os.arch</code></td>
     *     <td>Operating system architecture</td></tr>
     * <tr><td><code>os.version</code></td>
     *     <td>Operating system version</td></tr>
     * <tr><td><code>file.separator</code></td>
     *     <td>File separator ("/" on UNIX)</td></tr>
     * <tr><td><code>path.separator</code></td>
     *     <td>Path separator (":" on UNIX)</td></tr>
     * <tr><td><code>line.separator</code></td>
     *     <td>Line separator ("\n" on UNIX)</td></tr>
     * <tr><td><code>user.name</code></td>
     *     <td>User's account name</td></tr>
     * <tr><td><code>user.home</code></td>
     *     <td>User's home directory</td></tr>
     * <tr><td><code>user.dir</code></td>
     *     <td>User's current working directory</td></tr>
     * </table>
     *
     * @exception  SecurityException  if the current thread cannot access the
     *               system properties.
     * @see        java.lang.SecurityException
     * @see        java.lang.SecurityManager#checkPropertiesAccess()
     * @see        java.util.Properties
     * @since      JDK1.0
     */
    public static Properties getProperties() {
	if (security != null) {
	    security.checkPropertiesAccess();
	}
	return props;
    }

    /**
     * Sets the system properties to the <code>Properties</code> 
     * argument. 
     * <p>
     * First, if there is a security manager, its 
     * <code>checkPropertiesAccess</code> method is called with no 
     * arguments. This may result in a security exception. 
     * <p>
     * The argument becomes the current set of system properties for use 
     * by the <code>getProperty</code> method. If the argument is 
     * <code>null</code>, then the current set of system properties is 
     * forgotten. 
     *
     * @param      props   the new system properties.
     * @exception  SecurityException  if the current thread cannot set the
     *               system properties.
     * @see        java.lang.SecurityException
     * @see        java.lang.SecurityManager#checkPropertiesAccess()
     * @since      JDK1.0
     */
    public static void setProperties(Properties props) {
	if (security != null) {
	    security.checkPropertiesAccess();
	}
	System.props = props;
    }
    
    /**
     * Gets the system property indicated by the specified key. 
     * <p>
     * First, if there is a security manager, its 
     * <code>checkPropertyAccess</code> method is called with the key as 
     * its argument. This may result in a system exception. 
     * <p>
     * If there is no current set of system properties, a set of system 
     * properties is first created and initialized in the same manner as 
     * for the <code>getProperties</code> method. 
     *
     * @param      key   the name of the system property.
     * @return     the string value of the system property,
     *             or <code>null</code> if there is no property with that key.
     * @exception  SecurityException  if the current thread cannot access the
     *               system properties or the specified property.
     * @see        java.lang.SecurityException
     * @see        java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
     * @see        java.lang.System#getProperties()
     * @since      JDK1.0
     */
    public static String getProperty(String key) {
	if (security != null) {
	    security.checkPropertyAccess(key);
	}
	return props.getProperty(key);
    }
    
    /**
     * Gets the system property indicated by the specified key. 
     * <p>
     * First, if there is a security manager, its 
     * <code>checkPropertyAccess</code> method is called with the 
     * <code>key</code> as its argument. 
     * <p>
     * If there is no current set of system properties, a set of system 
     * properties is first created and initialized in the same manner as 
     * for the <code>getProperties</code> method. 
     *
     * @param      key   the name of the system property.
     * @param      def   a default value.
     * @return     the string value of the system property,
     *             or the default value if there is no property with that key.
     * @exception  SecurityException  if the current thread cannot access the
     *               system properties or the specified property.
     * @see        java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
     * @see        java.lang.System#getProperties()
     * @since      JDK1.0
     */
    public static String getProperty(String key, String def) {
	if (security != null) {
	    security.checkPropertyAccess(key); 
	}
	return props.getProperty(key, def);
    }
    
    /**
     * Gets an environment variable. An environment variable is a
     * system dependent external variable that has a string value.
     * 
     * @param   the name of the environment variable.
     * @return 	the value of the variable, or null if the variable is
     *		not defined.
     * @since   JDK1.0
     * @deprecated
     */
    public static String getenv(String name) {
	throw new Error("getenv no longer supported, use properties and -D instead: " + name);
    }

    /**
     * Terminates the currently running Java Virtual Machine. The 
     * argument serves as a status code; by convention, a nonzero status 
     * code indicates abnormal termination. 
     * <p>
     * This method calls the <code>exit</code> method in class 
     * <code>Runtime</code>. This method never returns normally. 
     *
     * @param      status   exit status.
     * @exception  SecurityException  if the current thread cannot exit with
     *               the specified status.
     * @see        java.lang.Runtime#exit(int)
     * @since      JDK1.0
     */
    public static void exit(int status) {
	Runtime.getRuntime().exit(status);
    }

    /**
     * Runs the garbage collector.
     * <p>
     * Calling the <code>gc</code> method suggests that the Java Virtual 
     * Machine expend effort toward recycling unused objects in order to 
     * make the memory they currently occupy available for quick reuse. 
     * When control returns from the method call, the Java Virtual 
     * Machine has made a best effort to reclaim space from all unused 
     * objects.
     *
     * @see     java.lang.Runtime#gc()
     * @since   JDK1.0
     */
    public static void gc() {
	Runtime.getRuntime().gc();
    }

    /**
     * Runs the finalization methods of any objects pending finalization.
     * <p>
     * Calling this method suggests that the Java Virtual Machine expend 
     * effort toward running the <code>finalize</code> methods of objects 
     * that have been found to be discarded but whose <code>finalize</code> 
     * methods have not yet been run. When control returns from the 
     * method call, the Java Virtual Machine has made a best effort to 
     * complete all outstanding finalizations. 
     *
     * @see     java.lang.Runtime#runFinalization()
     * @since   JDK1.0
     */
    public static void runFinalization() {
	Runtime.getRuntime().runFinalization();
    }

    /**
     * Enable or disable finalization on exit; doing so specifies that the
     * finalizers of all objects that have finalizers that have not yet been
     * automatically invoked are to be run before the Java runtime exits.
     * By default, finalization on exit is disabled.
     * @see     java.lang.Runtime#exit(int)
     * @see     java.lang.Runtime#gc()
     * @since   JDK1.1
     */
    public static void runFinalizersOnExit(boolean value) {
	Runtime.getRuntime().runFinalizersOnExit(value);
    }

    /**
     * Loads the specified filename as a dynamic library. The filename 
     * argument must be a complete pathname. 
     * <p>
     * This method calls the <code>load</code> method in class 
     * <code>Runtime. </code> 
     *
     * @param      filename   the file to load.
     * @exception  SecurityException  if the current thread cannot load the
     *               specified dynamic library.
     * @exception  UnsatisfiedLinkError  if the file does not exist.
     * @see        java.lang.Runtime#load(java.lang.String)
     * @since      JDK1.0
     */
    public static void load(String filename) {
	Runtime.getRuntime().load(filename);
    }

    /**
     * Loads the system library specified by the <code>libname</code> 
     * argument. The manner in which a library name is mapped to the 
     * actual system library is system dependent. 
     *
     * @param      libname   the name of the library.
     * @exception  SecurityException  if the current thread cannot load the
     *               specified dynamic library.
     * @exception  UnsatisfiedLinkError  if the library does not exist.
     * @see        java.lang.Runtime#loadLibrary(java.lang.String)
     * @since      JDK1.0
     */
    public static void loadLibrary(String libname) {
	Runtime.getRuntime().loadLibrary(libname);
    }

    /**
     * The following two methods exist because in, out, and err must be
     * initialized to null.  The compiler, however, cannot be permitted to
     * inline access to them, since they are later set to more sensible values
     * by initializeSystemClass().
     */
    private static InputStream nullInputStream() throws NullPointerException {
	if (currentTimeMillis() > 0)
	    return null;
	throw new NullPointerException();
    }

    private static PrintStream nullPrintStream() throws NullPointerException {
	if (currentTimeMillis() > 0)
	    return null;
	throw new NullPointerException();
    }

    /**
     * Initialize the system class.  Called after thread initialization.
     */
    private static void initializeSystemClass() {
	props = new Properties();
	initProperties(props);
	FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
	FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
	FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
	setIn0(new BufferedInputStream(fdIn));
	setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true));
	setErr0(new PrintStream(new BufferedOutputStream(fdErr, 128), true));
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -