Ejemplo n.º 1
0
 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;
 }
 /**
  * Store a properties file. The header and the date is not written.
  *
  * @param fileName the target file name
  */
 public synchronized void store(String fileName) throws IOException {
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   store(out, null);
   ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
   InputStreamReader reader = new InputStreamReader(in, "ISO8859-1");
   LineNumberReader r = new LineNumberReader(reader);
   Writer w;
   try {
     w = new OutputStreamWriter(IOUtils.openFileOutputStream(fileName, false));
   } catch (Exception e) {
     throw DbException.convertToIOException(e);
   }
   PrintWriter writer = new PrintWriter(new BufferedWriter(w));
   while (true) {
     String line = r.readLine();
     if (line == null) {
       break;
     }
     if (!line.startsWith("#")) {
       writer.print(line + "\n");
     }
   }
   writer.close();
 }