/Users/lyon/j4p/src/futils/Exec.java
|
1 package futils;
2
3 import java.io.IOException;
4
5 public class Exec {
6 Runtime rt = Runtime.getRuntime();
7
8 public static void main(String args[]) {
9 Exec e =
10 new Exec();
11 e.printRam();
12 }
13
14 public void setMethodTrace(boolean t) {
15 rt.traceMethodCalls(t);
16 }
17
18 public void setInstructionTrace(boolean t) {
19 rt.traceInstructions(t);
20 }
21
22 public void run(String s) {
23 try {
24 rt.exec(s);
25 } catch (IOException e) {
26 System.err.println("Exec error:" + e);
27 }
28 }
29
30 public String getPrintRamString() {
31 return "free " + getFreeRam()
32 + " bytes out of "
33 + getTotalRam() + " bytes\n" +
34 getFreeRatioPercent() + " percent free";
35 }
36
37 public void printRam() {
38 System.out.println(getPrintRamString());
39 }
40
41 public long getFreeRam() {
42 return rt.freeMemory();
43 }
44
45 public long getTotalRam() {
46 return rt.totalMemory();
47 }
48
49 public int getFreeRatioPercent() {
50 return (int) (100 * getFreeRam() / (float) getTotalRam());
51 }
52 }
53