Config (RabbIT/4)
Date: 2009-10-13

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## rabbit.util
Class Config

    java.lang.Object
      rabbit.util.Config

    public class Config

extends Object

a class to handle configs for different things. reads file on the format

      [sectionName1]
      key=value
      key2=value2
      [sectionName2]
      key=value
      key2=value2
      key_with_equals\=still_key=value3

everything after the first '#' is considered a comment. blank lines are ignored. If you want keys with '=' in them escape it to '\=' and you should be fine.

Constructor Summary
`Config()` create an empty Config (has only section "" with no data in it)
`Config(File file)` Create a Config for the specified file
`Config(InputStream is)` Create a Config by reading it from a stream.
`Config(Reader reader)` Create a Config by reading it from a reader.
`Config(String filename)` Create a Config for the specified file

Method Summary
`SProperties` | `getProperties(String sectionName)` get the properties for a given section
`String` | `getProperty(String section, String key)` get a property for given key in specified section
`String` | `getProperty(String section, String key, String defaultstring)` get a property for given key in specified section
`Collection<String>` | `getSections()` get the available sections
`void` | `merge(Config other)` Merge this config with another one.
`void` | `save(OutputStream os)` save the config to a OutputStream
`void` | `save(OutputStream os, String comment)` save the config to a OutputStream
`void` | `setProperties(String sectionName, SProperties prop)` set the properties for a given section
`void` | `setProperty(String section, String key, String value)` set a property for given section.
`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`

Constructor Detail

### Config

    public Config()

  create an empty Config (has only section "" with no data in it)

### Config

    public Config(String filename)
           throws IOException

  Create a Config for the specified file

  Parameters:
    `filename` - the File we read the config from
  Throws:
    `IOException`

### Config

    public Config(File file)
           throws IOException

  Create a Config for the specified file

  Parameters:
    `file` - the File we read the config from
  Throws:
    `IOException`

### Config

    public Config(InputStream is)
           throws IOException

  Create a Config by reading it from a stream.

  Parameters:
    `is` - the stream to read the config from.
  Throws:
    `IOException`

### Config

    public Config(Reader reader)
           throws IOException

  Create a Config by reading it from a reader.

  Parameters:
    `reader` - the Reader to read the config from.
  Throws:
    `IOException`

Method Detail

### getSections

    public Collection<String> getSections()

  get the available sections

  Returns:
    an Enumeration of the available sections (including the empty section).

### getProperties

    public SProperties getProperties(String sectionName)

  get the properties for a given section

  Parameters:
    `sectionName` - the section we want properties for.
  Returns:
    a SProperties if section exist or null.

### setProperties

    public void setProperties(String sectionName,
                              SProperties prop)

  set the properties for a given section

  Parameters:
    `sectionName` - the section we want to set the properties for.
    `prop` - the SProperties for the sections

### getProperty

    public String getProperty(String section,
                              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 String getProperty(String section,
                              String key,
                              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(String section,
                            String key,
                            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(OutputStream os)

  save the config to a OutputStream

### save

    public void save(OutputStream os,
                     String comment)

  save the config to a OutputStream

### toString

    public String toString()

  Get a string describing this Config

  Overrides:
    `toString` in class `Object`

### merge

    public void merge(Config other)

  Merge this config with another one. that for every section/key in either of the two configs do: if this Config has the value use it otherwise use others value.

  Parameters:
    `other` - the Config to merge with.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD