public synchronized void save(){
  Properties toSave=(Properties)PROPS.clone();
  for (  Setting set : settings) {
    if (!set.shouldAlwaysSave() && set.isDefault())     toSave.remove(set.getKey());
  }
  OutputStream out=null;
  try {
    if (SETTINGS_FILE.isDirectory())     SETTINGS_FILE.delete();
    File parent=SETTINGS_FILE.getParentFile();
    if (parent != null) {
      parent.mkdirs();
    }
    FileUtils.setWriteable(SETTINGS_FILE);
    if (SETTINGS_FILE.exists() && !SETTINGS_FILE.canRead()) {
      SETTINGS_FILE.delete();
    }
    try {
      out=new BufferedOutputStream(new FileOutputStream(SETTINGS_FILE));
    }
 catch (    IOException ioe) {
      if (SETTINGS_FILE.exists()) {
        SETTINGS_FILE.delete();
        out=new BufferedOutputStream(new FileOutputStream(SETTINGS_FILE));
      }
    }
    if (out != null) {
      toSave.store(out,HEADING);
    }
 else {
      markFailure();
    }
  }
 catch (  IOException e) {
    markFailure();
  }
 finally {
    IOUtils.closeQuietly(out);
  }
}

public synchronized void save ( ) { Properties toSave = ( Properties ) PROPS . clone ( ) ; for ( Setting set : settings ) { if ( ! set . shouldAlwaysSave ( ) && set . isDefault ( ) ) toSave . remove ( set . getKey ( ) ) ; } OutputStream out = null ; try { if ( SETTINGS_FILE . isDirectory ( ) ) SETTINGS_FILE . delete ( ) ; File parent = SETTINGS_FILE . getParentFile ( ) ; if ( parent != null ) { parent . mkdirs ( ) ; } FileUtils . setWriteable ( SETTINGS_FILE ) ; if ( SETTINGS_FILE . exists ( ) && ! SETTINGS_FILE . canRead ( ) ) { SETTINGS_FILE . delete ( ) ; } try { out = new BufferedOutputStream ( new FileOutputStream ( SETTINGS_FILE ) ) ; } catch ( IOException ioe ) { if ( SETTINGS_FILE . exists ( ) ) { SETTINGS_FILE . delete ( ) ; out = new BufferedOutputStream ( new FileOutputStream ( SETTINGS_FILE ) ) ; } } if ( out != null ) { toSave . store ( out , HEADING ) ; } else { markFailure ( ) ; } } catch ( IOException e ) { markFailure ( ) ; } finally { IOUtils . closeQuietly ( out ) ; } }
save setting information to property file we want to not save any properties which are the default value , as well as any older properties that are no longer in use . to avoid having to manually encode the file , we clone the existing properties and manually remove the ones which are default and aren ' t required to be saved . it is important to do it this way ( as opposed to creating a new properties object and adding only those that should be saved or aren ' t default ) because ' adding ' properties may fail if certain settings classes haven ' t been statically loaded yet . ( note that we cannot use ' store ' since it ' s only available in 1 . 2 )
