private static String remapURL(String url) { // 比如System.setProperty("h2.urlMap", "E:/H2/my-h2/my-h2-src/my/test/h2.urlMap.properties"); // 假设url="my.url",那么可以在h2.urlMap.properties中重新映射: // my.url=my.url=jdbc:h2:tcp://localhost:9092/test9 // 最后返回的url实际是jdbc:h2:tcp://localhost:9092/test9 String urlMap = SysProperties.URL_MAP; if (urlMap != null && urlMap.length() > 0) { try { SortedProperties prop; prop = SortedProperties.loadProperties(urlMap); String url2 = prop.getProperty(url); if (url2 == null) { prop.put(url, ""); prop.store(urlMap); } else { url2 = url2.trim(); if (url2.length() > 0) { return url2; } } } catch (IOException e) { throw DbException.convert(e); } } return url; }
/** * Convert a String to a map. * * @param s the string * @return the map */ public static SortedProperties fromLines(String s) { SortedProperties p = new SortedProperties(); for (String line : StringUtils.arraySplit(s, '\n', true)) { int idx = line.indexOf('='); if (idx > 0) { p.put(line.substring(0, idx), line.substring(idx + 1)); } } return p; }
/** * Load a properties object from a file. * * @param fileName the name of the properties file * @return the properties object */ public static synchronized SortedProperties loadProperties(String fileName) throws IOException { SortedProperties prop = new SortedProperties(); if (IOUtils.exists(fileName)) { InputStream in = null; try { in = IOUtils.openFileInputStream(fileName); prop.load(in); } finally { if (in != null) { in.close(); } } } return prop; }