public class BaseFileParser
extends java.lang.Object
BaseFileSectionParser
:s
with setSectionParser(String, BaseFileSectionParser)
.
Sections that doens't have a registered parser are skipped.Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.String,BaseFileSectionParser> |
parsers |
private AbsoluteProgressReporter |
progress |
private java.util.Map<java.lang.String,java.lang.String> |
redefinedColumnNames |
private java.util.Map<java.lang.String,java.lang.Integer> |
sectionCount |
Constructor and Description |
---|
BaseFileParser()
Creates a new parser object.
|
Modifier and Type | Method and Description |
---|---|
void |
copyRedefinedColumnNames(BaseFileParser parser)
Copy redefined column names from the given parser into this
parser.
|
protected FlatFileParser |
getInitializedFlatFileParser(java.io.InputStream stream,
java.lang.String charset)
Creates a
FlatFileParser for parsing a BASEfile. |
java.lang.String |
getRedefinedColumnName(java.lang.String section,
java.lang.String defaultName)
Get the redefined column name for a section.
|
java.lang.String |
getRequiredHeader(FlatFileParser ffp,
java.lang.String header,
java.lang.String section,
java.lang.String filename)
Get the value of a required header.
|
java.util.List<java.lang.String> |
getRequiredHeader(FlatFileParser ffp,
java.lang.String header,
java.lang.String split,
java.lang.String section,
java.lang.String filename)
Get the value of a header as a list of sub-values.
|
int |
getRequiredIndex(java.util.List<java.lang.String> values,
java.lang.String value,
java.lang.String header,
java.lang.String section,
int line,
java.lang.String filename)
Get the index of value in a list of values or throw an exception
if the value is not found.
|
int |
getSectionCount(java.lang.String section)
The number of times we have seen a certain section in the
file.
|
BaseFileSectionParser |
getSectionParser(java.lang.String section)
Get the parser that is currently registered for a section.
|
protected void |
increaseSectionCount(java.lang.String section,
int count)
Counts the number of times a section has been seen in the file.
|
FlatFileParser |
parse(java.io.InputStream in,
java.lang.String charset)
Parse the given input stream.
|
void |
setProgress(long completed,
java.lang.String message)
Update the progress of the parsing.
|
void |
setProgressReporter(AbsoluteProgressReporter progress)
Set a progress reporter that will be used to report
how the parsing is progressing.
|
void |
setRedefinedColumnName(java.lang.String section,
java.lang.String defaultName,
java.lang.String redefinedName)
Redefined a column name for a specified section.
|
void |
setSectionParser(java.lang.String section,
BaseFileSectionParser parser)
Adds a section parser.
|
private final java.util.Map<java.lang.String,BaseFileSectionParser> parsers
private AbsoluteProgressReporter progress
private java.util.Map<java.lang.String,java.lang.Integer> sectionCount
private java.util.Map<java.lang.String,java.lang.String> redefinedColumnNames
public void setSectionParser(java.lang.String section, BaseFileSectionParser parser)
section
- The name of the section the parser handlesparser
- The parser, or null to remove a previously
registered parserpublic BaseFileSectionParser getSectionParser(java.lang.String section)
section
- The name of the sectionpublic void setRedefinedColumnName(java.lang.String section, java.lang.String defaultName, java.lang.String redefinedName)
section
- The section the redefined name is valid fordefaultName
- The default name (eg. 'reporter')redefinedName
- The redefined name (ef. 'Reporter ID')public java.lang.String getRedefinedColumnName(java.lang.String section, java.lang.String defaultName)
section
- The section the redefined name is valid fordefaultName
- The default namepublic void copyRedefinedColumnNames(BaseFileParser parser)
parser
- The parser to copy redefined column names frompublic void setProgressReporter(AbsoluteProgressReporter progress)
progress
- A progress reporter, or null to not report progresspublic FlatFileParser parse(java.io.InputStream in, java.lang.String charset) throws java.io.IOException
in
- The data stream to parsecharset
- The character set used by the data, or null
to use the configured defaultjava.io.IOException
- If there is any problem with the parsingpublic int getSectionCount(java.lang.String section)
section
- The name of the sectionprotected void increaseSectionCount(java.lang.String section, int count)
section
- The name of the sectioncount
- The count to add to the current countpublic void setProgress(long completed, java.lang.String message)
ProgressReporter
protected FlatFileParser getInitializedFlatFileParser(java.io.InputStream stream, java.lang.String charset)
FlatFileParser
for parsing a BASEfile.stream
- The stream that the parser should read from.public java.lang.String getRequiredHeader(FlatFileParser ffp, java.lang.String header, java.lang.String section, java.lang.String filename)
FlatFileParser.getHeader(String)
to get the value of
the header. If the header is missing or has an empty value
an exception is thrown.ffp
- The flat file parserheader
- The name of the headersection
- The name of the section that is being parsedfilename
- The name of the file that is being parsed (used to
create the error message in case the header is missing)public java.util.List<java.lang.String> getRequiredHeader(FlatFileParser ffp, java.lang.String header, java.lang.String split, java.lang.String section, java.lang.String filename)
ffp
- The flat file parserheader
- The name of the headersplit
- A regular expression used to split the valuesection
- The name of the section that is being parsedfilename
- The name of the file that is being parsed (used to
create the error message in case the header is missing)public int getRequiredIndex(java.util.List<java.lang.String> values, java.lang.String value, java.lang.String header, java.lang.String section, int line, java.lang.String filename)
values
- The list of values to look invalue
- The value to look forheader
- The name of the header the values are fromsection
- The name of the section that is being parsedline
- The current line number in the parsed filefilename
- The The name of the file that is being parsed (used to
create the error message in case the header is missing)