Class Config

java.lang.Object
  |
  +--Config

public class Config
extends java.lang.Object

a class to handle configs for different things. reads file on the format [sectionName1] key=value key2=value2 [sectionName2] key=value key2=value2 ... Everything after the first '#' is considered a comment. Blank lines are ignored. Kkeys with '=' need the '=' to be escaped ('\=')


Field Summary
 java.util.Date lastModified
           
 
Constructor Summary
Config()
          create an empty Config
Config(java.io.File file)
          Create a Config for the specified file
Config(java.io.InputStream is)
          Create a Config by reading it from a stream.
Config(java.io.Reader reader)
          Create a Config by reading it from a reader.
Config(java.lang.String filename)
          Create a Config for the specified file
 
Method Summary
 java.util.Properties getProperties(java.lang.String sectionName)
          get the properties for a given section
 java.lang.String getProperty(java.lang.String section, java.lang.String key)
          get a property for given key in specified section
 java.lang.String getProperty(java.lang.String section, java.lang.String key, java.lang.String defaultstring)
          get a property for given key in specified section
 void save(java.io.OutputStream os)
          save the config to a OutputStream
 void save(java.io.OutputStream os, java.lang.String comment)
          save the config to a OutputStream
 void setProperties(java.lang.String sectionName, java.util.Properties prop)
          set the properties for a given section
 void setProperty(java.lang.String section, java.lang.String key, java.lang.String value)
          set a property for given section.
 java.lang.String toString()
          Get a string describing this Config
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

lastModified

public java.util.Date lastModified
Constructor Detail

Config

public Config()
create an empty Config

Config

public Config(java.lang.String filename)
       throws java.io.IOException
Create a Config for the specified file
Parameters:
filename - the name of the file we read the config from

Config

public Config(java.io.File file)
       throws java.io.IOException
Create a Config for the specified file
Parameters:
file - the File we read the config from

Config

public Config(java.io.InputStream is)
       throws java.io.IOException
Create a Config by reading it from a stream.
Parameters:
is - the stream to read the config from.

Config

public Config(java.io.Reader reader)
       throws java.io.IOException
Create a Config by reading it from a reader.
Parameters:
reader - the Reader to read the config from.
Method Detail

getProperties

public java.util.Properties getProperties(java.lang.String sectionName)
get the properties for a given section
Parameters:
sectionName - the section we want properties for.
Returns:
a Properties if section exist or null.

setProperties

public void setProperties(java.lang.String sectionName,
                          java.util.Properties prop)
set the properties for a given section
Parameters:
sectionName - the section we want to set the properties for.
prop - the Properties for the sections

getProperty

public java.lang.String getProperty(java.lang.String section,
                                    java.lang.String key)
get a property for given key in specified section
Parameters:
section - the section we should look in.
key - the key we want a value for.
Returns:
a string if section + key is set, null otherwise

getProperty

public java.lang.String getProperty(java.lang.String section,
                                    java.lang.String key,
                                    java.lang.String defaultstring)
get a property for given key in specified section
Parameters:
section - the section we should look in.
key - the key we want a value for.
defaultstring - the string to use if no value is found.
Returns:
a string if section + key is set, null otherwise

setProperty

public void setProperty(java.lang.String section,
                        java.lang.String key,
                        java.lang.String value)
set a property for given section.
Parameters:
section - the section we should look in.
key - the key.
value - the value.

save

public void save(java.io.OutputStream os)
save the config to a OutputStream

save

public void save(java.io.OutputStream os,
                 java.lang.String comment)
save the config to a OutputStream

toString

public java.lang.String toString()
Get a string describing this Config
Overrides:
toString in class java.lang.Object