Package gov.usgs.util

Class Ini

All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>
Direct Known Subclasses:
Config

public class Ini extends 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:
  • Field Details

  • Constructor Details

    • Ini

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

      public Ini(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 Details

    • getSections

      public HashMap<String,Properties> getSections()
      Returns:
      the section properties map.
    • getSectionProperty

      public String getSectionProperty(String section, 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 Object setSectionProperty(String section, String key, 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(InputStream inStream) throws IOException
      Read an Ini input stream.
      Overrides:
      load in class Properties
      Parameters:
      inStream - the input stream to read.
      Throws:
      IOException - if unable to parse input stream.
    • write

      public static void write(Properties props, PrintWriter writer, String header) throws 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:
      IOException - if unable to write output.
    • store

      public void store(OutputStream out, String header) throws IOException
      Calls write(new PrintWriter(out), header).
      Overrides:
      store in class Properties
      Throws:
      IOException
    • save

      public void save(OutputStream out)
      Write properties to an OutputStream.
      Parameters:
      out - the OutputStream used for writing.
    • list

      public void list(PrintStream out)
      Write properties to a PrintStream.
      Overrides:
      list in class Properties
      Parameters:
      out - the PrintStream used for writing.
    • list

      public void list(PrintWriter out)
      Write properties to a PrintWriter.
      Overrides:
      list in class Properties
      Parameters:
      out - the PrintWriter used for writing.