home *** CD-ROM | disk | FTP | other *** search
/ Print Shop Ensemble 3 / the-print-shop-ensemble-iii.iso / worldnet / disk2 / java.z / MOZ2_01.ZIP / java / lang / Runtime.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-03-08  |  4.0 KB  |  150 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 security = System.getSecurityManager();
  23.       if (security != null) {
  24.          security.checkExit(status);
  25.       }
  26.  
  27.       this.exitInternal(status);
  28.    }
  29.  
  30.    private native Process execInternal(String[] var1, String[] var2) throws IOException;
  31.  
  32.    public Process exec(String command) throws IOException {
  33.       return this.exec((String)command, (String[])null);
  34.    }
  35.  
  36.    public Process exec(String command, String[] envp) throws IOException {
  37.       int count = 0;
  38.       StringTokenizer st = new StringTokenizer(command);
  39.       count = st.countTokens();
  40.       String[] cmdarray = new String[count];
  41.       st = new StringTokenizer(command);
  42.  
  43.       for(int var8 = 0; st.hasMoreTokens(); cmdarray[var8++] = st.nextToken()) {
  44.       }
  45.  
  46.       SecurityManager security = System.getSecurityManager();
  47.       if (security != null) {
  48.          security.checkExec(cmdarray[0]);
  49.       }
  50.  
  51.       return this.execInternal(cmdarray, envp);
  52.    }
  53.  
  54.    public Process exec(String[] cmdarray) throws IOException {
  55.       return this.exec((String[])cmdarray, (String[])null);
  56.    }
  57.  
  58.    public Process exec(String[] cmdarray, String[] envp) throws IOException {
  59.       SecurityManager security = System.getSecurityManager();
  60.       if (security != null) {
  61.          security.checkExec(cmdarray[0]);
  62.       }
  63.  
  64.       return this.execInternal(cmdarray, envp);
  65.    }
  66.  
  67.    public native long freeMemory();
  68.  
  69.    public native long totalMemory();
  70.  
  71.    public native void gc();
  72.  
  73.    public native void runFinalization();
  74.  
  75.    public native void traceInstructions(boolean var1);
  76.  
  77.    public native void traceMethodCalls(boolean var1);
  78.  
  79.    private synchronized native String initializeLinkerInternal();
  80.  
  81.    private native String buildLibName(String var1, String var2);
  82.  
  83.    private native boolean loadFileInternal(String var1);
  84.  
  85.    private void initializeLinker() {
  86.       String ldpath = this.initializeLinkerInternal();
  87.       char c = System.getProperty("path.separator").charAt(0);
  88.       int ldlen = ldpath.length();
  89.       int i = ldpath.indexOf(c);
  90.  
  91.       int n;
  92.       for(n = 0; i >= 0; i = ldpath.indexOf(c, i + 1)) {
  93.          ++n;
  94.       }
  95.  
  96.       this.paths = new String[n + 1];
  97.       i = 0;
  98.       n = 0;
  99.  
  100.       for(int j = ldpath.indexOf(c); j >= 0; j = ldpath.indexOf(c, i)) {
  101.          if (j - i > 0) {
  102.             this.paths[n++] = ldpath.substring(i, j);
  103.          }
  104.  
  105.          i = j + 1;
  106.       }
  107.  
  108.       this.paths[n] = ldpath.substring(i, ldlen);
  109.    }
  110.  
  111.    public synchronized void load(String filename) {
  112.       SecurityManager security = System.getSecurityManager();
  113.       if (security != null) {
  114.          security.checkLink(filename);
  115.       }
  116.  
  117.       if (!this.loadFileInternal(filename)) {
  118.          throw new UnsatisfiedLinkError(filename);
  119.       }
  120.    }
  121.  
  122.    public synchronized void loadLibrary(String libname) {
  123.       SecurityManager security = System.getSecurityManager();
  124.       if (security != null) {
  125.          security.checkLink(libname);
  126.       }
  127.  
  128.       if (this.paths == null) {
  129.          this.initializeLinker();
  130.       }
  131.  
  132.       for(int i = 0; i < this.paths.length; ++i) {
  133.          String tempname = this.buildLibName(this.paths[i], libname);
  134.          if (this.loadFileInternal(tempname)) {
  135.             return;
  136.          }
  137.       }
  138.  
  139.       throw new UnsatisfiedLinkError("no " + libname + " in shared library path");
  140.    }
  141.  
  142.    public InputStream getLocalizedInputStream(InputStream in) {
  143.       return in;
  144.    }
  145.  
  146.    public OutputStream getLocalizedOutputStream(OutputStream out) {
  147.       return out;
  148.    }
  149. }
  150.