public class INIFileReader extends FileLineReader
This INIFileReader class is intended to read INI formatted text files.
Physical INI files are expected to be in a particular format. This is very much like the format for Windows INI files--which is the App Map format currently in use for the Rational Robot SAFS Engine (RRAFS). (Though, there may be slight differences.)
The following characters are allowed to indicate commentlines or are otherwise ignored. Lines are trimmed of leading whitespace before this check is made:
! (bang - exclamation point)
; (semicolon)
# (hash or pound mark)
However, if an equality character ('=') exists in the line the line will be treated as a valid text line. The assumption is the comment indicators are actually part of the NAME in a NAME=VALUE pair.
Each INI "Section" is delimited with brackets ([ ])containing the name of the section. In SAFS automation parlance, these are the "Window" definition sections. A section delimiter should appear all by itself on a line. There should be no additional text. The line is first trimmed before the check for a section is made.
A section identifier is not case-sensitive.
If an INI file contains a [ApplicationConstants] section, that will be considered the "default" section. Otherwise, any first, unnamed section is the "default".
Items within a section have a NAME=VALUE format.
To the left of the Equals sign is the NAME. The substring is trimmed of leading or
trailing whitespace and by default is not case-sensitive. Enclose any space character(s)
in double-quote characters.
Everything to the right of the Equals sign is returned unmodified. It is NOT trimmed
of leading or trailing whitespace and the text is returned unmodified. However, leading
and trailing quotes will be removed if they exist.
An example is below:
! this line is ignored
; this line is ignored
# this line is ignored
; the following 2 items are in an initial, unnamed section.
; these are accessible by passing a NULL or empty string when
; specifying a Section parameter.
An Item = a value
Another = another value
[A Section Name]
An Item = a value
Another = another value
[A Second Section]
An Item = a value
Another = another value
The file uses a java.io.BufferedReader for STORED memory mode, or a java.io.RandomAccessFile for MAPPED memory mode. (MAPPED mode is not yet implemented.)
Modifier and Type | Class and Description |
---|---|
protected class |
INIFileReader.JITLoader |
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
defaultsection |
static java.lang.String |
IFR_DEFAULT_MAP_SECTION
the Default App Map section until reassigned: ApplicationConstants
|
static java.lang.String |
IFR_DEFAULT_MAP_SECTION_COMMAND
The text string that specifies to reference the "default" AppMap section in requests.
|
static int |
IFR_MEMORY_MODE_MAPPED
FUTURE:Specifies to store file pointers and map regions in memory for storage efficiency.
|
static int |
IFR_MEMORY_MODE_STORED
Specifies to completely read and store the file in memory for performance.
|
protected boolean |
ignoreItemCase |
protected INIFileReader.JITLoader |
jit |
protected boolean |
jitstop |
protected int |
memorymode
Determines if the file should be fully loaded and stored in memory.
|
protected CaseInsensitiveHashtable |
sections |
Constructor and Description |
---|
INIFileReader()
This constructor will create an inoperable (Closed) file object.
|
INIFileReader(java.io.File file,
int memorymode)
The constructor used by the SAFSAppMapReader.
|
INIFileReader(java.io.File file,
int memorymode,
boolean ignoreItemCase)
The constructor used to force Item case sensitivity.
|
INIFileReader(java.io.File file,
int memorymode,
boolean ignoreItemCase,
java.lang.String encoding)
The constructor used to force Item case sensitivity.
|
INIFileReader(java.io.File file,
int memorymode,
java.lang.String encoding)
The constructor used by the SAFSAppMapReader.
|
INIFileReader(java.io.InputStream stream,
int memorymode,
boolean ignoreItemCase)
The constructor used to force Item case sensitivity while using an InputStream.
|
INIFileReader(java.io.InputStream stream,
int memorymode,
boolean ignoreItemCase,
java.lang.String encoding)
The constructor used to force Item case sensitivity while using an InputStream.
|
Modifier and Type | Method and Description |
---|---|
void |
clearCache()
Clears any internally stored cache of prefetched items.
|
protected void |
clearHashtables()
All the stored Hashtables and the parent sections Hashtable are clear()ed.
|
void |
close()
Closes the file (if still open) and releases all stored resources via clearHashtables().
|
protected void |
closeJIT()
Shutdown the JIT file processor.
|
java.lang.String |
getAppMapItem(java.lang.String section,
java.lang.String item)
Lookup an item in a particular section of the map.
|
java.lang.String |
getDefaultSection()
Return the "default" section setting
|
java.lang.String |
getItem(java.lang.String section,
java.lang.String item) |
java.util.Vector |
getItems(java.lang.String section)
Returns the list of items in a section.
|
int |
getMode()
Retrieves the memorymode (STORED or MAPPED)
|
java.util.Hashtable |
getNewHashtable(int size)
Instantiates a new Hashtable or CaseInsensitiveHashtable depending on the type of
storage to be used.
|
java.util.Vector |
getSections()
Retrieve the list of sections.
|
int |
setDefaultSection(java.lang.String section)
Set the "default" section.
|
protected void |
tryJITLoader()
Will run the JITLoader to populate the cache if the memorymode is appropriate.
|
closeReader, getFilename, getFullpath, isClosed, isEOF, open, openFile, openStream, readLine, resetpointers, setFile, setStream
protected boolean ignoreItemCase
protected CaseInsensitiveHashtable sections
public static final int IFR_MEMORY_MODE_STORED
public static final int IFR_MEMORY_MODE_MAPPED
public static final java.lang.String IFR_DEFAULT_MAP_SECTION_COMMAND
public static final java.lang.String IFR_DEFAULT_MAP_SECTION
protected int memorymode
In this mode, a helper thread runs in the background populating our internal storage. The underlying file stream will actually be closed once the helper thread has loaded all values into memory. Yet, this file instance remains valid servicing data requests until it receives the official close() request from the object owner.
For much larger files, it may be more efficient to simply store pointers to key locations in the file and then map sections in and out of memory as needed. For this there will be the IFR_MEMORY_MODE_MAPPED mode.
The initial release of this file handler only supports the STORED memorymode. However, the MAPPED memory mode will be implemented using the RandomAccessFile and FileChannel support in Java.
protected java.lang.String defaultsection
protected INIFileReader.JITLoader jit
protected boolean jitstop
public INIFileReader()
public INIFileReader(java.io.File file, int memorymode)
super(file);
file
- A valid File object for the file to be opened.
memorymode
- the memory model for this handler to use: STORED or MAPPED. Currently
only the STORED model is used.public INIFileReader(java.io.File file, int memorymode, java.lang.String encoding)
super(file);
file
- A valid File object for the file to be opened.
memorymode
- the memory model for this handler to use: STORED or MAPPED. Currently
only the STORED model is used.
encoding
- a valid Charset encoding like "UTF-16", etc...public INIFileReader(java.io.File file, int memorymode, boolean ignoreItemCase)
file
- A valid File object for the file to be opened.
memorymode
- the memory model for this handler to use: STORED or MAPPED. Currently
only the STORED model is used.ignoreItemCase
- set to FALSE to make Item NAMES case-sensitive. By default Item
names are not case-sensitive.public INIFileReader(java.io.File file, int memorymode, boolean ignoreItemCase, java.lang.String encoding)
file
- A valid File object for the file to be opened.
memorymode
- the memory model for this handler to use: STORED or MAPPED. Currently
only the STORED model is used.ignoreItemCase
- set to FALSE to make Item NAMES case-sensitive. By default Item
names are not case-sensitive.encoding
- a valid Charset encoding like "UTF-16", etc...public INIFileReader(java.io.InputStream stream, int memorymode, boolean ignoreItemCase)
stream
- A valid InputStream object for the data to be read.
memorymode
- the memory model for this handler to use: STORED or MAPPED. Currently
only the STORED model is used.ignoreItemCase
- set to FALSE to make Item NAMES case-sensitive. By default Item
names are not case-sensitive.ClassLoader.getSystemResourceAsStream(java.lang.String)
public INIFileReader(java.io.InputStream stream, int memorymode, boolean ignoreItemCase, java.lang.String encoding)
stream
- A valid InputStream object for the data to be read.
memorymode
- the memory model for this handler to use: STORED or MAPPED. Currently
only the STORED model is used.ignoreItemCase
- set to FALSE to make Item NAMES case-sensitive. By default Item
names are not case-sensitive.encoding
- a valid Charset encoding like "UTF-16", etc...ClassLoader.getSystemResourceAsStream(java.lang.String)
protected void tryJITLoader()
protected void clearHashtables()
protected void closeJIT()
public void close()
close
in class FileLineReader
closeJIT()
,
clearHashtables()
public java.lang.String getAppMapItem(java.lang.String section, java.lang.String item)
section
- the section of the Map to find an item in. If section is null, an empty
String will be used to identify the the first, unnamed section. This is not
case-sensitive. To use the "default" section, specify "DefaultMapSection"
for this parameter. All "keys" are stored in lower-case.
item
- the item in the section to find a value on. This is not case-sensitive.
If the item parameter is null or empty then a null value will be returned.
All "keys" are stored in lower-case.
public java.lang.String getItem(java.lang.String section, java.lang.String item)
public int getMode()
public java.util.Vector getSections()
public java.lang.String getDefaultSection()
public int setDefaultSection(java.lang.String section)
section
- the section to set as default. If the value is null or 0-length,
then we will set the default to be the first, unnamed section.
public java.util.Vector getItems(java.lang.String section)
section
- the section to query for list items. If the value is null or 0-length,
then we will get the list of items in the first, unnamed section. If the
value is DEFAULTMAPSECTION, then we will get the list of items in the
"default" section.
public void clearCache()
public java.util.Hashtable getNewHashtable(int size)
Copyright © SAS Institute. All Rights Reserved.