public class IniFile
extends java.lang.Object
eg.
[Section Name]
key = value
Note: As of 7.1 SP1, the IniFile class has been modified to ensure keys are
used in a case-insensitive manner. If for some reason you have an existing
application that relies on case sensitive keys, then you can use the following
system property to ensure keys are case sensitive.
com.entrust.toolkit.util.IniFile.CaseSensitive=true
You can also set it programmatically by using the System.setProperty() method:
System.setProperty("com.entrust.toolkit.util.IniFile.CaseSensitive","true");
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_ENCODING |
| Constructor and Description |
|---|
IniFile()
Initializes an empty IniFile
|
IniFile(java.io.InputStream is)
Initializes an IniFile using an
InputStream. |
IniFile(java.lang.String filename)
Initializes an IniFile with a specific filename
|
| Modifier and Type | Method and Description |
|---|---|
int |
getInt(java.lang.String sectionName,
java.lang.String entryName)
Gets the integer value associated with the given key in the given section.
|
int |
getInt(java.lang.String sectionName,
java.lang.String entryName,
int defaultValue)
Gets the integer value associated with the given key in the given section.
|
java.util.Vector |
getSection(java.lang.String sectionName)
Gets all of the entries in the given section.
|
java.util.Enumeration |
getSectionNames()
Returns an enumeration of all section names in this ini file.
|
java.lang.String |
getString(java.lang.String sectionName,
java.lang.String entryName)
Gets the value associated with the given entry in the given section.
|
java.lang.String |
getString(java.lang.String sectionName,
java.lang.String entryName,
java.lang.String defaultString)
Gets the value associated with the given entry in the given section.
|
boolean |
putInt(java.lang.String sectionName,
java.lang.String entryName,
int entryValue)
Puts the value associated with the given entry in the given section into
the IniFile.
|
boolean |
putSection(java.lang.String sectionName,
java.util.List entries)
Puts a given set of entries in the given section.
|
boolean |
putString(java.lang.String sectionName,
java.lang.String entryName,
java.lang.String entryValue)
Puts the value associated with the given entry in the given section into
the IniFile.
|
protected void |
readIniFile(java.io.BufferedReader reader,
java.lang.String charset)
Reads the ini file from the given
BufferedReader. |
void |
readStream(java.io.InputStream inputStream)
Builds an IniFile object from the given
InputStream. |
void |
readStream(java.io.InputStream inputStream,
java.lang.String charset)
Builds an IniFile object from the given
InputStream. |
void |
removeEntry(java.lang.String sectionName,
java.lang.String entryName)
Removes an entry from the IniFile.
|
void |
removeSection(java.lang.String sectionName)
Removes a section from the IniFile.
|
void |
writeStream(java.io.OutputStream outputStream)
Writes this IniFile object to the given
OutputStream. |
void |
writeStream(java.io.OutputStream outputStream,
java.lang.String charset)
Writes this IniFile object to the given
OutputStream. |
public static final java.lang.String DEFAULT_ENCODING
public IniFile()
public IniFile(java.lang.String filename)
throws java.io.FileNotFoundException
filename - The name of the file from which the ini file is read.java.io.FileNotFoundException - Thrown if the file for the given filename can't be found.public IniFile(java.io.InputStream is)
InputStream.is - an InputStream from which the ini file is read. The stream is read
until there is no more data left, after which the stream is closed.public java.lang.String getString(java.lang.String sectionName,
java.lang.String entryName)
sectionName - The name of the section from which to get the entry.entryName - The name of the entry in the section.public java.lang.String getString(java.lang.String sectionName,
java.lang.String entryName,
java.lang.String defaultString)
sectionName - The name of the section from which to get the entry.entryName - The name of the entry in the section.defaultString - The value to return if the entry is not found.public int getInt(java.lang.String sectionName,
java.lang.String entryName)
sectionName - The name of the section in the IniFile.entryName - The name of the key in the section.public int getInt(java.lang.String sectionName,
java.lang.String entryName,
int defaultValue)
defaultValue is returned.sectionName - The name of the section in the IniFile.entryName - The name of the key in the section.defaultValue - The default value to return if the entry cannot be founddefaultValue if not found.
If there is an exception converting the entry to an integer,
defaultValue is returned.public java.util.Enumeration getSectionNames()
public java.util.Vector getSection(java.lang.String sectionName)
Vector is returned.
This method preserves the order in which entries were added to the section, or were read from an input stream.
sectionName - The name of the section in the IniFile.Vector containing Strings of entries, (ie. "entryName=value")public boolean putString(java.lang.String sectionName,
java.lang.String entryName,
java.lang.String entryValue)
sectionName - The name of the section to add the entry to.entryName - The name of the entry in the section.entryValue - The String value of the entry. Note that the value should not
include carriage return or line feed characters. These will cause
problems when the file is written and read back in again.true. The return value is maintained for backwards
compatibility only.public boolean putInt(java.lang.String sectionName,
java.lang.String entryName,
int entryValue)
sectionName - The name of the section to add the entry to.entryName - The name of the entry in the section.entryValue - The int value of the entry.true. The return value is maintained for backwards
compatibility only.public boolean putSection(java.lang.String sectionName,
java.util.List entries)
sectionName - The name of the section in the IniFile.entries - A List containing strings of entries. e.g. "entryName=value"true. The return value is maintained for backwards
compatibility only.public void removeEntry(java.lang.String sectionName,
java.lang.String entryName)
sectionName - The name of the section from which to remove the entry.entryName - The name of the entry to remove.public void removeSection(java.lang.String sectionName)
sectionName - The name of the section to remove.protected void readIniFile(java.io.BufferedReader reader,
java.lang.String charset)
BufferedReader.reader - The BufferedReader from which the ini file is read. Note
that this reader is not closed after reading is complete.charset - The character set that the reader will use to read the data. This is
to determine if any special care needs to be taken when reading the stream
based on the given character set.public void readStream(java.io.InputStream inputStream)
InputStream. Any
data currently maintained by this object is erased. A
default character set of "UTF-8" will be used to write out the INI file.
This method also checks the system property com.entrust.toolkit.util.Initfile.encoding
to see if an alternate character coding is specified. If an alternate encoding
is specified, that encoding will be used to write the INI file.
inputStream - The stream to read from. The stream is read until there is no more
data left to be read, after which the stream is closed.public void readStream(java.io.InputStream inputStream,
java.lang.String charset)
InputStream. Any
data currently maintained by this object is erased.inputStream - The stream to read from. The stream is read until there is no more
data left to be read, after which the stream is closed.charset - The character set to use when reading the Stream. If no character
set is specified then the default encoding "UTF-8" will be used.public void writeStream(java.io.OutputStream outputStream)
OutputStream. A
default character set of "UTF-8" will be used to write out the INI file.
This method also checks the system property com.entrust.toolkit.util.Initfile.encoding
to see if an alternate character coding is specified. If an alternate encoding
is specified, that encoding will be used to write the INI file.
outputStream - The OutputStream to which the IniFile will be written.
Note that this stream in not closed after the ini file is written.public void writeStream(java.io.OutputStream outputStream,
java.lang.String charset)
OutputStream.outputStream - The OutputStream to which the IniFile will be written.charset - The character set to use when reading the Stream. If no character
set is specified then the default encoding "UTF-8" will be used.
Note that this stream in not closed after the ini file is written.