Class IniFile
- Author:
- Christopher Mindus
Constructor Summary
ConstructorDescriptionLoads the contents a the opened file (typically from a JAR or ZIP file).Loads the contents a the opened file (typically from a JAR or ZIP file).The constructor loads the contents of the file.The constructor loads the contents of the file.Loads the contents a the opened file (typically from a JAR or ZIP file).Loads the contents a the opened file (typically from a JAR or ZIP file).The constructor loads the contents of the file.The constructor loads the contents of the file.Method Summary
Modifier and TypeMethodDescriptionstatic IniFile
createNewIniFile
(boolean isCaseSensitive, String fileName) Creates a new editable INI file.static IniFile
createNewIniFile
(String fileName) Creates a new editable INI file.boolean
deleteSection
(String name) Removes a section from the INI file.boolean
Checked if untitled sections headings should be created.Gets an item string in a section.boolean
Gets a boolean value from an item.int
Gets a integer value from an item.Gets an item string in a section with default data if not found.Gets the file name of the ini file.Gets all the item elements in a section.getSectionItems
(String section) Gets a copy of the hash table of a section.Gets all the section elements in the file.int
Gets number of elements in a section.boolean
Checks if the INI file has changed and might need a "save".boolean
Check if this file needs to be reloaded.boolean
reload
(boolean force) Reload internal state from external sources.void
removeAllItems
(String section) Removes all items defined in a section.boolean
renameSection
(String oldName, String newName) Renames a section in the INI file.void
save
(OutputStream out) Saves the INI file to an OutputStream without closing it.void
save2
(XOutputFile out) Saves the INI file to an open PhantomOutputFile without closing it.void
saveFile()
Saves all changes (if any) made to the file.void
setCreateUntitledSectionHeadings
(boolean on) Sets if untitled sections headings should be created or not.void
Sets the topic and item to a specific boolean (0 or 1).void
Sets the topic and item to a specific integer.void
Sets the topic and item to a specific string.void
Sets the topic and item to a specific string.void
Adds a set of items that does not include the equal sign to a topic.void
Adds a set of items that does not include the equal sign to a topic.void
Sets the topic and item to a specific string.void
Sets the topic and item to a specific string.void
Sets the topic and item to a specific string.void
Sets the topic and item to a specific string.void
Sets the topic and item to a specific string.void
Sets the topic and item to a specific string.
Constructor Details
IniFile
The constructor loads the contents of the file.- Throws:
IOException
- if an I/O error occurs.FileNotFoundException
- if the file is not found.
IniFile
The constructor loads the contents of the file.- Throws:
IOException
- if an I/O error occurs.FileNotFoundException
- if the file is not found.
IniFile
The constructor loads the contents of the file. SetisEditable
totrue
if the contents of the file may be changed and later saved.- Throws:
IOException
- if an I/O error occurs.FileNotFoundException
- if the file is not found.
IniFile
public IniFile(boolean isCaseSensitive, String fileName, boolean isEditable) throws IOException, FileNotFoundException The constructor loads the contents of the file. SetisEditable
totrue
if the contents of the file may be changed and later saved.- Throws:
IOException
- if an I/O error occurs.FileNotFoundException
- if the file is not found.
IniFile
Loads the contents a the opened file (typically from a JAR or ZIP file).- Throws:
IOException
- if an I/O error occurs.
IniFile
Loads the contents a the opened file (typically from a JAR or ZIP file).- Throws:
IOException
- if an I/O error occurs.
IniFile
Loads the contents a the opened file (typically from a JAR or ZIP file).- Throws:
IOException
- if an I/O error occurs.
IniFile
Loads the contents a the opened file (typically from a JAR or ZIP file).- Throws:
IOException
- if an I/O error occurs.
Method Details
createNewIniFile
Creates a new editable INI file.createNewIniFile
Creates a new editable INI file.setCreateUntitledSectionHeadings
public void setCreateUntitledSectionHeadings(boolean on) Sets if untitled sections headings should be created or not.doCreateUntitledSectionHeadings
public boolean doCreateUntitledSectionHeadings()Checked if untitled sections headings should be created.needsReload
public boolean needsReload()Check if this file needs to be reloaded.reload
Reload internal state from external sources.- Parameters:
force
- Force the reload flag.- Returns:
- true for success, false for nothing done (failure is reported by IOException).
- Throws:
IOException
getFileName
Gets the file name of the ini file.getSections
Gets all the section elements in the file.getItems
Gets all the item elements in a section.- Returns:
- null If section not found.
getSectionItems
Gets a copy of the hash table of a section.getSize
Gets number of elements in a section.- Returns:
- 0 If section not found.
getData
Gets an item string in a section.- Returns:
- null If no item is found or if the item did not contain any data (i.e. as "ItemDoesNotHave An EqualSign".
getData
Gets an item string in a section with default data if not found.getData
Gets a integer value from an item.getData
Gets a boolean value from an item.setItem
Sets the topic and item to a specific integer. If the topic or item doesn't exist, they will be created. Note that the topic may be in any character case (and any existing entry will preserve the original case). New topics/items are added at the end of the topic or the file respectively.Use the method
saveFile
to save all changes made to the file.setItem
Sets the topic and item to a specific boolean (0 or 1). If the topic or item doesn't exist, they will be created. Note that the topic may be in any character case (and any existing entry will preserve the original case). New topics/items are added at the end of the topic or the file respectively.Use the method
saveFile
to save all changes made to the file.setItem
Sets the topic and item to a specific string. If the topic or item doesn't exist, they will be created. Note that the topic may be in any character case (and any existing entry will preserve the original case). New topics/items are added at the end of the topic or the file respectively.Use the method
saveFile
to save all changes made to the file.setItem
Sets the topic and item to a specific string. If the topic or item doesn't exist, they will be created. Note that the topic may be in any character case (and any existing entry will preserve the original case). New topics/items are added at the end of the topic or the file respectively.This method doesn't do anything if the item already has the specified data.
Use the method
saveFile
to save all changes made to the file.setItems
Adds a set of items that does not include the equal sign to a topic. If the topic doesn't exist, it will be created. Note that the topic may be in any character case (and any existing entry will preserve the original case). New topics/items are added at the end of the topic or the file respectively.Use the method
saveFile
to save all changes made to the file.setItems
Adds a set of items that does not include the equal sign to a topic. If the topic doesn't exist, it will be created. Note that the topic may be in any character case (and any existing entry will preserve the original case). New topics/items are added at the end of the topic or the file respectively.Use the method
saveFile
to save all changes made to the file.setItems
Sets the topic and item to a specific string. If the topic or item doesn't exist, they will be created. Note that the topic may be in any character case (and any existing entry will preserve the original case). New topics/items are added at the end of the topic or the file respectively.Use the method
saveFile
to save all changes made to the file.setItems
public void setItems(String section, Hashtable<String, String> itemDataPairs, String newSectionHeadingText) Sets the topic and item to a specific string. If the topic or item doesn't exist, they will be created. Note that the topic may be in any character case (and any existing entry will preserve the original case). New topics/items are added at the end of the topic or the file respectively.Use the method
saveFile
to save all changes made to the file.setItems
Sets the topic and item to a specific string. If the topic or item doesn't exist, they will be created. Note that the topic may be in any character case (and any existing entry will preserve the original case). New topics/items are added at the end of the topic or the file respectively.Use the method
saveFile
to save all changes made to the file.setItems
public void setItems(String section, HashMap<String, String> itemDataPairs, String newSectionHeadingText) Sets the topic and item to a specific string. If the topic or item doesn't exist, they will be created. Note that the topic may be in any character case (and any existing entry will preserve the original case). New topics/items are added at the end of the topic or the file respectively.Use the method
saveFile
to save all changes made to the file.setItems
Sets the topic and item to a specific string. If the topic or item doesn't exist, they will be created. Note that the topic may be in any character case (and any existing entry will preserve the original case). New topics/items are added at the end of the topic or the file respectively.Use the method
saveFile
to save all changes made to the file.setItems
public void setItems(String section, Set<Map.Entry<String, String>> entries, String newSectionHeadingText) Sets the topic and item to a specific string. If the topic or item doesn't exist, they will be created. Note that the topic may be in any character case (and any existing entry will preserve the original case). New topics/items are added at the end of the topic or the file respectively.Use the method
saveFile
to save all changes made to the file.removeAllItems
Removes all items defined in a section.deleteSection
Removes a section from the INI file. This will comment the section heading and remove all the uncommented items in it.- Returns:
- true for success; false for failure.
renameSection
Renames a section in the INI file. The section should not contain the [brackets]. To remove a section from the INI file, i.e. to comment it, just setnewName
tonull
. This will comment the section heading and remove all the uncommented items in it.- Returns:
- true for success; false for failure.
hasChanged
public boolean hasChanged()Checks if the INI file has changed and might need a "save".saveFile
Saves all changes (if any) made to the file. Before the save is performed, a backup file as "filename[.extension].bak" is created.- Throws:
IOException
- if an I/O error occurs.
save2
Saves the INI file to an open PhantomOutputFile without closing it.- Throws:
IOException
- if an I/O error occurs.
save
Saves the INI file to an OutputStream without closing it.- Throws:
IOException
- if an I/O error occurs.