Class Properties.PropertiesReader

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.lang.Readable
    Enclosing class:
    Properties

    public static class Properties.PropertiesReader
    extends java.io.LineNumberReader
    This class is used to read properties lines. These lines do not terminate with new-line chars but rather when there is no backslash sign a the end of the line. This is used to concatenate multiple lines for readability.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<java.lang.String> commentLines
      Stores the comment lines for the currently processed property.
      private boolean maybeTyped  
      private java.lang.String propertyName
      Stores the name of the last read property.
      private java.lang.String propertyValue
      Stores the value of the last read property.
      (package private) java.lang.Boolean typed
      Stores if the properties are typed or not
      private java.util.List<java.lang.String> valueLines
      Stores the value lines for the currently processed property.
      • Fields inherited from class java.io.Reader

        lock
    • Constructor Summary

      Constructors 
      Constructor Description
      PropertiesReader​(java.io.Reader reader, boolean maybeTyped)
      Creates a new instance of PropertiesReader and sets the underlaying reader and the list delimiter.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static boolean checkCombineLines​(java.lang.String line)
      Checks if the passed in line should be combined with the following.
      java.util.List<java.lang.String> getCommentLines()
      Returns the comment lines that have been read for the last property.
      java.lang.String getPropertyName()
      Returns the name of the last read property.
      java.lang.String getPropertyValue()
      Returns the value of the last read property.
      java.util.List<java.lang.String> getValueLines()
      Returns the value lines that have been read for the last property.
      boolean nextProperty()
      Parses the next property from the input stream and stores the found name and value in internal fields.
      private static java.lang.String[] parseProperty​(java.lang.String line)
      Parse a property line and return the key and the value in an array.
      java.lang.String readProperty()
      Reads a property line.
      • Methods inherited from class java.io.LineNumberReader

        getLineNumber, mark, read, read, readLine, reset, setLineNumber, skip
      • Methods inherited from class java.io.BufferedReader

        close, lines, markSupported, ready
      • Methods inherited from class java.io.Reader

        nullReader, read, read, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • commentLines

        private final java.util.List<java.lang.String> commentLines
        Stores the comment lines for the currently processed property.
      • valueLines

        private final java.util.List<java.lang.String> valueLines
        Stores the value lines for the currently processed property.
      • propertyName

        private java.lang.String propertyName
        Stores the name of the last read property.
      • propertyValue

        private java.lang.String propertyValue
        Stores the value of the last read property.
      • maybeTyped

        private boolean maybeTyped
      • typed

        java.lang.Boolean typed
        Stores if the properties are typed or not
    • Constructor Detail

      • PropertiesReader

        public PropertiesReader​(java.io.Reader reader,
                                boolean maybeTyped)
        Creates a new instance of PropertiesReader and sets the underlaying reader and the list delimiter.
        Parameters:
        reader - the reader
    • Method Detail

      • readProperty

        public java.lang.String readProperty()
                                      throws java.io.IOException
        Reads a property line. Returns null if Stream is at EOF. Concatenates lines ending with "\". Skips lines beginning with "#" or "!" and empty lines. The return value is a property definition (<name> = <value>)
        Returns:
        A string containing a property value or null
        Throws:
        java.io.IOException - in case of an I/O error
      • nextProperty

        public boolean nextProperty()
                             throws java.io.IOException
        Parses the next property from the input stream and stores the found name and value in internal fields. These fields can be obtained using the provided getter methods. The return value indicates whether EOF was reached (false) or whether further properties are available (true).
        Returns:
        a flag if further properties are available
        Throws:
        java.io.IOException - if an error occurs
      • getCommentLines

        public java.util.List<java.lang.String> getCommentLines()
        Returns the comment lines that have been read for the last property.
        Returns:
        the comment lines for the last property returned by readProperty()
      • getValueLines

        public java.util.List<java.lang.String> getValueLines()
        Returns the value lines that have been read for the last property.
        Returns:
        the raw value lines for the last property returned by readProperty()
      • getPropertyName

        public java.lang.String getPropertyName()
        Returns the name of the last read property. This method can be called after nextProperty() was invoked and its return value was true.
        Returns:
        the name of the last read property
      • getPropertyValue

        public java.lang.String getPropertyValue()
        Returns the value of the last read property. This method can be called after nextProperty() was invoked and its return value was true.
        Returns:
        the value of the last read property
      • checkCombineLines

        private static boolean checkCombineLines​(java.lang.String line)
        Checks if the passed in line should be combined with the following. This is true, if the line ends with an odd number of backslashes.
        Parameters:
        line - the line
        Returns:
        a flag if the lines should be combined
      • parseProperty

        private static java.lang.String[] parseProperty​(java.lang.String line)
        Parse a property line and return the key and the value in an array.
        Parameters:
        line - the line to parse
        Returns:
        an array with the property's key and value