File: System.java

package info (click to toggle)
orp-classpath 1%3A0.02.1-3
  • links: PTS
  • area: contrib
  • in suites: woody
  • size: 15,212 kB
  • ctags: 16,077
  • sloc: java: 82,255; ansic: 12,779; sh: 6,321; makefile: 1,478; perl: 962; exp: 122; lisp: 115
file content (382 lines) | stat: -rwxr-xr-x 12,168 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/* java.lang.System
   Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the 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, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.

As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */


package java.lang;

import java.io.*;
import java.util.*;
import gnu.classpath.Configuration;

/**
 * System represents system-wide resources; things that
 * represent the general environment.  As such, all
 * methods are static.
 *
 * @author John Keiser
 * @version 1.1.0, Aug 8 1998
 * @since JDK1.0
 */

public class System
{

  static
  {
    if (Configuration.INIT_LOAD_LIBRARY)
      {
	System.loadLibrary ("javalang");
      }
  }

  /* This class is uninstantiable. */
  private System ()
  {
  }

  private static Properties properties;

	/** The standard InputStream.  This is assigned at
	 ** startup and starts its life perfectly valid.<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;

	/** The standard output PrintStream.  This is assigned at
	 ** startup and starts its life perfectly valid.<P>
	 ** This corresponds to the C stderr and C++ cerr
	 ** variables, which typically output 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;

	/** The standard error PrintStream.  This is assigned at
	 ** startup and starts its life perfectly valid.<P>
	 ** This corresponds to the C stdout and C++ cout
	 ** variables, which typically output 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;

  static
  {
    properties = new Properties ();
    VMSystem.insertSystemProperties (properties);
    insertGNUProperties ();
    in = new FileInputStream (FileDescriptor.in);
    out = new PrintStream (new FileOutputStream (FileDescriptor.out));
    err = new PrintStream (new FileOutputStream (FileDescriptor.err));
  }

	/** Set in to a new InputStream.
	 ** @param in the new InputStream.
	 ***/
  public static native void setIn (InputStream in);

	/** Set out to a new PrintStream.
	 ** @param out the new PrintStream.
	 ***/
  public static native void setOut (PrintStream out);

	/** Set err to a new PrintStream.
	 ** @param err the new PrintStream.
	 ***/
  public static native void setErr (PrintStream err);

	/** 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 Runtime.getSecurityManager ();
  }

	/** Set the current SecurityManager.
	 ** This may only be done once.  If you try to re-set the
	 ** current SecurityManager, then you will get a
	 ** SecurityException.  If you use null and there is no
	 ** SecurityManager set, then the state will not
	 ** change.<P>
	 ** <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.
	 **
	 ** @param securityManager the new SecurityManager.
	 ** @exception SecurityException if the SecurityManger is
	 **            already set.
	 **/
  public static void setSecurityManager (SecurityManager securityManager)
  {
    Runtime.setSecurityManager (securityManager);
  }

	/** 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.
	 **/
  public static native long currentTimeMillis ();

