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

📄 system.java

📁 《移动Agent技术》一书的所有章节源代码。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * @(#)System.java	1.72 97/11/14
 * 
 * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of Sun
 * Microsystems, Inc. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Sun.
 * 
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
 * THIS SOFTWARE OR ITS DERIVATIVES.
 * 
 * CopyrightVersion 1.1_beta
 * 
 */

package java.lang;

import java.io.*;
import java.util.Properties;
import java.util.StringTokenizer;

/**
 * The <code>System</code> class contains several useful class fields 
 * and methods. It cannot be instantiated. 
 * <p>
 * Among the facilities provided by the <code>System</code> class 
 * are standard input, standard output, and error output streams; 
 * access to externally defined "properties"; a means of 
 * loading files and libraries; and a utility method for quickly 
 * copying a portion of an array. 
 *
 * @author  Arthur van Hoff 
 * @version 1.72, 11/14/97
 * @since   JDK1.0
 */
public final
class System {
    /** Don't let anyone instantiate this class */
    private System() {
    }

    /**
     * The "standard" input stream. This stream is already 
     * open and ready to supply input data. Typically this stream 
     * corresponds to keyboard input or another input source specified by 
     * the host environment or user. 
     *
     * @since   JDK1.0
     */
    public final static InputStream in = nullInputStream();

    /**
     * The "standard" output stream. This stream is already 
     * open and ready to accept output data. Typically this stream 
     * corresponds to display output or another output destination 
     * specified by the host environment or user. 
     * <p>
     * For simple stand-alone Java applications, a typical way to write 
     * a line of output data is: 
     * <ul><code>System.out.println(data)</code></ul>
     * <p>
     * See the <code>println</code> methods in class <code>PrintStream</code>. 
     *
     * @see     java.io.PrintStream#println()
     * @see     java.io.PrintStream#println(boolean)
     * @see     java.io.PrintStream#println(char)
     * @see     java.io.PrintStream#println(char[])
     * @see     java.io.PrintStream#println(double)
     * @see     java.io.PrintStream#println(float)
     * @see     java.io.PrintStream#println(int)
     * @see     java.io.PrintStream#println(long)
     * @see     java.io.PrintStream#println(java.lang.Object)
     * @see     java.io.PrintStream#println(java.lang.String)
     * @since   JDK1.0
     */
    public final static PrintStream out = nullPrintStream();

    /**
     * The "standard" error output stream. This stream is already 
     * open and ready to accept output data. 
     * <p>
     * Typically this stream corresponds to display output or another 
     * output destination specified by the host environment or user. By 
     * convention, this output stream is used to display error messages 
     * or other information that should come to the immediate attention 
     * of a user even if the principal output stream, the value of the 
     * variable <code>out</code>, has been redirected to a file or other 
     * destination that is typically not continuously monitored. 
     *
     * @since   JDK1.0
     */
    public final static PrintStream err = nullPrintStream();

    /* The security manager for the system.
     */
    private static SecurityManager security = null;

    /**
     * Reassigns the "standard" input stream.
     *
     * @since   JDK1.1
     */
    public static void setIn(InputStream in) {
	checkIO();
	setIn0(in);
    }

    /**
     * Reassigns the "standard" output stream.
     *
     * @since   JDK1.1
     */
    public static void setOut(PrintStream out) {
	checkIO();
	setOut0(out);
    }

    /**
     * Reassigns the "standard" error output stream.
     *
     * @since   JDK1.1
     */
    public static void setErr(PrintStream err) {
	checkIO();
	setErr0(err);
    }

    private static void checkIO() {
	if (security != null) {
	    /* REMIND: this should have its own security check call */
	    security.checkExec("setio");
	}
    }

    private static native void setIn0(InputStream in);
    private static native void setOut0(PrintStream out);
    private static native void setErr0(PrintStream err);

    /**
     * Sets the System security.
     * If a security manager has already been established for the 
     * currently running Java application, a <code>SecurityException</code> 
     * is thrown. Otherwise, the argument is established as the current 
     * security manager. If the argument is <code>null</code> and no 
     * security manager has been established, then no action is taken and 
     * the method simply returns. 
     *
     * @param      s   the security manager.
     * @exception  SecurityException  if the security manager has already
     *               been set.
     * @since   JDK1.0
     */
    public static void setSecurityManager(SecurityManager s) {
	if (security != null) {
	    throw new SecurityException("SecurityManager already set");
	}
	security = s;
    }

    /**
     * Gets the system security interface.
     *
     * @return  if a security manager has already been established for the
     *          current application, then that security manager is returned;
     *          otherwise, <code>null</code> is returned.
     * @since   JDK1.0
     */
    public static SecurityManager getSecurityManager() {
	return security;
    }

    /**
     * Returns the current time in milliseconds.
     * <p>
     * See the description of the class <code>Date</code> for a discussion 
     * of slight discrepancies that may arise between "computer 
     * time" and coordinated universal time (UTC). 
     *
     * @return  the difference, measured in milliseconds, between the current
     *          time and midnight, January 1, 1970 UTC.
     * @see     java.util.Date
     * @since   JDK1.0
     */
    public static native long currentTimeMillis();

    /** 
     * Copies an array from the specified source array, beginning at the
     * specified position, to the specified position of the destination array.
     * A subsequence of array components are copied from the source 
     * array referenced by <code>src</code> to the destination array 
     * referenced by <code>dst</code>. The number of components copied is 
     * equal to the <code>length</code> argument. The components at 
     * positions <code>srcOffset</code> through 
     * <code>srcOffset+length-1</code> in the source array are copied into 
     * positions <code>dstOffset</code> through 
     * <code>dstOffset+length-1</code>, respectively, of the destination 
     * array. 
     * <p>
     * If the <code>src</code> and <code>dst</code> arguments refer to the 
     * same array object, then the copying is performed as if the 
     * components at positions <code>srcOffset</code> through 
     * <code>srcOffset+length-1</code> were first copied to a temporary 
     * array with <code>length</code> components and then the contents of 
     * the temporary array were copied into positions 
     * <code>dstOffset</code> through <code>dstOffset+length-1</code> of the 
     * argument array. 
     * <p>
     * If any of the following is true, an 
     * <code>ArrayStoreException</code> is thrown and the destination is 
     * not modified: 
     * <ul>
     * <li>The <code>src</code> argument refers to an object that is not an 
     *     array. 
     * <li>The <code>dst</code> argument refers to an object that is not an 
     *     array. 
     * <li>The <code>src</code> argument and <code>dst</code> argument refer to 
     *     arrays whose component types are different primitive types. 
     * <li>The <code>src</code> argument refers to an array with a primitive 
     *     component type and the <code>dst</code> argument refers to an array 
     *     with a reference component type. 
     * <li>The <code>src</code> argument refers to an array with a reference 
     *     component type and the <code>dst</code> argument refers to an array 
     *     with a primitive component type. 
     * </ul>
     * <p>
     * Otherwise, if any of the following is true, an 
     * <code>ArrayIndexOutOfBoundsException</code> is 
     * thrown and the destination is not modified: 
     * <ul>
     * <li>The <code>srcOffset</code> argument is negative. 
     * <li>The <code>dstOffset</code> argument is negative. 
     * <li>The <code>length</code> argument is negative. 
     * <li><code>srcOffset+length</code> is greater than 
     *     <code>src.length</code>, the length of the source array. 
     * <li><code>dstOffset+length</code> is greater than 
     *     <code>dst.length</code>, the length of the destination array. 
     * </ul>
     * <p>
     * Otherwise, if any actual component of the source array from 
     * position <code>srcOffset</code> through 
     * <code>srcOffset+length-1</code> cannot be converted to the component 
     * type of the destination array by assignment conversion, an 
     * <code>ArrayStoreException</code> is thrown. In this case, let 
     * <b><i>k</i></b> be the smallest nonnegative integer less than 
     * length such that <code>src[srcOffset+</code><i>k</i><code>]</code> 
     * cannot be converted to the component type of the destination 
     * array; when the exception is thrown, source array components from 
     * positions <code>srcOffset</code> through
     * <code>srcOffset+</code><i>k</i><code>-1</code> 
     * will already have been copied to destination array positions 
     * <code>dstOffset</code> through
     * <code>dstOffset+</code><i>k</I><code>-1</code> and no other 
     * positions of the destination array will have been modified. 
     *
     * @param      src:      the source array.
     * @param      srcpos    start position in the source array.
     * @param      dest      the destination array.
     * @param      destpos   start position in the destination data.
     * @param      length    the number of array elements to be copied.
     * @exception  ArrayIndexOutOfBoundsException  if copying would cause
     *               access of data outside array bounds.
     * @exception  ArrayStoreException  if an element in the <code>src</code>
     *               array could not be stored into the <code>dest</code> array
     *               because of a type mismatch.
     * @since      JDK1.0
     */
    public static native void arraycopy(Object src, int src_position,
                                        Object dst, int dst_position,
                                        int length);

    /**
     * Returns the same hashcode for the given object as
     * would be returned by the default method hashCode(),
     * whether or not the given object's class overrides
     * hashCode().
     * The hashcode for the null reference is zero.
     *
     * @since   JDK1.1
     */
    public static native int identityHashCode(Object x);

    /**
     * System properties. The following properties are guaranteed to be defined:
     * <dl>
     * <dt>java.version		<dd>Java version number
     * <dt>java.vendor		<dd>Java vendor specific string
     * <dt>java.vendor.url	<dd>Java vendor URL
     * <dt>java.home		<dd>Java installation directory
     * <dt>java.class.version	<dd>Java class version number
     * <dt>java.class.path	<dd>Java classpath
     * <dt>os.name		<dd>Operating System Name
     * <dt>os.arch		<dd>Operating System Architecture
     * <dt>os.version		<dd>Operating System Version
     * <dt>file.separator	<dd>File separator ("/" on Unix)
     * <dt>path.separator	<dd>Path separator (":" on Unix)
     * <dt>line.separator	<dd>Line separator ("\n" on Unix)

⌨️ 快捷键说明

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