Package loci.common

Class IniParser


  • public class IniParser
    extends Object
    A simple parser for INI configuration files. Supports pound (#) as comments, and backslash (\) to continue values across multiple lines.
    Author:
    Curtis Rueden ctrueden at wisc.edu
    • Constructor Detail

      • IniParser

        public IniParser()
    • Method Detail

      • setCommentDelimiter

        public void setCommentDelimiter​(String delimiter)
        Set the String that identifies a comment. Defaults to "#".
        Parameters:
        delimiter - the String used to identify comments
      • setBackslashContinuesLine

        public void setBackslashContinuesLine​(boolean slashContinues)
        Set whether or not a '\' at the end of a line signifies that the line continues on the following line. By default, a '\' does continue the line.
        Parameters:
        slashContinues - true if a '\' at the end of a line signifies that the line continues on the following line
      • parseINI

        public IniList parseINI​(String path)
                         throws IOException
        Parses the INI-style configuration data from the given resource.
        Parameters:
        path - the name of the resource to read
        Returns:
        the IniList parsed from the named resource
        Throws:
        IOException - if the resource cannot be read
        See Also:
        openTextResource(String)
      • parseINI

        public IniList parseINI​(String path,
                                Class<?> c)
                         throws IOException
        Parses the INI-style configuration data from the given resource, using the given class to find the resource.
        Parameters:
        path - the name of the resource to read
        c - the Class to use for finding the named resource
        Returns:
        the IniList parsed from the named resource
        Throws:
        IOException - if the resource cannot be read
        See Also:
        openTextResource(String, Class)
      • parseINI

        public IniList parseINI​(File file)
                         throws IOException
        Parses the INI-style wrapping the given file in a BufferedReader
        Parameters:
        file - the file on disk from which to read
        Returns:
        the IniList parsed from the file
        Throws:
        IOException - if the file cannot be read
      • parseINI

        public IniList parseINI​(BufferedReader in)
                         throws IOException
        Parses the INI-style configuration data from the given input stream.
        Parameters:
        in - the BufferedReader stream from which to read
        Returns:
        the IniList parsed from the reader
        Throws:
        IOException - if the stream cannot be read
      • openTextResource

        public static BufferedReader openTextResource​(String path)
        Opens a buffered reader for the given resource.
        Parameters:
        path - the name of the resource to read
        Returns:
        the BufferedReader corresponding to the named resource
        See Also:
        openTextResource(String)
      • openTextResource

        public static BufferedReader openTextResource​(String path,
                                                      Class<?> c)
        Opens a buffered reader for the given resource.
        Parameters:
        path - the name of the resource to read
        c - the Class to use for finding the named resource
        Returns:
        the BufferedReader corresponding to the named resource
        See Also:
        openTextResource(String)