Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH . All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: s IT Solutions AT Spardat GmbH - initial API and implementation /
 
 
 /*
  * Created by : s3595
  */
 package at.spardat.xma.boot.util;
 
 import java.io.File;
PropertiesFile which automatically flushes its properties into its file.

Author(s):
s3595 Chris Sch�fer (CGS)
Version:
$Id: PropertyFile.java 2084 2007-11-27 14:53:31Z s3460 $
 
 public class PropertyFile extends Properties {

    
header info for property files
 
     private String strHeader = "XMA-File Properties";

    
the file_ to save to
 
     private File file_;

    
extended file output
 
     private boolean debug;

    
ProertyFile backed by the specified "file"

Parameters:
file the file to save and load to
header the file header
Throws:
java.io.IOException containing the filename
 
     public PropertyFile(File fileString headerthrows IOException {
        initfileheaderfalse);
     }
    
ProertyFile backed by the specified "file"

Parameters:
file the file to save and load to
debug if true trace information is writen into the log file
Throws:
java.io.IOException containing the filename
 
     public PropertyFile(File fileboolean debugthrows IOException {
        initfilethis.debug);
     }

    

Parameters:
file the file to load from and save to
header header info
Throws:
java.io.IOException containing the filename
 
     private void initFile fileString headerboolean debugthrows IOException {
         this.        = file;
         this.    = header;
         this.        = debug;
         this.load();
     }

    
Returns the value of the specified key, or null if the key does not exist.

Parameters:
key key to look for
 
     public String getProperty(String key) {
       return super.getProperty(key);
     }

    
Returns the value of the specified key, or the default value if the key does not exist.
 
     public String getProperty(String keyString defaultValue) {
       return super.getProperty(keydefaultValue);
     }

    
Sets the value for the specified key and updates the corresponding .ifo file.

Returns:
the previous value
Throws:
java.lang.RuntimeException if the property could not be persisted
 
     public Object setProperty(String keyString value) {
         Object o = super.setProperty(keyvalue);
        try {
            this.store();
        }
        catch (IOException e) {
          throw new RuntimeException("io/error on underlying property-file '"+.getAbsolutePath()+"'",e);
        }
      return o;
    }

    
Sets the value for the specified key without updating the file now.

Returns:
the previous value
Author(s):
s2877
Since:
1.3.1
    public Object setPropertyNoflush(String key,String value) {
        return super.setProperty(key,value);
    }

    
get the underlying file_
    public File getStoreFile() {
      return ;
    }

    
load from file_

Throws:
java.io.IOException containing the filename
    public void load() throws IOException {
      try {
          if( !.exists()) {
            .getParentFile().mkdirs();
            .createNewFile();
            this.store();
          } else {
              InputStream s = null;
              try {
                s = new FileInputStream();
                super.load(s);
              } finally {
                  Util.close(s,.getAbsolutePath());
              }
          }
      } catch (Exception exc) {
          IOException ne = new IOException("error loading "+.getAbsolutePath());
          ne.initCause(exc);
          throw ne;
      }
    }// load

    
Saves the properties to the file_.

Throws:
java.io.IOException containing the filename
    public void store() throws IOException {
        OutputStream s = null;
        try {
            s = new FileOutputStream();
            store(s);
        } catch(IOException exc) {
            IOException ne = new IOException("error storing "+.getAbsolutePath());
            ne.initCause(exc);
            throw ne;
        } finally {
            Util.close(s,.getAbsolutePath());
        }
    }// store
New to GrepCode? Check out our FAQ X