Package gov.usgs.util
Class Ini
- java.lang.Object
-
- java.util.Dictionary<K,V>
-
- java.util.Hashtable<java.lang.Object,java.lang.Object>
-
- java.util.Properties
-
- gov.usgs.util.Ini
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map<java.lang.Object,java.lang.Object>
- Direct Known Subclasses:
Config
public class Ini extends java.util.Properties
Ini is a Properties that supports sections. Format Rules:- Empty lines are ignored.
- Leading and trailing white space are ignored.
- Comments must be on separate lines, and begin with '#' or ';'.
- Properties are key value pairs delimited by an equals: key = value
- Section Names are on separate lines, begin with '[' and end with ']'. Any whitespace around the brackets is ignored.
- Any properties before the first section are in the "null" section
#comment about the global global = value # comment about this section ; another comment about this section [ Section Name ] section = value
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ALTERNATE_COMMENT_START
String for representing an alternate comment startstatic java.lang.String
COMMENT_START
String for representing a comment startstatic java.lang.String
PROPERTY_DELIMITER
String to delimit propertiesstatic java.lang.String
SECTION_END
String to represent a section endstatic java.lang.String
SECTION_START
String to represent a section start
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getSectionProperty(java.lang.String section, java.lang.String key)
Get a section property.java.util.HashMap<java.lang.String,java.util.Properties>
getSections()
void
list(java.io.PrintStream out)
Write properties to a PrintStream.void
list(java.io.PrintWriter out)
Write properties to a PrintWriter.void
load(java.io.InputStream inStream)
Read an Ini input stream.void
save(java.io.OutputStream out)
Write properties to an OutputStream.java.lang.Object
setSectionProperty(java.lang.String section, java.lang.String key, java.lang.String value)
Set a section property.void
store(java.io.OutputStream out, java.lang.String header)
Calls write(new PrintWriter(out), header).static void
write(java.util.Properties props, java.io.PrintWriter writer, java.lang.String header)
Write an Ini format to a PrintWriter.-
Methods inherited from class java.util.Properties
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, getProperty, getProperty, hashCode, isEmpty, keys, keySet, load, loadFromXML, merge, propertyNames, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, setProperty, size, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
-
-
-
-
Field Detail
-
COMMENT_START
public static final java.lang.String COMMENT_START
String for representing a comment start- See Also:
- Constant Field Values
-
ALTERNATE_COMMENT_START
public static final java.lang.String ALTERNATE_COMMENT_START
String for representing an alternate comment start- See Also:
- Constant Field Values
-
SECTION_START
public static final java.lang.String SECTION_START
String to represent a section start- See Also:
- Constant Field Values
-
SECTION_END
public static final java.lang.String SECTION_END
String to represent a section end- See Also:
- Constant Field Values
-
PROPERTY_DELIMITER
public static final java.lang.String PROPERTY_DELIMITER
String to delimit properties- See Also:
- Constant Field Values
-
-
Method Detail
-
getSections
public java.util.HashMap<java.lang.String,java.util.Properties> getSections()
- Returns:
- the section properties map.
-
getSectionProperty
public java.lang.String getSectionProperty(java.lang.String section, java.lang.String key)
Get a section property.- Parameters:
section
- the section, if null calls getProperty(key).key
- the property name.- Returns:
- value or property, or null if no matching property found.
-
setSectionProperty
public java.lang.Object setSectionProperty(java.lang.String section, java.lang.String key, java.lang.String value)
Set a section property.- Parameters:
section
- the section, if null calls super.setProperty(key, value).key
- the property name.value
- the property value.- Returns:
- any previous value for key.
-
load
public void load(java.io.InputStream inStream) throws java.io.IOException
Read an Ini input stream.- Overrides:
load
in classjava.util.Properties
- Parameters:
inStream
- the input stream to read.- Throws:
java.io.IOException
- if unable to parse input stream.
-
write
public static void write(java.util.Properties props, java.io.PrintWriter writer, java.lang.String header) throws java.io.IOException
Write an Ini format to a PrintWriter.- Parameters:
props
- properties to write.writer
- the writer that writes.header
- an optioal header that will appear in comments at the start of the ini format.- Throws:
java.io.IOException
- if unable to write output.
-
store
public void store(java.io.OutputStream out, java.lang.String header) throws java.io.IOException
Calls write(new PrintWriter(out), header).- Overrides:
store
in classjava.util.Properties
- Throws:
java.io.IOException
-
save
public void save(java.io.OutputStream out)
Write properties to an OutputStream.- Parameters:
out
- the OutputStream used for writing.
-
list
public void list(java.io.PrintStream out)
Write properties to a PrintStream.- Overrides:
list
in classjava.util.Properties
- Parameters:
out
- the PrintStream used for writing.
-
list
public void list(java.io.PrintWriter out)
Write properties to a PrintWriter.- Overrides:
list
in classjava.util.Properties
- Parameters:
out
- the PrintWriter used for writing.
-
-