Class TemplateReader

  • All Implemented Interfaces:
    Closeable, AutoCloseable, Readable

    public class TemplateReader
    extends FilterReader
    A template reader replaces any occurences of ${key} or $key in the underlying stream with the string representations of any non-null value returned by a given resolver for that key.
    • Constructor Detail

      • TemplateReader

        public TemplateReader​(Reader in,
                              Map map)
        Constructs a template reader for the given reader stream and a resolver given by a Map.
        Parameters:
        in - the underlying reader
        map - the map to serve as resolver
      • TemplateReader

        public TemplateReader​(Reader in,
                              TemplateReader.Resolver resolver)
        Constructs a template reader for the given reader stream and the given resolver.
        Parameters:
        in - the underlying reader
        resolver - the resolver
    • Method Detail

      • getKeyIndicator

        public char getKeyIndicator()
        Gets the key indicator.
        Returns:
        the key indicator, defaults to '$'.
      • setKeyIndicator

        public void setKeyIndicator​(char keyIndicator)
        Sets the key indicator.
        Parameters:
        keyIndicator - the key indicator, must not be a digit, letter or whitespace.
      • read

        public int read​(char[] cbuf)
                 throws IOException
        Read characters into an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.
        Overrides:
        read in class Reader
        Parameters:
        cbuf - Destination buffer
        Returns:
        The number of characters read, or -1 if the end of the stream has been reached
        Throws:
        IOException - If an I/O error occurs
      • read

        public int read​(char[] cbuf,
                        int off,
                        int len)
                 throws IOException
        Read characters into a portion of an array.
        Overrides:
        read in class FilterReader
        Throws:
        IOException - If an I/O error occurs
      • read

        public int read​(CharBuffer target)
                 throws IOException
        Attempts to read characters into the specified character buffer. The buffer is used as a repository of characters as-is: the only changes made are the results of a put operation. No flipping or rewinding of the buffer is performed.
        Specified by:
        read in interface Readable
        Overrides:
        read in class Reader
        Parameters:
        target - the buffer to read characters into
        Returns:
        The number of characters added to the buffer, or -1 if this source of characters is at its end
        Throws:
        IOException - if an I/O error occurs
        NullPointerException - if target is null
        ReadOnlyBufferException - if target is a read only buffer
      • markSupported

        public boolean markSupported()
        Tell whether this stream supports the mark() operation.
        Overrides:
        markSupported in class FilterReader
      • mark

        public void mark​(int readAheadLimit)
                  throws IOException
        Mark the present position in the stream.
        Overrides:
        mark in class FilterReader
        Throws:
        IOException - If an I/O error occurs