	/** Copy one array onto another from
	 ** <CODE>src[srcStart] ... src[srcStart+len]</CODE> to
	 ** <CODE>dest[destStart] ... dest[destStart+len]</CODE>
	 ** @param src the array to copy elements from
	 ** @param srcStart the starting position to copy elements
	 **        from in the src array
	 ** @param dest the array to copy elements to
	 ** @param destStart the starting position to copy
	 **        elements from in the src array
	 ** @param len the number of elements to copy
	 ** @exception ArrayStoreException if src or dest is not
	 **            an array, or if one is a primitive type
	 **            and the other is a reference type or a
	 **            different primitive type.  The array will
	 **            not be modified if any of these is the
	 **            case.  If there is an element in src that
	 **            is not assignable to dest's type, this will
	 **            be thrown and all elements up to but not
	 **            including that element will have been
	 **            modified.
	 ** @exception ArrayIndexOutOfBoundsException if len is
	 **            negative, or if the start or end copy
	 **            position in either array is out of bounds.
	 **            The array will not be modified if this
	 **            exception is thrown.
	 **/
  public static void arraycopy (Object src, int srcStart, Object dest,
				int destStart, int len)
  {
    VMSystem.arraycopy (src, srcStart, dest, destStart, 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
	 **/
  public static int identityHashCode (Object o)
  {
    return VMSystem.identityHashCode (o);
  }

	/** Get all the system properties at once.
	 ** @XXX list the standard system properties
	 ** @return the system properties
	 ** @exception SecurityException if thrown by
	 **            getSecurityManager().checkPropertiesAccess()
	 **/
  public static Properties getProperties ()
  {
    try
    {
      getSecurityManager ().checkPropertiesAccess ();
    }
    catch (NullPointerException e)
    {
    }
    return properties;
  }

	/** Set all the system properties at once.
	 ** @param properties the new set of system properties.
	 ** @exception SecurityException if thrown by
	 **            getSecurityManager().checkPropertiesAccess()
	 **/
  public static void setProperties (Properties properties)
  {
    try
    {
      getSecurityManager ().checkPropertiesAccess ();
    }
    catch (NullPointerException e)
    {
    }
    System.properties = properties;
  }


	/** Get a single system property by name.
	 ** @param name the name of the system property to get
	 ** @return the property, or null if not found.
	 ** @exception SecurityException if thrown by
	 **            getSecurityManager().checkPropertyAccess(name)
	 **/
  public static String getProperty (String name)
  {
    SecurityManager sm = getSecurityManager ();
    try
    {
      sm.checkPropertyAccess (name);
    }
    catch (NullPointerException e)
    {
    }
    return properties.getProperty (name);
  }

	/** Set a single system property by name.
	 ** @param name the name of the system property to set
	 ** @param value the new value of the system property
	 ** @return the old property value, or null if not yet set
	 ** @exception SecurityException if a SecurityManager is set
     **            and the caller doesn't have
	 **            <code>PropertyPermission(name, "write")</code>
	 **
	 ** @since 1.2
	 **/
  public static String setProperty (String name, String value)
  {
    SecurityManager sm = getSecurityManager ();
    if (sm != null)
      sm.checkPermission (new PropertyPermission (name, "write"));

    return (String) properties.setProperty (name, value);
  }

	/** Get a single property by name, with a possible default
	 ** value returned if not found.
	 ** @param name the name of the system property to set
	 ** @param def the default value to use if the
	 **        property does not exist.
	 ** @return the property, or default if not found.
	 ** @exception SecurityException if thrown by
	 **            getSecurityManager().checkPropertyAccess(name)
	 **/
  public static String getProperty (String name, String def)
  {
    try
    {
      getSecurityManager ().checkPropertyAccess (name);
    }
    catch (NullPointerException e)
    {
    }
    return properties.getProperty (name, def);
  }

	/** Get a single property by name.  Calls getProperty(name).
	 ** @deprecated use getProperty(name).
	 ** @see #getProperty(java.lang.String)
	 **/
  public static String getenv (String name)
  {
    return getProperty (name);
  }

	/** Helper method to exit the Java runtime using
	 ** <CODE>Runtime.getRuntime().exit()</CODE>.
	 ** @see java.lang.Runtime#exit(int)
	 **/
  public static void exit (int status)
  {
    Runtime.getRuntime ().exit (status);
  }

	/** Helper method to run the garbage collector using
	 ** <CODE>Runtime.getRuntime().gc()</CODE>.
	 ** @see java.lang.Runtime#gc()
	 **/
  public static void gc ()
  {
    Runtime.getRuntime ().gc ();
  }

	/** Helper method to run finalization using
	 ** <CODE>Runtime.getRuntime().runFinalization()</CODE>.
	 ** @see java.lang.Runtime#runFinalization()
	 **/
  public static void runFinalization ()
  {
    Runtime.getRuntime ().runFinalization ();
  }

	/** Tell the Runtime whether to run finalization before
	 ** exiting the JVM.  Just uses
	 ** <CODE>Runtime.getRuntime().runFinalizersOnExit()</CODE>.
	 ** @see java.lang.Runtime#runFinalizersOnExit()
	 **
	 ** @deprecated Since 1.2 this method is officially deprecated
	 ** because there is no guarantee and doing the actual finalization
	 ** on all objects is unsafe since not all (daemon) threads might
	 ** be finished with all objects when the VM terminates.
	 **/
  public static void runFinalizersOnExit (boolean finalizeOnExit)
  {
    Runtime.getRuntime ().runFinalizersOnExit (finalizeOnExit);
  }

	/** Helper method to load a library using its explicit
	 ** system-dependent filename.  This just calls
	 ** <CODE>Runtime.getRuntime().load(filename)</CODE>.
	 ** @see java.lang.Runtime#load(java.lang.String)
	 **/
  public static void load (String filename)
  {
    Runtime.getRuntime ().load (filename);
  }

	/** Helper method to load a library using just a
	 ** short identifier for the name.  This just calls
	 ** <CODE>Runtime.getRuntime().loadLibrary(libname)</CODE>.
	 ** @see java.lang.Runtime#loadLibrary(java.lang.String)
	 **/
  public static void loadLibrary (String libname)
  {
    Runtime.getRuntime ().loadLibrary (libname);
  }

  /** Add Classpath specific system properties.
   ** <br>
   ** Current properties:
   ** <br>
   ** <ul>
   **   <li> gnu.cpu.endian - big or little</li>
   ** </ul>
   **/
  static void insertGNUProperties ()
  {
    properties.put ("gnu.cpu.endian",
		    (isWordsBigEndian ())? "big" : "little");
  }

  static native boolean isWordsBigEndian ();
}