Class AbstractTextDataReader
- java.lang.Object
-
- com.aquima.interactions.framework.util.textdata.AbstractTextDataReader
-
- Direct Known Subclasses:
CsvReader
,FixedWidthTextReader
public abstract class AbstractTextDataReader extends Object
Abstract base class to parse a text based resource.- Since:
- 6.3
- Author:
- Jon van Leuven
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_SKIP_LINES
The default line to start reading.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractTextDataReader(IResource resource, int skipLines, String charset)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the underlying reader.protected String
getNextLine()
Reads the next line from the file.protected abstract String[]
parseLine(String nextLine)
Parses an incoming String and returns an array of elements.TextDataContent
readAll(boolean hasHeader)
Reads the entire file into a TextDataContent object.String[]
readNext()
Reads the next line from the buffer and converts to a string array.
-
-
-
Field Detail
-
DEFAULT_SKIP_LINES
public static final int DEFAULT_SKIP_LINES
The default line to start reading.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractTextDataReader
protected AbstractTextDataReader(IResource resource, int skipLines, String charset) throws ResourceException
- Throws:
ResourceException
-
-
Method Detail
-
readAll
public TextDataContent readAll(boolean hasHeader) throws IOException
Reads the entire file into a TextDataContent object.- Parameters:
hasHeader
- Indicator if the first row is treated as header.- Returns:
- a TextDataContent.
- Throws:
IOException
- if bad things happen during the read
-
readNext
public String[] readNext() throws IOException
Reads the next line from the buffer and converts to a string array.- Returns:
- a string array with each comma-separated element as a separate entry.
- Throws:
IOException
- if bad things happen during the read
-
getNextLine
protected String getNextLine() throws IOException
Reads the next line from the file. Empty lines are skipped.- Returns:
- the next line from the file without trailing newline
- Throws:
IOException
- if bad things happen during the read
-
parseLine
protected abstract String[] parseLine(String nextLine) throws IOException
Parses an incoming String and returns an array of elements.- Parameters:
nextLine
- the string to parse- Returns:
- the comma-tokenized list of elements, or null if nextLine is null
- Throws:
IOException
- if bad things happen during the read
-
close
public void close() throws IOException
Closes the underlying reader.- Throws:
IOException
- if the close fails
-
-