2 * environment information
4 * License : The MIT License
5 * Copyright(c) 2009 olyutorskii
8 package jp.sfjp.jindolf.config;
11 import java.text.NumberFormat;
13 import java.util.SortedMap;
14 import java.util.TreeMap;
19 public final class EnvInfo{
22 public static final String OS_NAME;
24 public static final String OS_VERSION;
26 public static final String OS_ARCH;
28 public static final String JAVA_VENDOR;
30 public static final String JAVA_VERSION;
33 public static final long MAX_MEMORY;
35 private static final SortedMap<String, String> PROPERTY_MAP =
38 private static final SortedMap<String, String> ENVIRONMENT_MAP =
41 private static final String[] CLASSPATHS;
44 OS_NAME = getSecureProperty("os.name");
45 OS_VERSION = getSecureProperty("os.version");
46 OS_ARCH = getSecureProperty("os.arch");
47 JAVA_VENDOR = getSecureProperty("java.vendor");
48 JAVA_VERSION = getSecureProperty("java.version");
50 getSecureEnvironment("LANG");
51 getSecureEnvironment("DISPLAY");
53 Runtime runtime = Runtime.getRuntime();
54 MAX_MEMORY = runtime.maxMemory();
56 String classpath = getSecureProperty("java.class.path");
58 if(classpath != null){
59 pathVec = classpath.split(File.pathSeparator);
61 pathVec = new String[0];
72 throw new AssertionError();
79 * @return プロパティ値。セキュリティ上読み込み禁止の場合はnull。
81 private static String getSecureProperty(String key){
84 result = System.getProperty(key);
85 if(result != null) PROPERTY_MAP.put(key, result);
86 }catch(SecurityException e){
95 * @return 環境変数値。セキュリティ上読み込み禁止の場合はnull。
97 private static String getSecureEnvironment(String name){
100 result = System.getenv(name);
101 if(result != null) ENVIRONMENT_MAP.put(name, result);
102 }catch(SecurityException e){
112 public static String getVMInfo(){
113 StringBuilder result = new StringBuilder();
114 NumberFormat nform = NumberFormat.getNumberInstance();
116 result.append("最大ヒープメモリ量: ")
117 .append(nform.format(MAX_MEMORY))
122 result.append("主要システムプロパティ:\n");
123 Set<String> propKeys = PROPERTY_MAP.keySet();
124 for(String propKey : propKeys){
125 if(propKey.equals("java.class.path")) continue;
126 String value = PROPERTY_MAP.get(propKey);
128 result.append(propKey).append("=").append(value).append("\n");
133 result.append("主要環境変数:\n");
134 Set<String> envKeys = ENVIRONMENT_MAP.keySet();
135 for(String envKey : envKeys){
136 String value = ENVIRONMENT_MAP.get(envKey);
138 result.append(envKey).append("=").append(value).append("\n");
143 result.append("クラスパス:\n");
144 for(String path : CLASSPATHS){
146 result.append(path).append("\n");
151 return result.toString();