|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--puzzled.IniFile
A class for handling Windows-style INI files. The file format is as follows:
Field Summary | |
protected java.lang.String |
fileName
Name of the file |
protected java.util.Vector |
lines
Actual text lines of the file stored in a vector. |
protected boolean |
saveOnChange
If true, INI file will be saved every time a value is changed. |
protected java.util.Vector |
subjects
A vector of all subjects |
protected java.util.Vector |
values
A vector of variable value vectors grouped by subject |
protected java.util.Vector |
variables
A vector of variable name vectors grouped by subject |
Constructor Summary | |
IniFile(java.lang.String name)
Creates an INI file object using the specified name If the named file doesn't exist, create one |
|
IniFile(java.lang.String name,
boolean save)
Creates an INI file object using the specified name If the named file doesn't exist, create one |
Method Summary | |
protected boolean |
addAssignment(java.lang.String subject,
java.lang.String assignment)
Adds and assignment (i.e. |
protected void |
addSubjectLine(java.lang.String subject)
add a subject line to the end of the lines vector |
protected boolean |
addValue(java.lang.String subject,
java.lang.String variable,
java.lang.String value,
boolean addToLines)
Sets a specific subject/variable combination the given value. |
protected boolean |
createFile()
Create a new INI file. |
void |
deleteSubject(java.lang.String subject)
delete a subject and all its variables |
void |
deleteValue(java.lang.String subject,
java.lang.String variable)
delete variable within a subject |
protected int |
endOfSubject(int start)
find the line number which is 1 past the last assignment in a subject starting at a given line |
protected void |
finalize()
clean up |
protected int |
findAssignmentBetween(java.lang.String variable,
int start,
int end)
find the line containing a variable within a range of lines |
protected int |
findAssignmentLine(java.lang.String subject,
java.lang.String variable)
find the line containing a variable within a subject |
protected int |
findSubjectLine(java.lang.String subject)
find a subject line within the lines vector |
java.util.Vector |
getLines()
get a copy of the lines vector |
java.lang.String[] |
getSubjects()
get an array containing all subjects |
java.lang.String |
getValue(java.lang.String subject,
java.lang.String variable)
get the value of a variable within a subject |
java.lang.String[] |
getVariables(java.lang.String subject)
get a vector containing all variables in a subject |
protected boolean |
isanAssignment(java.lang.String line)
does the line represent an assignment? |
protected boolean |
isaSubject(java.lang.String line)
does the line represent a subject? |
void |
loadFile()
Loads and parses the INI file. |
protected void |
parseLines()
Reads lines, filling in subjects, variables and values. |
void |
saveFile()
save the lines vector back to the INI file Code modified to throw IOException by Frederic Demers for engineering project. |
protected void |
setLine(java.lang.String subject,
java.lang.String variable,
java.lang.String value)
set a line in the lines vector |
boolean |
setValue(java.lang.String subject,
java.lang.String variable,
java.lang.String value)
Sets a specific subject/variable combination the given value. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.util.Vector lines
protected java.util.Vector subjects
protected java.util.Vector variables
protected java.util.Vector values
protected java.lang.String fileName
protected boolean saveOnChange
Constructor Detail |
public IniFile(java.lang.String name) throws java.io.IOException
name
- the name of the filepublic IniFile(java.lang.String name, boolean save) throws java.io.IOException
name
- the name of the filesaveOnSet
- save file whenever a value is setMethod Detail |
public void loadFile()
protected boolean createFile() throws java.io.IOException
protected void parseLines()
protected boolean addAssignment(java.lang.String subject, java.lang.String assignment)
public boolean setValue(java.lang.String subject, java.lang.String variable, java.lang.String value) throws java.io.IOException
subject
- the subject heading (e.g. "Widget Settings")variable
- the variable name (e.g. "Color")value
- the value of the variable (e.g. "green")protected boolean addValue(java.lang.String subject, java.lang.String variable, java.lang.String value, boolean addToLines)
subject
- the subject heading (e.g. "Widget Settings")variable
- the variable name (e.g. "Color")value
- the value of the variable (e.g. "green")addToLines
- add the information to the lines vectorprotected boolean isaSubject(java.lang.String line)
line
- a string representing a line from an INI fileprotected void setLine(java.lang.String subject, java.lang.String variable, java.lang.String value)
subject
- the subject heading (e.g. "Widget Settings")variable
- the variable name (e.g. "Color")value
- the value of the variable (e.g. "green")protected int findAssignmentLine(java.lang.String subject, java.lang.String variable)
subject
- the subject heading (e.g. "Widget Settings")variable
- the variable name (e.g. "Color")protected int findAssignmentBetween(java.lang.String variable, int start, int end)
variable
- the variable name (e.g. "Color")start
- the start of the range (inclusive)end
- the end of the range (exclusive)protected void addSubjectLine(java.lang.String subject)
subject
- the subject heading (e.g. "Widget Settings")protected int findSubjectLine(java.lang.String subject)
subject
- the subject heading (e.g. "Widget Settings")protected int endOfSubject(int start)
start
- the line number at which to start lookingprotected boolean isanAssignment(java.lang.String line)
line
- a string representing a line from an INI filepublic java.util.Vector getLines()
public java.lang.String[] getVariables(java.lang.String subject)
subject
- the subject heading (e.g. "Widget Settings")public java.lang.String[] getSubjects()
public java.lang.String getValue(java.lang.String subject, java.lang.String variable)
subject
- the subject heading (e.g. "Widget Settings")variable
- the variable name (e.g. "Color")public void deleteValue(java.lang.String subject, java.lang.String variable) throws java.io.IOException
subject
- the subject heading (e.g. "Widget Settings")variable
- the variable name (e.g. "Color")public void deleteSubject(java.lang.String subject) throws java.io.IOException
subject
- the subject heading (e.g. "Widget Settings")public void saveFile() throws java.io.IOException
protected void finalize() throws java.io.IOException
finalize
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |