Class ReaderFactory

  • Direct Known Subclasses:
    FileReaderFactory

    public abstract class ReaderFactory
    extends Object
    Provides several useful helper methods to read the contents of a resource that is given by a Reader.
    Author:
    Ullrich Hafner
    • Constructor Detail

      • ReaderFactory

        public ReaderFactory​(Charset charset)
        Creates a new factory to read a resource with a given charset.
        Parameters:
        charset - the charset to use when reading the file
      • ReaderFactory

        public ReaderFactory​(Charset charset,
                             Function<String,​String> lineMapper)
        Creates a new factory to read a resource with a given charset.
        Parameters:
        charset - the charset to use when reading the file
        lineMapper - provides a mapper to transform each of the resource lines
    • Method Detail

      • getFileName

        public abstract String getFileName()
        Returns the name of the resource.
        Returns:
        the file name
      • create

        @MustBeClosed
        public abstract Reader create()
        Creates a new Reader for the file.
        Returns:
        a reader
      • readStream

        @MustBeClosed
        public Stream<String> readStream()
        Provides the lines of the file as a Stream of strings.
        Returns:
        the file content as stream
        Throws:
        ParsingException - if the file could not be read
      • readString

        public String readString()
        Reads the whole file into a String.
        Returns:
        the file content as string
        Throws:
        ParsingException - if the file could not be read
      • readDocument

        public Document readDocument()
        Parses the whole file into a Document.
        Returns:
        the file content as document
        Throws:
        ParsingException - if the file could not be parsed
      • getCharset

        public Charset getCharset()
        Returns the character set that is used to read the stream.
        Returns:
        the character set
      • parse

        public void parse​(DefaultHandler handler)
        Parses the whole file with the specified SAX DefaultHandler.
        Parameters:
        handler - the SAX handler to parse the file
        Throws:
        ParsingException - if the file could not be parsed