Package edu.hm.hafner.analysis
Class ReaderFactory
- java.lang.Object
-
- edu.hm.hafner.analysis.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 aReader.- Author:
- Ullrich Hafner
-
-
Constructor Summary
Constructors Constructor Description ReaderFactory(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
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract Readercreate()Creates a newReaderfor the file.CharsetgetCharset()Returns the character set that is used to read the stream.abstract StringgetFileName()Returns the name of the resource.voidparse(DefaultHandler handler)Parses the whole file with the specified SAXDefaultHandler.DocumentreadDocument()Parses the whole file into aDocument.Stream<String>readStream()Provides the lines of the file as aStreamof strings.StringreadString()Reads the whole file into aString.
-
-
-
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
-
-
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 newReaderfor the file.- Returns:
- a reader
-
readStream
@MustBeClosed public Stream<String> 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
public String readString()
Reads the whole file into aString.- Returns:
- the file content as string
- Throws:
ParsingException- if the file could not be read
-
readDocument
public Document readDocument()
Parses the whole file into aDocument.- 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 SAXDefaultHandler.- Parameters:
handler- the SAX handler to parse the file- Throws:
ParsingException- if the file could not be parsed
-
-