Ejemplo n.º 1
0
 private Properties getProperties() throws IOException {
   Properties p;
   File f;
   if ((f = Environment.getPropertiesFile(FManager.class)).exists()) {
     try (InputStream is = new FileInputStream(f)) {
       p = new Properties();
       p.load(is);
       is.close();
     }
   } else {
     throw new IOException("Cannot load properties.");
   }
   return p;
 }
Ejemplo n.º 2
0
  public void saveSettings(Map<String, String> keyValMap, boolean autoLoad) throws IOException {
    Properties p;
    File f;
    if ((f = Environment.getPropertiesFile(FManager.class)).exists()) {
      this.activeFingerprintFileMap.clear();
      try (InputStream is = new FileInputStream(f)) {
        p = new Properties();
        // p.load(is);
        keyValMap
            .entrySet()
            .stream()
            .forEach(
                pair -> {
                  p.setProperty(pair.getKey(), pair.getValue());
                  this.activeFingerprintFileMap.put(
                      new File(pair.getKey()), Boolean.valueOf(pair.getValue()));
                });

        p.setProperty(AUTOLOAD, autoLoad + "");

        // is.close();
        FileOutputStream fos = new FileOutputStream(f);
        p.store(
            fos,
            "Updated "
                + DateFormatUtils.format(
                    System.currentTimeMillis(), ISO_EXTENDED_FORMAT_PATTERN, Locale.ENGLISH));
        try {
          fos.close();
        } catch (Exception ex) {
        }
      }
    } else {
      throw new IOException("Cannot store properties.");
    }
  }
Ejemplo n.º 3
0
 public static void saveSetting(String key, String val) throws IOException {
   Properties p;
   File f;
   if ((f = Environment.getPropertiesFile(FManager.class)).exists()) {
     try (InputStream is = new FileInputStream(f)) {
       p = new Properties();
       p.load(is);
       p.setProperty(key, val);
       is.close();
       FileOutputStream fos = new FileOutputStream(f);
       p.store(
           fos,
           "Updated "
               + DateFormatUtils.format(
                   System.currentTimeMillis(), ISO_EXTENDED_FORMAT_PATTERN, Locale.ENGLISH));
       try {
         fos.close();
       } catch (Exception ex) {
       }
     }
   } else {
     throw new IOException("Cannot store properties.");
   }
 }