com.entrust.toolkit.util
Class IniFile

java.lang.Object
  |
  +--com.entrust.toolkit.util.IniFile

public class IniFile
extends java.lang.Object

IniFile provides a convient format for storing program data in a file, based closely on MS-Windows 3.x "INI" files. An INI file consists of sections, keys and values. A section consists of related keys and values and all sections and keys must have a unique name.

 eg.
     [Section Name]
     key = value
 


Field Summary
protected  Map m_sections
           
 
Constructor Summary
IniFile()
          Initializes IniFile
IniFile(java.io.InputStream is)
          Initializes IniFile using a generic input stream
IniFile(java.lang.String filename)
          Initializes IniFile with a specific filename
 
Method Summary
 int getInt(java.lang.String section, java.lang.String key)
          Gets the value associated with the given key in the given section.
 Map getSection(int position)
          Returns the sections by position within the inifile.
 java.util.Vector getSection(java.lang.String section)
          Gets all of the entries (ie.
 java.lang.String getString(java.lang.String section, java.lang.String key)
          Gets the value associated with the given key in the given section.
 java.lang.String getString(java.lang.String section, java.lang.String key, java.lang.String defaultString)
          Gets the value associated with the given key in the given section.
 boolean putInt(java.lang.String section, java.lang.String key, int anInt)
          Puts the value associated with the given key in the given section into the IniFile.
 boolean putSection(java.lang.String section, java.util.Vector strings)
          Puts a given set of entries (ie.
 boolean putString(java.lang.String section, java.lang.String key, java.lang.String aString)
          Puts the value associated with the given key in the given section into the IniFile.
protected  java.lang.String readSection(java.io.LineNumberReader reader, java.lang.String aSection)
          Parses a section entry from the given InputStream.
 void readStream(java.io.InputStream inputStream)
          Builds an IniFile object from the given InputStream.
 void removeEntry(java.lang.String section, java.lang.String entry)
          Removes an entry from the IniFile.
 void removeSection(java.lang.String section)
          Removes a section from the IniFile.
 void writeStream(java.io.OutputStream outputStream)
          Writes this IniFile object to the given OutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_sections

protected Map m_sections
Constructor Detail

IniFile

public IniFile()
Initializes IniFile

IniFile

public IniFile(java.lang.String filename)
        throws java.io.FileNotFoundException
Initializes IniFile with a specific filename
Parameters:
filename - String containing the filename

IniFile

public IniFile(java.io.InputStream is)
Initializes IniFile using a generic input stream
Parameters:
is - an InputStream
Method Detail

getString

public java.lang.String getString(java.lang.String section,
                                  java.lang.String key)
Gets the value associated with the given key in the given section.
Parameters:
section - The name of the section in the IniFile.
key - The name of the key in the section.
Returns:
A string containing the value.

getString

public java.lang.String getString(java.lang.String section,
                                  java.lang.String key,
                                  java.lang.String defaultString)
Gets the value associated with the given key in the given section. If no value is found for this key, the defaultString is returned.
Parameters:
section - The name of the section in the IniFile.
key - The name of the key in the section.
defaultString - The default value to return if nothing found
Returns:
A string containing the value.

getInt

public int getInt(java.lang.String section,
                  java.lang.String key)
Gets the value associated with the given key in the given section. If no value is found for this key, 0 is returned.
Parameters:
section - The name of the section in the IniFile.
key - The name of the key in the section.
Returns:
An int value or 0 if not found.

getSection

public java.util.Vector getSection(java.lang.String section)
Gets all of the entries (ie. the key and value) in the given section. If no value is found for this key, 0 is returned.
Parameters:
section - The name of the section in the IniFile.
Returns:
A Vector containing strings of entries, (ie. "key=value")

getSection

public Map getSection(int position)
Returns the sections by position within the inifile.
Parameters:
position - The position of the section to return.
Returns:
The section as a Map, or null if there aren't that many sections.

putString

public boolean putString(java.lang.String section,
                         java.lang.String key,
                         java.lang.String aString)
Puts the value associated with the given key in the given section into the IniFile.
Parameters:
section - The name of the section in the IniFile.
key - The name of the key in the section.
aString - The string value to map to this key
Returns:
true if the operation was successful, otherwise false

putInt

public boolean putInt(java.lang.String section,
                      java.lang.String key,
                      int anInt)
Puts the value associated with the given key in the given section into the IniFile.
Parameters:
section - The name of the section in the IniFile.
key - The name of the key in the section.
anInt - The integer value to map to this key
Returns:
true if the operation was successful, otherwise false

putSection

public boolean putSection(java.lang.String section,
                          java.util.Vector strings)
Puts a given set of entries (ie. the key and value) in the given section.
Parameters:
section - The name of the section in the IniFile.
strings - A Vector containing strings of entries, (ie. "key=value")
Returns:
true if the operation was successful, otherwise false

removeEntry

public void removeEntry(java.lang.String section,
                        java.lang.String entry)
Removes an entry from the IniFile. If the entry does not exist, nothing happens.
Parameters:
section - Section name
entry - Entry name in the section

removeSection

public void removeSection(java.lang.String section)
Removes a section from the IniFile. If the section does not exist, nothing happens.
Parameters:
section - Secton name

readSection

protected java.lang.String readSection(java.io.LineNumberReader reader,
                                       java.lang.String aSection)
Parses a section entry from the given InputStream.
Parameters:
reader - A LineNumberReader
aSection - Section name
Returns:
Name of next section or null if none

readStream

public void readStream(java.io.InputStream inputStream)
Builds an IniFile object from the given InputStream.
Parameters:
inputStream - An input stream

writeStream

public void writeStream(java.io.OutputStream outputStream)
Writes this IniFile object to the given OutputStream.
Parameters:
outputStream - An input stream