001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package java.lang;
028:
029: import java.io.*;
030: import com.sun.cldchi.io.*;
031:
032: /**
033: * The <code>System</code> class contains several useful class fields
034: * and methods. It cannot be instantiated.
035: *
036: * @version 12/17/01 (CLDC 1.1)
037: * @since JDK1.0, CLDC 1.0
038: */
039: public final class System {
040:
041: /** Don't let anyone instantiate this class */
042: private System() {
043: }
044:
045: /**
046: * The "standard" input stream. This stream is already
047: * open and ready to supply input data. Typically this stream
048: * corresponds to keyboard input or another input source specified by
049: * the host environment or user.
050: */
051: // public final static InputStream in = getConsoleInput();
052: // private static InputStream getConsoleInput() {
053: // return new ConsoleInputStream();
054: // }
055: /**
056: * The "standard" output stream. This stream is already
057: * open and ready to accept output data. Typically this stream
058: * corresponds to display output or another output destination
059: * specified by the host environment or user.
060: * <p>
061: * For simple stand-alone Java applications, a typical way to write
062: * a line of output data is:
063: * <blockquote><pre>
064: * System.out.println(data)
065: * </pre></blockquote>
066: * <p>
067: * See the <code>println</code> methods in class <code>PrintStream</code>.
068: *
069: * @see java.io.PrintStream#println()
070: * @see java.io.PrintStream#println(boolean)
071: * @see java.io.PrintStream#println(char)
072: * @see java.io.PrintStream#println(char[])
073: * @see java.io.PrintStream#println(int)
074: * @see java.io.PrintStream#println(long)
075: * @see java.io.PrintStream#println(java.lang.Object)
076: * @see java.io.PrintStream#println(java.lang.String)
077: */
078: public final static PrintStream out = new PrintStream(
079: new ConsoleOutputStream());
080:
081: /**
082: * The "standard" error output stream. This stream is already
083: * open and ready to accept output data.
084: * <p>
085: * Typically this stream corresponds to display output or another
086: * output destination specified by the host environment or user. By
087: * convention, this output stream is used to display error messages
088: * or other information that should come to the immediate attention
089: * of a user even if the principal output stream, the value of the
090: * variable <code>out</code>, has been redirected to a file or other
091: * destination that is typically not continuously monitored.
092: */
093: public final static PrintStream err = out;
094:
095: /**
096: * Returns the current time in milliseconds.
097: *
098: * @return the difference, measured in milliseconds, between the current
099: * time and midnight, January 1, 1970 UTC.
100: */
101: public static native long currentTimeMillis();
102:
103: /**
104: * Copies an array from the specified source array, beginning at the
105: * specified position, to the specified position of the destination array.
106: * A subsequence of array components are copied from the source
107: * array referenced by <code>src</code> to the destination array
108: * referenced by <code>dst</code>. The number of components copied is
109: * equal to the <code>length</code> argument. The components at
110: * positions <code>srcOffset</code> through
111: * <code>srcOffset+length-1</code> in the source array are copied into
112: * positions <code>dstOffset</code> through
113: * <code>dstOffset+length-1</code>, respectively, of the destination
114: * array.
115: * <p>
116: * If the <code>src</code> and <code>dst</code> arguments refer to the
117: * same array object, then the copying is performed as if the
118: * components at positions <code>srcOffset</code> through
119: * <code>srcOffset+length-1</code> were first copied to a temporary
120: * array with <code>length</code> components and then the contents of
121: * the temporary array were copied into positions
122: * <code>dstOffset</code> through <code>dstOffset+length-1</code> of the
123: * destination array.
124: * <p>
125: * If <code>dst</code> is <code>null</code>, then a
126: * <code>NullPointerException</code> is thrown.
127: * <p>
128: * If <code>src</code> is <code>null</code>, then a
129: * <code>NullPointerException</code> is thrown and the destination
130: * array is not modified.
131: * <p>
132: * Otherwise, if any of the following is true, an
133: * <code>ArrayStoreException</code> is thrown and the destination is
134: * not modified:
135: * <ul>
136: * <li>The <code>src</code> argument refers to an object that is not an
137: * array.
138: * <li>The <code>dst</code> argument refers to an object that is not an
139: * array.
140: * <li>The <code>src</code> argument and <code>dst</code> argument refer to
141: * arrays whose component types are different primitive types.
142: * <li>The <code>src</code> argument refers to an array with a primitive
143: * component type and the <code>dst</code> argument refers to an array
144: * with a reference component type.
145: * <li>The <code>src</code> argument refers to an array with a reference
146: * component type and the <code>dst</code> argument refers to an array
147: * with a primitive component type.
148: * </ul>
149: * <p>
150: * Otherwise, if any of the following is true, an
151: * <code>IndexOutOfBoundsException</code> is
152: * thrown and the destination is not modified:
153: * <ul>
154: * <li>The <code>srcOffset</code> argument is negative.
155: * <li>The <code>dstOffset</code> argument is negative.
156: * <li>The <code>length</code> argument is negative.
157: * <li><code>srcOffset+length</code> is greater than
158: * <code>src.length</code>, the length of the source array.
159: * <li><code>dstOffset+length</code> is greater than
160: * <code>dst.length</code>, the length of the destination array.
161: * </ul>
162: * <p>
163: * Otherwise, if any actual component of the source array from
164: * position <code>srcOffset</code> through
165: * <code>srcOffset+length-1</code> cannot be converted to the component
166: * type of the destination array by assignment conversion, an
167: * <code>ArrayStoreException</code> is thrown. In this case, let
168: * <i>k</i> be the smallest nonnegative integer less than
169: * length such that <code>src[srcOffset+</code><i>k</i><code>]</code>
170: * cannot be converted to the component type of the destination
171: * array; when the exception is thrown, source array components from
172: * positions <code>srcOffset</code> through
173: * <code>srcOffset+</code><i>k</i><code>-1</code>
174: * will already have been copied to destination array positions
175: * <code>dstOffset</code> through
176: * <code>dstOffset+</code><i>k</I><code>-1</code> and no other
177: * positions of the destination array will have been modified.
178: * (Because of the restrictions already itemized, this
179: * paragraph effectively applies only to the situation where both
180: * arrays have component types that are reference types.)
181: *
182: * @param src the source array.
183: * @param srcOffset start position in the source array.
184: * @param dst the destination array.
185: * @param dstOffset start position in the destination data.
186: * @param length the number of array elements to be copied.
187: * @exception IndexOutOfBoundsException if copying would cause
188: * access of data outside array bounds.
189: * @exception ArrayStoreException if an element in the <code>src</code>
190: * array could not be stored into the <code>dest</code> array
191: * because of a type mismatch.
192: * @exception NullPointerException if either <code>src</code> or
193: * <code>dst</code> is <code>null</code>.
194: */
195: public static native void arraycopy(Object src, int srcOffset,
196: Object dst, int dstOffset, int length);
197:
198: /**
199: * Returns the same hashcode for the given object as
200: * would be returned by the default method hashCode(),
201: * whether or not the given object's class overrides
202: * hashCode().
203: * The hashcode for the null reference is zero.
204: *
205: * @param x object for which the hashCode is to be calculated
206: * @return the hashCode
207: * @since JDK1.1
208: */
209: public static native int identityHashCode(Object x);
210:
211: /**
212: * Gets the system property indicated by the specified key.
213: *
214: * @param key the name of the system property.
215: * @return the string value of the system property,
216: * or <code>null</code> if there is no property with that key.
217: *
218: * @exception NullPointerException if <code>key</code> is
219: * <code>null</code>.
220: * @exception IllegalArgumentException if <code>key</code> is empty.
221: */
222: public static String getProperty(String key) {
223: if (key == null) {
224: throw new NullPointerException(
225: /* #ifdef VERBOSE_EXCEPTIONS */
226: /// skipped "key can't be null"
227: /* #endif */
228: );
229: }
230: if (key.equals("")) {
231: throw new IllegalArgumentException(
232: /* #ifdef VERBOSE_EXCEPTIONS */
233: /// skipped "key can't be empty"
234: /* #endif */
235: );
236: }
237: return getProperty0(key);
238: }
239:
240: private native static String getProperty0(String key);
241:
242: /**
243: * Terminates the currently running Java application. The
244: * argument serves as a status code; by convention, a nonzero
245: * status code indicates abnormal termination.
246: * <p>
247: * This method calls the <code>exit</code> method in class
248: * <code>Runtime</code>. This method never returns normally.
249: * <p>
250: * The call <code>System.exit(n)</code> is effectively equivalent
251: * to the call:
252: * <blockquote><pre>
253: * Runtime.getRuntime().exit(n)
254: * </pre></blockquote>
255: *
256: * @param status exit status.
257: * @see java.lang.Runtime#exit(int)
258: */
259: public static void exit(int status) {
260: Runtime.getRuntime().exit(status);
261: }
262:
263: /**
264: * Runs the garbage collector.
265: * <p>
266: * Calling the <code>gc</code> method suggests that the Java Virtual
267: * Machine expend effort toward recycling unused objects in order to
268: * make the memory they currently occupy available for quick reuse.
269: * When control returns from the method call, the Java Virtual
270: * Machine has made a best effort to reclaim space from all discarded
271: * objects.
272: * <p>
273: * The call <code>System.gc()</code> is effectively equivalent to the
274: * call:
275: * <blockquote><pre>
276: * Runtime.getRuntime().gc()
277: * </pre></blockquote>
278: *
279: * @see java.lang.Runtime#gc()
280: */
281: public static void gc() {
282: Runtime.getRuntime().gc();
283: }
284:
285: /*
286: * This method is called by compiled code to throw null pointer exceptions.
287: */
288: private static void throwNullPointerException() throws Throwable {
289: throw new NullPointerException();
290: }
291:
292: /*
293: * This method is called by compiled code to throw aioob exceptions.
294: */
295: private static void throwArrayIndexOutOfBoundsException()
296: throws Throwable {
297: throw new ArrayIndexOutOfBoundsException();
298: }
299:
300: /*
301: * This is a special VM method used for throwing exceptions inside
302: * quick native methods.
303: */
304: private static native void quickNativeThrow();
305: }
|