📄 system.java
字号:
/* System.java -- useful methods to interface with the system Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package java.lang;import gnu.classpath.SystemProperties;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.FileDescriptor;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.InputStream;import java.io.PrintStream;import java.util.Properties;import java.util.PropertyPermission;/** * System represents system-wide resources; things that represent the * general environment. As such, all methods are static. * * @author John Keiser * @author Eric Blake (ebb9@email.byu.edu) * @since 1.0 * @status still missing 1.4 functionality */public final class System{ // WARNING: System is a CORE class in the bootstrap cycle. See the comments // in vm/reference/java/lang/Runtime for implications of this fact. /** * The standard InputStream. This is assigned at startup and starts its * life perfectly valid. Although it is marked final, you can change it * using {@link #setIn(InputStream)} through some hefty VM magic. * * <p>This corresponds to the C stdin and C++ cin variables, which * typically input from the keyboard, but may be used to pipe input from * other processes or files. That should all be transparent to you, * however. */ public static final InputStream in = new BufferedInputStream(new FileInputStream(FileDescriptor.in)); /** * The standard output PrintStream. This is assigned at startup and * starts its life perfectly valid. Although it is marked final, you can * change it using {@link #setOut(PrintStream)} through some hefty VM magic. * * <p>This corresponds to the C stdout and C++ cout variables, which * typically output normal messages to the screen, but may be used to pipe * output to other processes or files. That should all be transparent to * you, however. */ public static final PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)), true); /** * The standard output PrintStream. This is assigned at startup and * starts its life perfectly valid. Although it is marked final, you can * change it using {@link #setErr(PrintStream)} through some hefty VM magic. * * <p>This corresponds to the C stderr and C++ cerr variables, which * typically output error messages to the screen, but may be used to pipe * output to other processes or files. That should all be transparent to * you, however. */ public static final PrintStream err = new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.err)), true); /** * This class is uninstantiable. */ private System() { } /** * Set {@link #in} to a new InputStream. This uses some VM magic to change * a "final" variable, so naturally there is a security check, * <code>RuntimePermission("setIO")</code>. * * @param in the new InputStream * @throws SecurityException if permission is denied * @since 1.1 */ public static void setIn(InputStream in) { SecurityManager sm = SecurityManager.current; // Be thread-safe. if (sm != null) sm.checkPermission(new RuntimePermission("setIO")); setIn0(in); } /** * Set {@link #out} to a new PrintStream. This uses some VM magic to change * a "final" variable, so naturally there is a security check, * <code>RuntimePermission("setIO")</code>. * * @param out the new PrintStream * @throws SecurityException if permission is denied * @since 1.1 */ public static void setOut(PrintStream out) { SecurityManager sm = SecurityManager.current; // Be thread-safe. if (sm != null) sm.checkPermission(new RuntimePermission("setIO")); setOut0(out); } /** * Set {@link #err} to a new PrintStream. This uses some VM magic to change * a "final" variable, so naturally there is a security check, * <code>RuntimePermission("setIO")</code>. * * @param err the new PrintStream * @throws SecurityException if permission is denied * @since 1.1 */ public static void setErr(PrintStream err) { SecurityManager sm = SecurityManager.current; // Be thread-safe. if (sm != null) sm.checkPermission(new RuntimePermission("setIO")); setErr0(err); } /** * Set the current SecurityManager. If a security manager already exists, * then <code>RuntimePermission("setSecurityManager")</code> is checked * first. Since this permission is denied by the default security manager, * setting the security manager is often an irreversible action. * * <STRONG>Spec Note:</STRONG> Don't ask me, I didn't write it. It looks * pretty vulnerable; whoever gets to the gate first gets to set the policy. * There is probably some way to set the original security manager as a * command line argument to the VM, but I don't know it. * * @param sm the new SecurityManager * @throws SecurityException if permission is denied */ public static synchronized void setSecurityManager(SecurityManager sm) { // Implementation note: the field lives in SecurityManager because of // bootstrap initialization issues. This method is synchronized so that // no other thread changes it to null before this thread makes the change. if (SecurityManager.current != null) SecurityManager.current.checkPermission (new RuntimePermission("setSecurityManager")); SecurityManager.current = sm; } /** * Get the current SecurityManager. If the SecurityManager has not been * set yet, then this method returns null. * * @return the current SecurityManager, or null */ public static SecurityManager getSecurityManager() { return SecurityManager.current; } /** * Get the current time, measured in the number of milliseconds from the * beginning of Jan. 1, 1970. This is gathered from the system clock, with * any attendant incorrectness (it may be timezone dependent). * * @return the current time * @see java.util.Date */ public static native long currentTimeMillis(); /** * Copy one array onto another from <code>src[srcStart]</code> ... * <code>src[srcStart+len-1]</code> to <code>dest[destStart]</code> ... * <code>dest[destStart+len-1]</code>. First, the arguments are validated: * neither array may be null, they must be of compatible types, and the * start and length must fit within both arrays. Then the copying starts, * and proceeds through increasing slots. If src and dest are the same * array, this will appear to copy the data to a temporary location first. * An ArrayStoreException in the middle of copying will leave earlier * elements copied, but later elements unchanged. * * @param src the array to copy elements from * @param srcStart the starting position in src * @param dest the array to copy elements to * @param destStart the starting position in dest * @param len the number of elements to copy * @throws NullPointerException if src or dest is null * @throws ArrayStoreException if src or dest is not an array, if they are * not compatible array types, or if an incompatible runtime type * is stored in dest * @throws IndexOutOfBoundsException if len is negative, or if the start or * end copy position in either array is out of bounds */ public static native void arraycopy(Object src, int srcStart, Object dest, int destStart, int len); /** * Get a hash code computed by the VM for the Object. This hash code will * be the same as Object's hashCode() method. It is usually some * convolution of the pointer to the Object internal to the VM. It * follows standard hash code rules, in that it will remain the same for a * given Object for the lifetime of that Object. * * @param o the Object to get the hash code for * @return the VM-dependent hash code for this Object * @since 1.1 */ public static native int identityHashCode(Object o); /** * Get all the system properties at once. A security check may be performed, * <code>checkPropertiesAccess</code>. Note that a security manager may * allow getting a single property, but not the entire group. * * <p>The required properties include: * <dl> * <dt>java.version</dt> <dd>Java version number</dd> * <dt>java.vendor</dt> <dd>Java vendor specific string</dd> * <dt>java.vendor.url</dt> <dd>Java vendor URL</dd> * <dt>java.home</dt> <dd>Java installation directory</dd> * <dt>java.vm.specification.version</dt> <dd>VM Spec version</dd> * <dt>java.vm.specification.vendor</dt> <dd>VM Spec vendor</dd> * <dt>java.vm.specification.name</dt> <dd>VM Spec name</dd> * <dt>java.vm.version</dt> <dd>VM implementation version</dd> * <dt>java.vm.vendor</dt> <dd>VM implementation vendor</dd> * <dt>java.vm.name</dt> <dd>VM implementation name</dd> * <dt>java.specification.version</dt> <dd>Java Runtime Environment version</dd> * <dt>java.specification.vendor</dt> <dd>Java Runtime Environment vendor</dd> * <dt>java.specification.name</dt> <dd>Java Runtime Environment name</dd> * <dt>java.class.version</dt> <dd>Java class version number</dd> * <dt>java.class.path</dt> <dd>Java classpath</dd> * <dt>java.library.path</dt> <dd>Path for finding Java libraries</dd> * <dt>java.io.tmpdir</dt> <dd>Default temp file path</dd> * <dt>java.compiler</dt> <dd>Name of JIT to use</dd> * <dt>java.ext.dirs</dt> <dd>Java extension path</dd> * <dt>os.name</dt> <dd>Operating System Name</dd> * <dt>os.arch</dt> <dd>Operating System Architecture</dd> * <dt>os.version</dt> <dd>Operating System Version</dd> * <dt>file.separator</dt> <dd>File separator ("/" on Unix)</dd> * <dt>path.separator</dt> <dd>Path separator (":" on Unix)</dd>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -