home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 January / PCO0198.ISO / 1&1 / java.z / java_301 / java / lang / Runtime.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-10-20  |  3.7 KB  |  130 lines

  1. package java.lang;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.OutputStream;
  6. import java.util.StringTokenizer;
  7.  
  8. public class Runtime {
  9.    private static Runtime currentRuntime = new Runtime();
  10.    private String[] paths;
  11.  
  12.    public static Runtime getRuntime() {
  13.       return currentRuntime;
  14.    }
  15.  
  16.    private Runtime() {
  17.    }
  18.  
  19.    private native void exitInternal(int var1);
  20.  
  21.    public void exit(int status) {
  22.       SecurityManager.checksExit(status);
  23.       this.exitInternal(status);
  24.    }
  25.  
  26.    private native Process execInternal(String[] var1, String[] var2) throws IOException;
  27.  
  28.    public Process exec(String command) throws IOException {
  29.       return this.exec((String)command, (String[])null);
  30.    }
  31.  
  32.    public Process exec(String command, String[] envp) throws IOException {
  33.       int count = 0;
  34.       StringTokenizer st = new StringTokenizer(command);
  35.       count = st.countTokens();
  36.       String[] cmdarray = new String[count];
  37.       st = new StringTokenizer(command);
  38.  
  39.       for(int var7 = 0; st.hasMoreTokens(); cmdarray[var7++] = st.nextToken()) {
  40.       }
  41.  
  42.       SecurityManager.checksExec(cmdarray[0]);
  43.       return this.execInternal(cmdarray, envp);
  44.    }
  45.  
  46.    public Process exec(String[] cmdarray) throws IOException {
  47.       return this.exec((String[])cmdarray, (String[])null);
  48.    }
  49.  
  50.    public Process exec(String[] cmdarray, String[] envp) throws IOException {
  51.       SecurityManager.checksExec(cmdarray[0]);
  52.       return this.execInternal(cmdarray, envp);
  53.    }
  54.  
  55.    public native long freeMemory();
  56.  
  57.    public native long totalMemory();
  58.  
  59.    public native void gc();
  60.  
  61.    public native void runFinalization();
  62.  
  63.    public native void traceInstructions(boolean var1);
  64.  
  65.    public native void traceMethodCalls(boolean var1);
  66.  
  67.    private synchronized native String initializeLinkerInternal();
  68.  
  69.    private native String buildLibName(String var1, String var2);
  70.  
  71.    private native boolean loadFileInternal(String var1);
  72.  
  73.    private void initializeLinker() {
  74.       String ldpath = this.initializeLinkerInternal();
  75.       char c = System.getProperty("path.separator").charAt(0);
  76.       int ldlen = ldpath.length();
  77.       int i = ldpath.indexOf(c);
  78.  
  79.       int n;
  80.       for(n = 0; i >= 0; i = ldpath.indexOf(c, i + 1)) {
  81.          ++n;
  82.       }
  83.  
  84.       this.paths = new String[n + 1];
  85.       i = 0;
  86.       n = 0;
  87.  
  88.       for(int j = ldpath.indexOf(c); j >= 0; j = ldpath.indexOf(c, i)) {
  89.          if (j - i > 0) {
  90.             this.paths[n++] = ldpath.substring(i, j);
  91.          }
  92.  
  93.          i = j + 1;
  94.       }
  95.  
  96.       this.paths[n] = ldpath.substring(i, ldlen);
  97.    }
  98.  
  99.    public synchronized void load(String filename) {
  100.       SecurityManager.checksLink(filename, 1);
  101.       if (!this.loadFileInternal(filename)) {
  102.          throw new UnsatisfiedLinkError(filename);
  103.       }
  104.    }
  105.  
  106.    public synchronized void loadLibrary(String libname) {
  107.       SecurityManager.checksLink(libname, 1);
  108.       if (this.paths == null) {
  109.          this.initializeLinker();
  110.       }
  111.  
  112.       for(int i = 0; i < this.paths.length; ++i) {
  113.          String tempname = this.buildLibName(this.paths[i], libname);
  114.          if (this.loadFileInternal(tempname)) {
  115.             return;
  116.          }
  117.       }
  118.  
  119.       throw new UnsatisfiedLinkError("no " + libname + " in shared library path");
  120.    }
  121.  
  122.    public InputStream getLocalizedInputStream(InputStream in) {
  123.       return in;
  124.    }
  125.  
  126.    public OutputStream getLocalizedOutputStream(OutputStream out) {
  127.       return out;
  128.    }
  129. }
  130.