Package gov.usgs.util
Class Ini
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<Object,
Object>
- Direct Known Subclasses:
Config
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
String for representing an alternate comment startstatic final String
String for representing a comment startstatic final String
String to delimit propertiesstatic final String
String to represent a section endstatic final String
String to represent a section startFields inherited from class java.util.Properties
defaults
-
Constructor Summary
ConstructorsConstructorDescriptionIni()
Same as new Ini(null).Ini
(Properties properties) Construct a new Ini with defaults. -
Method Summary
Modifier and TypeMethodDescriptiongetSectionProperty
(String section, String key) Get a section property.void
list
(PrintStream out) Write properties to a PrintStream.void
list
(PrintWriter out) Write properties to a PrintWriter.void
load
(InputStream inStream) Read an Ini input stream.void
save
(OutputStream out) Write properties to an OutputStream.setSectionProperty
(String section, String key, String value) Set a section property.void
store
(OutputStream out, String header) Calls write(new PrintWriter(out), header).static void
write
(Properties props, PrintWriter writer, 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 Details
-
COMMENT_START
String for representing a comment start- See Also:
-
ALTERNATE_COMMENT_START
String for representing an alternate comment start- See Also:
-
SECTION_START
String to represent a section start- See Also:
-
SECTION_END
String to represent a section end- See Also:
-
PROPERTY_DELIMITER
String to delimit properties- See Also:
-
-
Constructor Details
-
Ini
public Ini()Same as new Ini(null). -
Ini
Construct a new Ini with defaults.- Parameters:
properties
- a Properties or Ini object with defaults. If an Ini object, also makes a shallow copy of sections.
-
-
Method Details
-
getSections
- Returns:
- the section properties map.
-
getSectionProperty
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
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
Read an Ini input stream.- Overrides:
load
in classProperties
- Parameters:
inStream
- the input stream to read.- Throws:
IOException
- if unable to parse input stream.
-
write
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:
IOException
- if unable to write output.
-
store
Calls write(new PrintWriter(out), header).- Overrides:
store
in classProperties
- Throws:
IOException
-
save
Write properties to an OutputStream.- Parameters:
out
- the OutputStream used for writing.
-
list
Write properties to a PrintStream.- Overrides:
list
in classProperties
- Parameters:
out
- the PrintStream used for writing.
-
list
Write properties to a PrintWriter.- Overrides:
list
in classProperties
- Parameters:
out
- the PrintWriter used for writing.
-