Package gov.usgs.util

Class 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
    Format Example:
     #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 start
      static java.lang.String COMMENT_START
      String for representing a comment start
      static java.lang.String PROPERTY_DELIMITER
      String to delimit properties
      static java.lang.String SECTION_END
      String to represent a section end
      static java.lang.String SECTION_START
      String to represent a section start
      • Fields inherited from class java.util.Properties

        defaults
    • Constructor Summary

      Constructors 
      Constructor Description
      Ini()
      Same as new Ini(null).
      Ini​(java.util.Properties properties)
      Construct a new Ini with defaults.
    • 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
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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
    • Constructor Detail

      • Ini

        public Ini()
        Same as new Ini(null).
      • Ini

        public Ini​(java.util.Properties properties)
        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 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 class java.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 class java.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 class java.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 class java.util.Properties
        Parameters:
        out - the PrintWriter used for writing.