cz.cuni.amis.utils
Class IniFile

Package class diagram package IniFile
java.lang.Object
  extended by cz.cuni.amis.utils.IniFile

public class IniFile
extends Object


Nested Class Summary
static class IniFile.Section
          Class representing one section of the ini file.
static class IniFile.SectionEntry
           
static class IniFile.SectionEntryComment
           
static class IniFile.SectionEntryKeyValue
           
 
Field Summary
static Comparator<IniFile.SectionEntry> SECTION_ENTRY_INDEX_COMPARATOR
           
static Comparator<IniFile.SectionEntry> SECTION_ENTRY_KEY_COMPARATOR
           
 
Constructor Summary
IniFile()
          Constructs Ini file with no defaults.
IniFile(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(String sectionName)
          Adds a new section into this class (won't overwrite existing one).
 void backup(String pathToFileToBeCreated)
          Similar to output(String) but this ensure not to overwrite any file + it appends current "_date_time" to filename.
 IniFile.Section copySection(IniFile.Section section)
           
 String get(String section, String key)
           
 IniFile.Section getSection(String name)
           
 Set<String> getSectionNames()
           
 Collection<IniFile.Section> getSections()
           
static boolean hasCommentKey(String comment)
          Whether this comment is commented key=value pair.
static boolean hasKey(String keyValue)
          Whether this non-comment line is a key=value.
 boolean hasSection(String name)
           
static boolean isComment(String line)
          Whether this line is comment.
 void load(File source)
          Loads IniFile#source into sections.
 void load(InputStream source)
          Loads IniFile#source into sections.
static void mergeIntoIniFile(IniFile values, File mergeIntoIniFile)
           
 String output()
          Returns contents of this IniFile as string.
 void output(File file)
          Outputs GameBots2004.ini stored by this class into 'file'.
 void output(PrintWriter writer)
          Outputs contents of this IniFile into the 'writer'.
 void output(String pathToFileToBeCreated)
          Outputs GameBots2004.ini stored by this class into 'file'.
 IniFile.Section set(IniFile.Section section)
          Set key=values from 'section' into this IniFile.
 IniFile set(IniFile values)
          Set 'values' into this IniFile, alias for addIniFile(IniFile).
 IniFile.Section set(String section, String key, 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
 

Field Detail

SECTION_ENTRY_INDEX_COMPARATOR

public static final Comparator<IniFile.SectionEntry> SECTION_ENTRY_INDEX_COMPARATOR

SECTION_ENTRY_KEY_COMPARATOR

public static final Comparator<IniFile.SectionEntry> SECTION_ENTRY_KEY_COMPARATOR
Constructor Detail

IniFile

public IniFile()
Constructs Ini file with no defaults.


IniFile

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

Parameters:
source -

IniFile

public IniFile(IniFile ini)
Method Detail

load

public void load(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 -

load

public void load(InputStream 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(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(String name)

getSection

public IniFile.Section getSection(String name)

getSectionNames

public Set<String> getSectionNames()

getSections

public Collection<IniFile.Section> getSections()

get

public String get(String section,
                  String key)

set

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

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

set

public IniFile set(IniFile values)
Set 'values' into this IniFile, alias for addIniFile(IniFile).

Parameters:
values -
Returns:
this

set

public IniFile.Section set(IniFile.Section section)
Set key=values from 'section' into this IniFile. Alias for addSection(Section).

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

isComment

public static boolean isComment(String line)
Whether this line is comment. (Does not check for end lines).

Parameters:
text -
Returns:

hasKey

public static boolean hasKey(String keyValue)
Whether this non-comment line is a key=value. (Does not check for end lines).

Parameters:
keyValue -
Returns:

hasCommentKey

public static boolean hasCommentKey(String comment)
Whether this comment is commented key=value pair. (Does not check for end lines).

Parameters:
comment -
Returns:

backup

public void backup(String pathToFileToBeCreated)
Similar to output(String) but this ensure not to overwrite any file + it appends current "_date_time" to filename.

Parameters:
file -

output

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

Parameters:
file -

output

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

Parameters:
file -

output

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

Parameters:
writer -

output

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

Returns:

mergeIntoIniFile

public static void mergeIntoIniFile(IniFile values,
                                    File mergeIntoIniFile)


Copyright © 2013 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.