Module bus.setting

Class IniSetting

All Implemented Interfaces:
Serializable, Cloneable, Iterable<IniElement>, Collection<IniElement>, List<IniElement>, RandomAccess, SequencedCollection<IniElement>

public class IniSetting extends ArrayList<IniElement>
Represents the in-memory structure of an INI file, extending ArrayList<IniElement>. An empty line in the INI file is represented by a null element in this list. To create an instance of this class programmatically, use the INI builder.
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Details

    • IniSetting

      public IniSetting()
      Constructs an empty list with an initial capacity of ten.
    • IniSetting

      public IniSetting(int initialCapacity)
      Constructs an empty list with the specified initial capacity.
      Parameters:
      initialCapacity - the initial capacity of the list.
    • IniSetting

      public IniSetting(Collection<? extends IniElement> c)
      Constructs a list containing the elements of the specified collection.
      Parameters:
      c - the collection whose elements are to be placed into this list.
  • Method Details

    • toString

      public String toString()
      Returns a string representation of the INI data, formatted as a valid INI file.
      Overrides:
      toString in class AbstractCollection<IniElement>
      Returns:
      The INI content as a string.
    • toProperties

      public Props toProperties(String delimiter)
      Converts the INI data into a Props object. The keys in the resulting properties will be a combination of the section name and the property key, joined by the specified delimiter.

      For example, with a delimiter of '.':

       [se1]
       key1=value1
       
      becomes a property with the key "se1.key1".
      Parameters:
      delimiter - The string to use for joining the section name and property key. If null, only the property key is used.
      Returns:
      A Props object representing the INI data.
    • toProperties

      public Props toProperties()
      Converts the INI data into a Props object using '.' as the delimiter between section names and keys.
      Returns:
      A Props object.
      See Also:
    • write

      public void write(OutputStream out, Charset charset, boolean withComment) throws IOException
      Writes the INI content to an OutputStream.
      Parameters:
      out - The output stream to write to.
      charset - The character set to use for encoding.
      withComment - If true, comments will be included in the output.
      Throws:
      IOException - if an I/O error occurs.
    • write

      public void write(OutputStream out, boolean withComment) throws IOException
      Writes the INI content to an OutputStream using UTF-8 encoding.
      Parameters:
      out - The output stream to write to.
      withComment - If true, comments will be included in the output.
      Throws:
      IOException - if an I/O error occurs.
      See Also:
    • write

      public void write(Writer writer, boolean withComment) throws IOException
      Writes the INI content to a Writer.
      Parameters:
      writer - The writer to use.
      withComment - If true, comments will be included in the output.
      Throws:
      IOException - if an I/O error occurs.
    • write

      public void write(PrintStream print, boolean withComment)
      Writes the INI content to a PrintStream.
      Parameters:
      print - The print stream to write to.
      withComment - If true, comments will be included in the output.
    • write

      public void write(File file, Charset charset, boolean withComment) throws IOException
      Writes the INI content to a File.
      Parameters:
      file - The destination file.
      charset - The character set to use.
      withComment - If true, comments will be included in the output.
      Throws:
      IOException - if an I/O error occurs.
    • write

      public void write(File file, boolean withComment) throws IOException
      Writes the INI content to a File using UTF-8 encoding.
      Parameters:
      file - The destination file.
      withComment - If true, comments will be included in the output.
      Throws:
      IOException - if an I/O error occurs.
    • write

      public void write(Path path, Charset charset, boolean withComment) throws IOException
      Writes the INI content to a Path.
      Parameters:
      path - The destination path.
      charset - The character set to use.
      withComment - If true, comments will be included in the output.
      Throws:
      IOException - if an I/O error occurs.
    • write

      public void write(Path path, boolean withComment) throws IOException
      Writes the INI content to a Path using UTF-8 encoding.
      Parameters:
      path - The destination path.
      withComment - If true, comments will be included in the output.
      Throws:
      IOException - if an I/O error occurs.