Class StreamPatternExtractor


  • public class StreamPatternExtractor
    extends Object
    Extracts regular expression patterns and/or applied templates from character streams. If a pattern has a corresponding template, then the template will be applied to yield the extraction result. If no corresponding template exists, then the entire match is yielded verbatim.
    See Also:
    PatternTemplate
    • Constructor Detail

      • StreamPatternExtractor

        public StreamPatternExtractor()
    • Method Detail

      • getPatterns

        public Map<String,​Pattern> getPatterns()
        Mapping of names to regular expression patterns to extract from the stream.
        Returns:
        the patterns' Map keyed with an identifier that may be reused in the templates' Map.
      • getTemplates

        public Map<String,​PatternTemplate> getTemplates()
        Mapping of names to optional templates to use for yielding pattern match results.
        Returns:
        the templates' Map keyed with an identifier that has to match a pattern's key.
      • extract

        public Iterable<Map.Entry<String,​String>> extract​(Reader reader)
        Extracts regular expression patterns from a character streams. Returns a mapping of names to the results of pattern extraction (literal match or applied template).

        Patterns are resolved lazily; only as much of the stream is read in order to satisfy a request for a specific key in the returned map.

        Note: If an IOException is encountered when accessing the stream, the exception is caught and suppressed. This results in null values being returned for values not extracted before the exception occurred.

        Parameters:
        reader - the character stream .
        Returns:
        a mapping of names to pattern match results (literal match or applied template).