OSDN Git Service

c0de112499740c81a59f7c8e4f5d469a8366f48a
[pf3gnuchains/gcc-fork.git] / libjava / java / lang / System.java
1 // System.java - System-specific info.
2
3 /* Copyright (C) 1998, 1999  Red Hat, Inc.
4
5    This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9 details.  */
10
11 package java.lang;
12
13 import java.io.FileDescriptor;
14 import java.io.FileInputStream;
15 import java.io.FileOutputStream;
16 import java.io.FilterInputStream;
17 import java.io.InputStream;
18 import java.io.PrintStream;
19 import java.io.BufferedInputStream;
20 import java.io.BufferedOutputStream;
21 import java.util.Properties;
22
23 /**
24  * @author Tom Tromey <tromey@cygnus.com>
25  * @date August 27, 1998 
26  */
27
28 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
29  * "The Java Language Specification", ISBN 0-201-63451-1
30  * plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
31  * Status: 1.1.  Some 1.2 methods missing.  Properties code not fully
32  * implemented.
33  */
34
35 public final class System
36 {
37   public static native void arraycopy (Object src, int srcOffset,
38                                        Object dst, int dstOffset,
39                                        int count);
40
41   public static native long currentTimeMillis ();
42
43   public static void exit (int status)
44   {
45     Runtime.getRuntime().exit(status);
46   }
47
48   public static void gc ()
49   {
50     Runtime.getRuntime().gc();
51   }
52
53   // Marked deprecated in 1.1.  We implement what the JCL book says.
54   public static String getenv (String name)
55   {
56     throw new Error ();
57   }
58
59   private static native void init_properties ();
60
61   public static Properties getProperties ()
62   {
63     if (secman != null)
64       secman.checkPropertiesAccess();
65     init_properties ();
66     return properties;
67   }
68
69   public static String getProperty (String property)
70   {
71     if (secman != null)
72       secman.checkPropertyAccess(property);
73     init_properties ();
74     return properties.getProperty(property);
75   }
76
77   public static String getProperty (String property, String defval)
78   {
79     if (secman != null)
80       secman.checkPropertyAccess(property, defval);
81     init_properties ();
82     return properties.getProperty(property, defval);
83   }
84
85   public static SecurityManager getSecurityManager ()
86   {
87     return secman;
88   }
89
90   public static native int identityHashCode (Object obj);
91
92   public static void load (String pathname)
93   {
94     Runtime.getRuntime().load(pathname);
95   }
96
97   public static void loadLibrary (String libname)
98   {
99     Runtime.getRuntime().loadLibrary(libname);
100   }
101
102   public static void runFinalization ()
103   {
104     Runtime.getRuntime().runFinalization();
105   }
106
107   // Marked as deprecated in 1.2.
108   public static void runFinalizersOnExit (boolean run)
109   {
110     Runtime.getRuntime().runFinalizersOnExit(run);
111   }
112
113   private static void checkSetIO ()
114   {
115     // In 1.1, we are supposed to call checkExec, but the argument is
116     // not specified.  In 1.2, we are supposed to use checkPermission,
117     // which doesn't exist in 1.1.
118     if (secman != null)
119       secman.checkExec("");
120   }
121
122   public static native void setErr (PrintStream newErr);
123   public static native void setIn (InputStream newIn);
124   public static native void setOut (PrintStream newOut);
125
126   public static void setProperties (Properties props)
127   {
128     if (secman != null)
129       secman.checkPropertiesAccess();
130     // We might not have initialized yet.
131     prop_init = true;
132     properties = props;
133   }
134
135   // TODO 1.2.
136   // public static String setProperty (String key, String value);
137
138   // TODO 1.2.
139   // public static String mapLibraryName (String libname);
140
141   public static void setSecurityManager (SecurityManager s)
142   {
143     if (secman != null)
144       throw new SecurityException ();
145     secman = s;
146   }
147
148   // Public data.
149   public static final InputStream in = new BufferedInputStream (new FileInputStream (FileDescriptor.in));
150
151   public static final PrintStream out = new PrintStream (new BufferedOutputStream (new FileOutputStream (FileDescriptor.out)), true);
152
153   public static final PrintStream err = new PrintStream (new BufferedOutputStream (new FileOutputStream (FileDescriptor.err)), true);
154
155   // Don't allow System objects to be made.
156   private System ()
157   {
158   }
159
160   // Private data.
161   private static SecurityManager secman = null;
162   private static Properties properties = null;
163   // This boolean is only required for 1.1 and earlier.  After 1.1, a
164   // null properties should always be re-initialized.
165   private static boolean prop_init = false;
166 }