Package edu.hm.hafner.analysis
Class ReaderFactory
java.lang.Object
edu.hm.hafner.analysis.ReaderFactory
- Direct Known Subclasses:
FileReaderFactory
Provides several useful helper methods to read the contents of a resource that is given by a
Reader.- Author:
- Ullrich Hafner
-
Constructor Summary
ConstructorsConstructorDescriptionReaderFactory(Charset charset) Creates a new factory to read a resource with a given charset.ReaderFactory(Charset charset, Function<String, String> lineMapper) Creates a new factory to read a resource with a given charset. -
Method Summary
Modifier and TypeMethodDescriptionabstract Readercreate()Creates a newReaderfor the file.Returns the character set that is used to read the stream.abstract StringReturns the name of the resource.voidparse(DefaultHandler handler) Parses the whole file with the specified SAXDefaultHandler.Parses the whole file into aDocument.Provides the lines of the file as aStreamof strings.Reads the whole file into aString.
-
Constructor Details
-
ReaderFactory
Creates a new factory to read a resource with a given charset.- Parameters:
charset- the charset to use when reading the file
-
ReaderFactory
Creates a new factory to read a resource with a given charset.- Parameters:
charset- the charset to use when reading the filelineMapper- provides a mapper to transform each of the resource lines
-
-
Method Details
-
getFileName
Returns the name of the resource.- Returns:
- the file name
-
create
Creates a newReaderfor the file.- Returns:
- a reader
-
readStream
Provides the lines of the file as aStreamof strings.- Returns:
- the file content as stream
- Throws:
ParsingException- if the file could not be read
-
readString
Reads the whole file into aString.- Returns:
- the file content as string
- Throws:
ParsingException- if the file could not be read
-
readDocument
Parses the whole file into aDocument.- Returns:
- the file content as document
- Throws:
ParsingException- if the file could not be parsed
-
getCharset
Returns the character set that is used to read the stream.- Returns:
- the character set
-
parse
Parses the whole file with the specified SAXDefaultHandler.- Parameters:
handler- the SAX handler to parse the file- Throws:
ParsingException- if the file could not be parsed
-