1 10 11 package com.sun.jmx.snmp.defaults; 12 13 14 import java.io.File ; 17 import java.io.BufferedReader ; 18 import java.io.InputStream ; 19 import java.io.InputStreamReader ; 20 import java.util.StringTokenizer ; 21 22 29 public class DefaultPaths { 30 private static final String INSTALL_PATH_RESOURCE_NAME = "com/sun/jdmk/defaults/install.path"; 31 private DefaultPaths() { 33 34 } 35 36 39 47 public static String getInstallDir() { 48 if (installDir == null) 49 return useRessourceFile(); 50 else 51 return installDir; 52 } 53 54 64 public static String getInstallDir(String dirname) { 65 if (installDir == null) { 66 if (dirname == null) { 67 return getInstallDir(); 68 } else { 69 return getInstallDir() + File.separator + dirname; 70 } 71 } else { 72 if (dirname == null) { 73 return installDir; 74 } else { 75 return installDir + File.separator + dirname; 76 } 77 } 78 } 79 80 85 public static void setInstallDir(String dirname) { 86 installDir = dirname; 87 } 88 89 99 public static String getEtcDir() { 100 if (etcDir == null) 101 return getInstallDir("etc"); 102 else 103 return etcDir; 104 } 105 106 118 public static String getEtcDir(String dirname) { 119 if (etcDir == null) { 120 if (dirname == null) { 121 return getEtcDir(); 122 } else { 123 return getEtcDir() + File.separator + dirname; 124 } 125 } else { 126 if (dirname == null) { 127 return etcDir; 128 } else { 129 return etcDir + File.separator + dirname; 130 } 131 } 132 } 133 134 139 public static void setEtcDir(String dirname) { 140 etcDir = dirname; 141 } 142 143 153 public static String getTmpDir() { 154 if (tmpDir == null) 155 return getInstallDir("tmp"); 156 else 157 return tmpDir; 158 } 159 160 172 public static String getTmpDir(String dirname) { 173 if (tmpDir == null) { 174 if (dirname == null) { 175 return getTmpDir(); 176 } else { 177 return getTmpDir() + File.separator + dirname; 178 } 179 } else { 180 if (dirname == null) { 181 return tmpDir; 182 } else { 183 return tmpDir + File.separator + dirname; 184 } 185 } 186 } 187 188 193 public static void setTmpDir(String dirname) { 194 tmpDir = dirname; 195 } 196 197 198 201 private static String useRessourceFile() { 202 InputStream in = null; 203 BufferedReader r = null; 204 try { 205 in = 206 DefaultPaths.class.getClassLoader().getResourceAsStream(INSTALL_PATH_RESOURCE_NAME); 207 if(in == null) return null; 208 r = new BufferedReader (new InputStreamReader (in)); 209 installDir = r.readLine(); 210 }catch(Exception e) { 211 } 212 finally { 213 try { 214 if(in != null) in.close(); 215 if(r != null) r.close(); 216 }catch(Exception e) {} 217 } 218 return installDir; 219 } 220 221 224 227 private static String etcDir; 228 private static String tmpDir; 229 private static String installDir; 230 } 231 | Popular Tags |