Interface FileReader<C extends FileReaderContext>
- All Known Implementing Classes:
CSVFileReader
,XLSFileReader
public interface FileReader<C extends FileReaderContext>
A reader for a file of a particular type. Responsible for the physical parsing of a file into
conceptual data records for the import flow
- Author:
- Phillip Verheyden (phillipuniverse)
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Whether or not this reader is applicable for the current contextlong
countTotalItems
(InputStream file) Counts all of the data records within the file.createParsingContext
(InputStream fileStream, long dataLinesToSkip) Creates a parsing context that is passed back throughout the rest of the parsing flows.long
currentLineNumber
(C context) The current line that the context is pointing to, 1-indexedString[]
getHeaders
(C context) Obtains the headers for the given contextboolean
Whether or not there are more data records to read as determined bycontext
.readNextLine
(C context) Returns the next row of data.
-
Method Details
-
canHandle
Whether or not this reader is applicable for the current context- Parameters:
fileType
- type of the file that should be read- Returns:
- whether or not this can handle the given file type
-
createParsingContext
Creates a parsing context that is passed back throughout the rest of the parsing flows. This must be invoked before attempting to invoke the parsing logic, but is not required for couting records in the file. Any data necessary to read off items, open additional resources, etc should be initialized here and stored within the returned context- Parameters:
fileStream
- the underlying file that should be read fromdataLinesToSkip
- how many lines should be skipped from the read in file. Assuming there is a header line, given a current line number the lines to skip should subtract 2- Returns:
- a context with reader-specific variables passed back through the lifecycle of the processing flow
- Throws:
IOException
-
countTotalItems
Counts all of the data records within the file. This should not include all of the physical lines within the file. For instance this should not include the header line or any lines that are denoted as comments- Parameters:
file
- file to count records for- Returns:
- the total number of data records in the file
-
getHeaders
Obtains the headers for the given context- Parameters:
context
- the context initialized bycreateParsingContext(InputStream, long)
- Returns:
- the headers from the file
-
currentLineNumber
The current line that the context is pointing to, 1-indexed- Parameters:
context
- the context initialized bycreateParsingContext(InputStream, long)
- Returns:
- the current line number that this reader is pointing to based on the context
-
hasNext
Whether or not there are more data records to read as determined bycontext
. Should be used as a guard againstreadNextLine(FileReaderContext)
to protect against an attempt at reading too far- Parameters:
context
- the context initialized bycreateParsingContext(InputStream, long)
- Returns:
- whether or not there are more data records to read
-
readNextLine
Returns the next row of data. Keys correspond to the headers and values are the specific values for those headers- Parameters:
context
- the context initialized bycreateParsingContext(InputStream, long)
- Returns:
- a row of data from the file specified by
context
-