/[classpath]/classpath/java/lang/System.java
ViewVC logotype

Diff of /classpath/java/lang/System.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by mark, Mon Jan 8 23:10:32 2001 UTC revision 1.11 by cbj, Fri Sep 21 04:22:07 2001 UTC
# Line 29  package java.lang; Line 29  package java.lang;
29    
30  import java.io.*;  import java.io.*;
31  import java.util.*;  import java.util.*;
32    import gnu.classpath.Configuration;
33    
34  /**  /**
35   ** System represents system-wide resources; things that   * System represents system-wide resources; things that
36   ** represent the general environment.  As such, all   * represent the general environment.  As such, all
37   ** methods are static.   * methods are static.
38   **   *
39   ** @author John Keiser   * @author John Keiser
40   ** @version 1.1.0, Aug 8 1998   * @version 1.1.0, Aug 8 1998
41   ** @since JDK1.0   * @since JDK1.0
42   **/   */
   
 public class System {  
         /* This class is uninstantiable. */  
         private System() { }  
43    
44          private static Properties properties;  public class System
45    {
46    
47      static
48      {
49        if (Configuration.INIT_LOAD_LIBRARY)
50          {
51            System.loadLibrary ("javalang");
52          }
53      }
54    
55      /* This class is uninstantiable. */
56      private System ()
57      {
58      }
59    
60      private static Properties properties;
61    
62          /** The standard InputStream.  This is assigned at          /** The standard InputStream.  This is assigned at
63           ** startup and starts its life perfectly valid.<P>           ** startup and starts its life perfectly valid.<P>
# Line 54  public class System { Line 67  public class System {
67           ** or files.  That should all be transparent to you,           ** or files.  That should all be transparent to you,
68           ** however.           ** however.
69           **/           **/
70          public static final InputStream in;    public static final InputStream in;
71    
72          /** The standard output PrintStream.  This is assigned at          /** The standard output PrintStream.  This is assigned at
73           ** startup and starts its life perfectly valid.<P>           ** startup and starts its life perfectly valid.<P>
# Line 64  public class System { Line 77  public class System {
77           ** or files.  That should all be transparent to you,           ** or files.  That should all be transparent to you,
78           ** however.           ** however.
79           **/           **/
80          public static final PrintStream out;    public static final PrintStream out;
81    
82          /** The standard error PrintStream.  This is assigned at          /** The standard error PrintStream.  This is assigned at
83           ** startup and starts its life perfectly valid.<P>           ** startup and starts its life perfectly valid.<P>
# Line 74  public class System { Line 87  public class System {
87           ** or files.  That should all be transparent to you,           ** or files.  That should all be transparent to you,
88           ** however.           ** however.
89           **/           **/
90          public static final PrintStream err;    public static final PrintStream err;
91    
92          static {    static
93                  properties = new Properties();    {
94                  VMSystem.insertSystemProperties(properties);      properties = new Properties ();
95                  insertGNUProperties ();      VMSystem.insertSystemProperties (properties);
96                  in = new FileInputStream(FileDescriptor.in);      insertGNUProperties ();
97                  out = new PrintStream(new FileOutputStream(FileDescriptor.out));      in = new FileInputStream (FileDescriptor.in);
98                  err = new PrintStream(new FileOutputStream(FileDescriptor.err));      out = new PrintStream (new FileOutputStream (FileDescriptor.out));
99          }      err = new PrintStream (new FileOutputStream (FileDescriptor.err));
100      }
101    
102          /** Set in to a new InputStream.          /** Set in to a new InputStream.
103           ** @param in the new InputStream.           ** @param in the new InputStream.
104           ***/           ***/
105          public static native void setIn(InputStream in);    public static native void setIn (InputStream in);
106    
107          /** Set out to a new PrintStream.          /** Set out to a new PrintStream.
108           ** @param out the new PrintStream.           ** @param out the new PrintStream.
109           ***/           ***/
110          public static native void setOut(PrintStream out);    public static native void setOut (PrintStream out);
111    
112          /** Set err to a new PrintStream.          /** Set err to a new PrintStream.
113           ** @param err the new PrintStream.           ** @param err the new PrintStream.
114           ***/           ***/
115          public static native void setErr(PrintStream err);    public static native void setErr (PrintStream err);
116    
117          /** Get the current SecurityManager.          /** Get the current SecurityManager.
118           ** If the SecurityManager has not been set yet, then this           ** If the SecurityManager has not been set yet, then this
119           ** method returns null.           ** method returns null.
120           ** @return the current SecurityManager, or null.           ** @return the current SecurityManager, or null.
121           **/           **/
122          public static SecurityManager getSecurityManager() {    public static SecurityManager getSecurityManager ()
123                  return Runtime.getSecurityManager();    {
124          }      return Runtime.getSecurityManager ();
125      }
126    
127          /** Set the current SecurityManager.          /** Set the current SecurityManager.
128           ** This may only be done once.  If you try to re-set the           ** This may only be done once.  If you try to re-set the
# Line 123  public class System { Line 138  public class System {
138           ** @exception SecurityException if the SecurityManger is           ** @exception SecurityException if the SecurityManger is
139           **            already set.           **            already set.
140           **/           **/
141          public static void setSecurityManager(SecurityManager securityManager) {    public static void setSecurityManager (SecurityManager securityManager)
142              Runtime.setSecurityManager(securityManager);    {
143          }      Runtime.setSecurityManager (securityManager);
144      }
145    
146          /** Get the current time, measured in the number of          /** Get the current time, measured in the number of
147           ** milliseconds from the beginning of Jan. 1, 1970.           ** milliseconds from the beginning of Jan. 1, 1970.
# Line 134  public class System { Line 150  public class System {
150           ** dependent).           ** dependent).
151           ** @return the current time.           ** @return the current time.
152           **/           **/
153          public static native long currentTimeMillis();    public static native long currentTimeMillis ();
154    
155          /** Copy one array onto another from          /** Copy one array onto another from
156           ** <CODE>src[srcStart] ... src[srcStart+len]</CODE> to           ** <CODE>src[srcStart] ... src[srcStart+len]</CODE> to
# Line 162  public class System { Line 178  public class System {
178           **            The array will not be modified if this           **            The array will not be modified if this
179           **            exception is thrown.           **            exception is thrown.
180           **/           **/
181          public static void arraycopy(Object src, int srcStart, Object dest, int destStart, int len) {    public static void arraycopy (Object src, int srcStart, Object dest,
182                  VMSystem.arraycopy(src,srcStart,dest,destStart,len);                                  int destStart, int len)
183          }    {
184        VMSystem.arraycopy (src, srcStart, dest, destStart, len);
185      }
186    
187          /** Get a hash code computed by the VM for the Object.          /** Get a hash code computed by the VM for the Object.
188           ** This hash code will be the same as Object's hashCode()           ** This hash code will be the same as Object's hashCode()
# Line 175  public class System { Line 193  public class System {
193           ** @param o the Object to get the hash code for           ** @param o the Object to get the hash code for
194           ** @return the VM-dependent hash code for this Object           ** @return the VM-dependent hash code for this Object
195           **/           **/
196          public static int identityHashCode(Object o) {    public static int identityHashCode (Object o)
197                  return VMSystem.identityHashCode(o);    {
198          }      return VMSystem.identityHashCode (o);
199      }
200    
201          /** Get all the system properties at once.          /** Get all the system properties at once.
202           ** @XXX list the standard system properties           ** @XXX list the standard system properties
# Line 185  public class System { Line 204  public class System {
204           ** @exception SecurityException if thrown by           ** @exception SecurityException if thrown by
205           **            getSecurityManager().checkPropertiesAccess()           **            getSecurityManager().checkPropertiesAccess()
206           **/           **/
207          public static Properties getProperties() {    public static Properties getProperties ()
208                  try {    {
209                          getSecurityManager().checkPropertiesAccess();                        try
210                  } catch(NullPointerException e) {      {
211                  }        getSecurityManager ().checkPropertiesAccess ();
212                  return properties;      }
213          }      catch (NullPointerException e)
214        {
215        }
216        return properties;
217      }
218    
219          /** Set all the system properties at once.          /** Set all the system properties at once.
220           ** @param properties the new set of system properties.           ** @param properties the new set of system properties.
221           ** @exception SecurityException if thrown by           ** @exception SecurityException if thrown by
222           **            getSecurityManager().checkPropertiesAccess()           **            getSecurityManager().checkPropertiesAccess()
223           **/           **/
224          public static void setProperties(Properties properties) {    public static void setProperties (Properties properties)
225                  try {    {
226                          getSecurityManager().checkPropertiesAccess();                        try
227                  } catch(NullPointerException e) {      {
228                  }        getSecurityManager ().checkPropertiesAccess ();
229                  System.properties = properties;      }
230          }      catch (NullPointerException e)
231        {
232        }
233        System.properties = properties;
234      }
235    
236    
237          /** Get a single system property by name.          /** Get a single system property by name.
# Line 213  public class System { Line 240  public class System {
240           ** @exception SecurityException if thrown by           ** @exception SecurityException if thrown by
241           **            getSecurityManager().checkPropertyAccess(name)           **            getSecurityManager().checkPropertyAccess(name)
242           **/           **/
243          public static String getProperty(String name) {    public static String getProperty (String name)
244                  SecurityManager sm = getSecurityManager();    {
245                  try {      SecurityManager sm = getSecurityManager ();
246                          sm.checkPropertyAccess(name);      try
247                  } catch(NullPointerException e) {      {
248                  }        sm.checkPropertyAccess (name);
249                  return properties.getProperty(name);      }
250          }      catch (NullPointerException e)
251        {
252        }
253        return properties.getProperty (name);
254      }
255    
256          /** Set a single system property by name.          /** Set a single system property by name.
257           ** @param name the name of the system property to set           ** @param name the name of the system property to set
# Line 232  public class System { Line 263  public class System {
263           **           **
264           ** @since 1.2           ** @since 1.2
265           **/           **/
266          public static String setProperty(String name, String value) {    public static String setProperty (String name, String value)
267              SecurityManager sm = getSecurityManager();    {
268          if (sm != null)      SecurityManager sm = getSecurityManager ();
269              sm.checkPermission(new PropertyPermission(name, "write"));      if (sm != null)
270                  sm.checkPermission (new PropertyPermission (name, "write"));
271          return (String)properties.setProperty(name, value);  
272          }      return (String) properties.setProperty (name, value);
273      }
274    
275          /** Get a single property by name, with a possible default          /** Get a single property by name, with a possible default
276           ** value returned if not found.           ** value returned if not found.
# Line 249  public class System { Line 281  public class System {
281           ** @exception SecurityException if thrown by           ** @exception SecurityException if thrown by
282           **            getSecurityManager().checkPropertyAccess(name)           **            getSecurityManager().checkPropertyAccess(name)
283           **/           **/
284          public static String getProperty(String name, String def) {    public static String getProperty (String name, String def)
285                  try {    {
286                          getSecurityManager().checkPropertyAccess(name);      try
287                  } catch(NullPointerException e) {      {
288                  }        getSecurityManager ().checkPropertyAccess (name);
289                  return properties.getProperty(name,def);      }
290          }      catch (NullPointerException e)
291        {
292        }
293        return properties.getProperty (name, def);
294      }
295    
296          /** Get a single property by name.  Calls getProperty(name).          /** Get a single property by name.  Calls getProperty(name).
297           ** @deprecated use getProperty(name).           ** @deprecated use getProperty(name).
298           ** @see #getProperty(java.lang.String)           ** @see #getProperty(java.lang.String)
299           **/           **/
300          public static String getenv(String name) {    public static String getenv (String name)
301                  return getProperty(name);    {
302          }      return getProperty (name);
303      }
304    
305          /** Helper method to exit the Java runtime using          /** Helper method to exit the Java runtime using
306           ** <CODE>Runtime.getRuntime().exit()</CODE>.           ** <CODE>Runtime.getRuntime().exit()</CODE>.
307           ** @see java.lang.Runtime#exit(int)           ** @see java.lang.Runtime#exit(int)
308           **/           **/
309          public static void exit(int status) {    public static void exit (int status)
310                  Runtime.getRuntime().exit(status);    {
311          }      Runtime.getRuntime ().exit (status);
312      }
313    
314          /** Helper method to run the garbage collector using          /** Helper method to run the garbage collector using
315           ** <CODE>Runtime.getRuntime().gc()</CODE>.           ** <CODE>Runtime.getRuntime().gc()</CODE>.
316           ** @see java.lang.Runtime#gc()           ** @see java.lang.Runtime#gc()
317           **/           **/
318          public static void gc() {    public static void gc ()
319                  Runtime.getRuntime().gc();    {
320          }      Runtime.getRuntime ().gc ();
321      }
322    
323          /** Helper method to run finalization using          /** Helper method to run finalization using
324           ** <CODE>Runtime.getRuntime().runFinalization()</CODE>.           ** <CODE>Runtime.getRuntime().runFinalization()</CODE>.
325           ** @see java.lang.Runtime#runFinalization()           ** @see java.lang.Runtime#runFinalization()
326           **/           **/
327          public static void runFinalization() {    public static void runFinalization ()
328                  Runtime.getRuntime().runFinalization();    {
329          }      Runtime.getRuntime ().runFinalization ();
330      }
331    
332          /** Tell the Runtime whether to run finalization before          /** Tell the Runtime whether to run finalization before
333           ** exiting the JVM.  Just uses           ** exiting the JVM.  Just uses
# Line 299  public class System { Line 339  public class System {
339           ** on all objects is unsafe since not all (daemon) threads might           ** on all objects is unsafe since not all (daemon) threads might
340           ** be finished with all objects when the VM terminates.           ** be finished with all objects when the VM terminates.
341           **/           **/
342          public static void runFinalizersOnExit(boolean finalizeOnExit) {    public static void runFinalizersOnExit (boolean finalizeOnExit)
343                  Runtime.getRuntime().runFinalizersOnExit(finalizeOnExit);    {
344          }      Runtime.getRuntime ().runFinalizersOnExit (finalizeOnExit);
345      }
346    
347          /** Helper method to load a library using its explicit          /** Helper method to load a library using its explicit
348           ** system-dependent filename.  This just calls           ** system-dependent filename.  This just calls
349           ** <CODE>Runtime.getRuntime().load(filename)</CODE>.           ** <CODE>Runtime.getRuntime().load(filename)</CODE>.
350           ** @see java.lang.Runtime#load(java.lang.String)           ** @see java.lang.Runtime#load(java.lang.String)
351           **/           **/
352          public static void load(String filename) {    public static void load (String filename)
353                  Runtime.getRuntime().load(filename);    {
354          }      Runtime.getRuntime ().load (filename);
355      }
356    
357          /** Helper method to load a library using just a          /** Helper method to load a library using just a
358           ** short identifier for the name.  This just calls           ** short identifier for the name.  This just calls
359           ** <CODE>Runtime.getRuntime().loadLibrary(libname)</CODE>.           ** <CODE>Runtime.getRuntime().loadLibrary(libname)</CODE>.
360           ** @see java.lang.Runtime#loadLibrary(java.lang.String)           ** @see java.lang.Runtime#loadLibrary(java.lang.String)
361           **/           **/
362          public static void loadLibrary(String libname) {    public static void loadLibrary (String libname)
363                  Runtime.getRuntime().loadLibrary(libname);    {
364          }      Runtime.getRuntime ().loadLibrary (libname);
365      }
366    
367    /** Add Classpath specific system properties.    /** Add Classpath specific system properties.
368     ** <br>     ** <br>
# Line 331  public class System { Line 374  public class System {
374     **/     **/
375    static void insertGNUProperties ()    static void insertGNUProperties ()
376    {    {
377      properties.put ("gnu.cpu.endian",      properties.put ("gnu.cpu.endian",
378                      (isWordsBigEndian ()) ? "big" : "little");                      (isWordsBigEndian ())? "big" : "little");
379    }    }
380    
381    static native boolean isWordsBigEndian ();    static native boolean isWordsBigEndian ();

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26