Esempio n. 1
0
  private void save() {
    Map modifiedProperties = propSet.getModifiedProperties();

    println();
    println("╭───────────────────────┈┈┈┈");
    println("│ 保存文件 " + getURI() + "...");
    println("│┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈");

    try {
      OutputStream os = propSet.getUserPropertiesFile().getResource().getOutputStream();
      String charset = propSet.getUserPropertiesFile().getCharset();

      fileWriter = new PrintWriter(new OutputStreamWriter(os, charset), true);
    } catch (IOException e) {
      throw new ConfigWizardException(e);
    }

    try {
      List[] keyGroups = getSortedKeys(modifiedProperties, 2);

      for (int i = 0; i < keyGroups.length; i++) {
        List keys = keyGroups[i];

        // 找出最长的名称
        int maxLength = -1;

        for (Iterator j = keys.iterator(); j.hasNext(); ) {
          String key = (String) j.next();
          int length = key.length();

          if (length > maxLength && length < MAX_ALIGN) {
            maxLength = length;
          }
        }

        // 输出property项
        for (Iterator j = keys.iterator(); j.hasNext(); ) {
          String key = (String) j.next();
          String value = (String) modifiedProperties.get(key);

          if (value == null) {
            value = "";
          }

          value = value.replaceAll("\\\\", "\\\\\\\\");

          StringBuffer buffer = new StringBuffer();

          buffer.append(key);

          for (int k = 0; k < maxLength - key.length(); k++) {
            buffer.append(' ');
          }

          buffer.append("  = ").append(value);

          println(buffer);
        }

        if (i < keyGroups.length - 1) {
          println();
        }
      }
    } finally {
      fileWriter.close();
      fileWriter = null;
    }

    println("└───────┈┈┈┈┈┈┈┈┈┈┈");
    println(" 已保存至文件: " + getURI());

    propSet.reloadUserProperties();
  }
Esempio n. 2
0
 private String getURI() {
   return propSet.getUserPropertiesFile().getURI().toString();
 }