Framework Professional Edition Package


com.prosyst.util.ini
Class IniFile

java.lang.Object
  extended by com.prosyst.util.ini.IniFile

public class IniFile
extends java.lang.Object

This class provides an easy access to sectioned files.

Every section starts with a definition:
[<section's name>].

Every key name is defined only for it's section block as follows:
<key name> = <key value>.

Sections do not have end delimiters - they end as the new section is defined or as the end of file is reached.

Sectioned files are defined as follows:
[<section's name>]
<key name> = <key value>
:
[<another section's name>]
:

It is possible to add commented lines and to comment certain key-value pairs.
A commented line will have a "//" in front of it.
A commented key-value pair will have a "##" in front of it.

Author:
Sinisha Djukic

Field Summary
protected  java.io.File lastLoadedFile
          This holds a reference to the last loaded file.
protected  com.prosyst.util.ini.Queue sections
          This is a Queue of IniSection objects.
 
Constructor Summary
IniFile()
          Constructs a new IniFile structure.
 
Method Summary
 void addSection(IniSection section)
          Appends a new section.
 boolean containsSection(IniSection section)
          Returns true if the given section is already contained.
 void deleteAllSections()
          Deletes all sections.
 void deleteSection(IniSection section)
          Deletes a section.
 void deleteSection(java.lang.String sectionName, boolean ignoreCase)
          Deletes the first section found by its name.
 IniFile duplicate()
          Returns a duplicate of this object.
 java.io.File getLastLoadedFile()
          Returns the last loaded file if the data was loaded from a file and not from a stream.
 IniSection getSection(int index)
          Returns the section at a given index.
 IniSection getSection(java.lang.String sectionName, boolean ignoreCase)
          Returns the section by its name.
 int getSectionCount()
          Returns the number of sections.
 int getSectionIndex(IniSection section)
          Returns the index of a given section.
 void insertSection(IniSection section, int index)
          Inserts a section at a given index.
 void load(java.io.File iniFile)
          Loads all sections from the given file.
 void load(java.io.InputStream inputStream)
          Loads all sections from the given input stream.
 void save(java.io.File iniFile)
          Saves all sections to the file.
 void save(java.io.OutputStream stream)
          Saves all sections to the output stream.
 void setSection(IniSection section, int index)
          Sets a section at index.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sections

protected com.prosyst.util.ini.Queue sections
This is a Queue of IniSection objects.


lastLoadedFile

protected java.io.File lastLoadedFile
This holds a reference to the last loaded file.

Constructor Detail

IniFile

public IniFile()
Constructs a new IniFile structure.

Method Detail

load

public void load(java.io.File iniFile)
          throws java.io.IOException
Loads all sections from the given file.

Parameters:
iniFile - file to be loaded
Throws:
java.io.IOException

load

public void load(java.io.InputStream inputStream)
          throws java.io.IOException
Loads all sections from the given input stream.

Parameters:
inputStream - stream to be loaded
Throws:
java.io.IOException

save

public void save(java.io.File iniFile)
          throws java.io.IOException
Saves all sections to the file.

Parameters:
iniFile - the file to be saved in
Throws:
java.io.IOException

save

public void save(java.io.OutputStream stream)
          throws java.io.IOException
Saves all sections to the output stream.

Parameters:
stream - the stream to be saved in
Throws:
java.io.IOException

addSection

public void addSection(IniSection section)
Appends a new section.

Parameters:
section - non-null section to be appended

containsSection

public boolean containsSection(IniSection section)
Returns true if the given section is already contained.

Parameters:
section - section to be checked
Returns:
true if the section is already contained

deleteSection

public void deleteSection(IniSection section)
Deletes a section.

Parameters:
section - section to be deleted

deleteAllSections

public void deleteAllSections()
Deletes all sections.


deleteSection

public void deleteSection(java.lang.String sectionName,
                          boolean ignoreCase)
Deletes the first section found by its name.

Parameters:
sectionName - the section name
ignoreCase - true if it is to ignore case while searching

getSection

public IniSection getSection(int index)
Returns the section at a given index.

Parameters:
index - section's index
Returns:
the section at a given index.

getSection

public IniSection getSection(java.lang.String sectionName,
                             boolean ignoreCase)
Returns the section by its name.

Parameters:
sectionName - the section's name
ignoreCase - true if it is to ignore case while searching
Returns:
the desired section or null if not found.

getSectionCount

public int getSectionCount()
Returns the number of sections.

Returns:
the number of sections defined.

getSectionIndex

public int getSectionIndex(IniSection section)
Returns the index of a given section.

Parameters:
section - section to search
Returns:
the section's index.

insertSection

public void insertSection(IniSection section,
                          int index)
Inserts a section at a given index. If the index is invalid, the section is appended using the addSection method.

Parameters:
section - section to be inserted
index - the index, at which the section is inserted

setSection

public void setSection(IniSection section,
                       int index)
Sets a section at index. If the index is invalid the section is appended using the addSection method.

Parameters:
section - the section to be set
index - the section's index

duplicate

public IniFile duplicate()
Returns a duplicate of this object.

Returns:
a duplicate of this object

getLastLoadedFile

public java.io.File getLastLoadedFile()
Returns the last loaded file if the data was loaded from a file and not from a stream.

Returns:
the last loaded file if the data was loaded from a file, or null if no files have been loaded yet, or the last data came from a stream

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

Framework Professional Edition Package


Copyright © 1999-2007 ProSyst Software GmbH. All Rights Reserved