1 64 65 package com.jcorporate.expresso.core.utility; 66 67 import java.net.InetAddress ; 68 import java.net.UnknownHostException ; 69 70 71 74 public class SystemInfo { 75 public SystemInfo() { 76 } 77 78 83 public static int getTotalMem() { 84 int totalMemory = (int) m_runtime.totalMemory() / 1024; 85 86 return totalMemory; 87 } 88 89 94 public static int getUsedMem() { 95 int totalMem = getTotalMem(); 96 int freeMem = getFreeMem(); 97 int memUsage = (totalMem - freeMem); 98 99 return memUsage; 100 } 101 102 107 public static int getFreeMem() { 108 int freeMemory = (int) m_runtime.freeMemory() / 1024; 109 110 return freeMemory; 111 } 112 113 118 public static int getLoadAverage() { 119 return 1; 120 } 121 122 public static double getPowerFactor() { 123 double powerFactor = 1; 124 125 return powerFactor; 126 } 127 128 134 public static String getHostName() { 135 String hostName = "unknown"; 136 137 try { 138 InetAddress netAddress = InetAddress.getLocalHost(); 139 hostName = netAddress.getHostName(); 140 if (hostName == null) { 141 hostName = "unknown"; 142 } 143 } catch (UnknownHostException e) { 144 System.err.println("Cannot get host name"); 145 } 146 147 return hostName; 148 } 149 150 156 public static String getOSName() { 157 return System.getProperty("os.name"); 158 } 159 160 165 public static String getOSClass() { 166 String osName = getOSName(); 167 String ret = null; 168 169 if (osName.startsWith("Windows")) { 170 ret = "MSWIN"; 171 } else { 172 ret = "Unix"; 173 } 174 175 return ret; 176 } 177 178 181 private static Runtime m_runtime = Runtime.getRuntime(); 182 } | Popular Tags |