cz.cuni.amis.utils
Class IniFile

java.lang.Object
  extended by cz.cuni.amis.utils.IniFile

public class IniFile
extends java.lang.Object


Nested Class Summary
static class IniFile.Section
          Class representing one section of the ini file.
 
Constructor Summary
IniFile()
          Constructs Ini file with no defaults.
IniFile(java.io.File source)
          Constructs GameBots2004Ini with defaults taken 'source' (file must exists!).
IniFile(IniFile ini)
           
 
Method Summary
 IniFile addIniFile(IniFile iniFile)
          Add all sections from one ini file into this one.
 IniFile.Section addSection(IniFile.Section section)
          Adds section into this ini file.
 IniFile.Section addSection(java.lang.String sectionName)
          Adds a new section into this class (won't overwrite existing one).
 IniFile.Section copySection(IniFile.Section section)
           
 java.lang.String get(java.lang.String section, java.lang.String key)
           
 IniFile.Section getSection(java.lang.String name)
           
 java.util.Set<java.lang.String> getSectionNames()
           
 java.util.Collection<IniFile.Section> getSections()
           
 boolean hasSection(java.lang.String name)
           
 void load(java.io.File source)
          Loads IniFile#source into sections.
 java.lang.String output()
          Returns contents of this IniFile as string.
 void output(java.io.File file)
          Outputs GameBots2004.ini stored by this class into 'file'.
 void output(java.io.PrintWriter writer)
          Outputs contents of this IniFile into the 'writer'.
 void output(java.lang.String pathToFileToBeCreated)
          Outputs GameBots2004.ini stored by this class into 'file'.
 IniFile.Section set(java.lang.String section, java.lang.String key, java.lang.String value)
          Sets property key=value into section 'section'
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IniFile

public IniFile()
Constructs Ini file with no defaults.


IniFile

public IniFile(java.io.File source)
Constructs GameBots2004Ini with defaults taken 'source' (file must exists!).

Parameters:
source -

IniFile

public IniFile(IniFile ini)
Method Detail

load

public void load(java.io.File source)
Loads IniFile#source into sections.

Note that his method won't clear anything, it will just load all sections/properties from the given file possibly overwriting existing properties in existing sections.

Parameters:
source -

addIniFile

public IniFile addIniFile(IniFile iniFile)
Add all sections from one ini file into this one.

Parameters:
iniFile -
Returns:
this

addSection

public IniFile.Section addSection(java.lang.String sectionName)
Adds a new section into this class (won't overwrite existing one).

Parameters:
sectionName -
Returns:
section that is stored in this class

addSection

public IniFile.Section addSection(IniFile.Section section)
Adds section into this ini file. If section of the same name exists, it won't be replaced. Instead all properties from 'section' will be put there.

If 'section' is a new section (i.e., its IniFile.Section.getName() is not already present in stored sections), this instance will be stored here (does not hard-copy the section!). For hard-copy variant, use copySection(Section).

Parameters:
section -
Returns:
section that is stored in this class

copySection

public IniFile.Section copySection(IniFile.Section section)

hasSection

public boolean hasSection(java.lang.String name)

getSection

public IniFile.Section getSection(java.lang.String name)

getSectionNames

public java.util.Set<java.lang.String> getSectionNames()

getSections

public java.util.Collection<IniFile.Section> getSections()

get

public java.lang.String get(java.lang.String section,
                            java.lang.String key)

set

public IniFile.Section set(java.lang.String section,
                           java.lang.String key,
                           java.lang.String value)
Sets property key=value into section 'section'

Parameters:
section -
key -
value -
Returns:
section instance that the property was set into

output

public void output(java.lang.String pathToFileToBeCreated)
Outputs GameBots2004.ini stored by this class into 'file'. If 'file' exists, it overwrites it.

Parameters:
file -

output

public void output(java.io.File file)
Outputs GameBots2004.ini stored by this class into 'file'. If 'file' exists, it overwrites it.

Parameters:
file -

output

public void output(java.io.PrintWriter writer)
Outputs contents of this IniFile into the 'writer'.

Parameters:
writer -

output

public java.lang.String output()
Returns contents of this IniFile as string.

Returns: