1 17 package org.apache.excalibur.util; 18 19 29 public final class SystemUtil 30 { 31 private static final int m_processors; 32 private static final String m_cpuInfo; 33 private static final String m_architecture; 34 private static final String m_osName; 35 private static final String m_osVersion; 36 37 static 38 { 39 m_architecture = System.getProperty( "os.arch" ); 40 m_osName = System.getProperty( "os.name" ); 41 m_osVersion = System.getProperty( "os.version" ); 42 int procs = 0; 43 String info = ""; 44 45 try 46 { 47 String name = "org.apache.excalibur.util.system." + 48 stripWhitespace( m_osName ); 49 Class klass = Class.forName( name ); 50 CPUParser parser = (CPUParser)klass.newInstance(); 51 52 procs = parser.numProcessors(); 53 info = parser.cpuInfo(); 54 } 55 catch( Exception e ) 56 { 57 String proc = System.getProperty( "os.arch.cpus", "1" ); 58 info = System.getProperty( 59 "os.arch.info", 60 m_architecture + 61 " Family n, Model n, Stepping n, Undeterminable" 62 ); 63 64 procs = Integer.parseInt( proc ); 65 } 66 67 m_processors = procs; 68 m_cpuInfo = info; 69 } 70 71 77 private static String stripWhitespace( String mosname ) 78 { 79 final StringBuffer sb = new StringBuffer (); 80 81 final int size = mosname.length(); 82 for( int i = 0; i < size; i++ ) 83 { 84 final char ch = mosname.charAt( i ); 85 if( ch != '\t' && ch != '\r' && 86 ch != '\n' && ch != '\b' ) 87 { 88 sb.append( ch ); 89 } 90 } 91 92 return sb.toString(); 93 } 94 95 96 private SystemUtil() 97 { 98 } 99 100 104 public static final int numProcessors() 105 { 106 return m_processors; 107 } 108 109 public static final String cpuInfo() 110 { 111 return m_cpuInfo; 112 } 113 114 117 public static final String architecture() 118 { 119 return m_architecture; 120 } 121 122 125 public static final String operatingSystem() 126 { 127 return m_osName; 128 } 129 130 133 public static final String osVersion() 134 { 135 return m_osVersion; 136 } 137 } 138 139 | Popular Tags |