|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.util.basefile.BaseFileParser
public class BaseFileParser
Parser for serial and matrix BASEfile:s. This class will setup and
perform the line-by-line parsing, but it doesn't handle the data.
Data is handled section-wise by registering BaseFileSectionParser
:s
with setSectionParser(String, BaseFileSectionParser)
.
Sections that doens't have a registered parser are skipped.
Field Summary | |
---|---|
private Map<String,BaseFileSectionParser> |
parsers
|
private AbsoluteProgressReporter |
progress
|
private Map<String,String> |
redefinedColumnNames
|
private Map<String,Integer> |
sectionCount
|
Constructor Summary | |
---|---|
BaseFileParser()
Creates a new parser object. |
Method Summary | |
---|---|
void |
checkInterrupted()
Deprecated. In 2.16, use ThreadSignalHandler.checkInterrupted() instead |
void |
copyRedefinedColumnNames(BaseFileParser parser)
Copy redefined column names from the given parser into this parser. |
protected FlatFileParser |
getInitializedFlatFileParser(InputStream stream,
String charset)
Creates a FlatFileParser for parsing a BASEfile. |
String |
getRedefinedColumnName(String section,
String defaultName)
Get the redefined column name for a section. |
String |
getRequiredHeader(FlatFileParser ffp,
String header,
String section,
String filename)
Get the value of a required header. |
List<String> |
getRequiredHeader(FlatFileParser ffp,
String header,
String split,
String section,
String filename)
Get the value of a header as a list of sub-values. |
int |
getRequiredIndex(List<String> values,
String value,
String header,
String section,
int line,
String filename)
Get the index of value in a list of values or throw an exception if the value is not found. |
int |
getSectionCount(String section)
The number of times we have seen a certain section in the file. |
BaseFileSectionParser |
getSectionParser(String section)
Get the parser that is currently registered for a section. |
protected void |
increaseSectionCount(String section,
int count)
Counts the number of times a section has been seen in the file. |
FlatFileParser |
parse(InputStream in,
String charset)
Parse the given input stream. |
void |
setProgress(long completed,
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(String section,
String defaultName,
String redefinedName)
Redefined a column name for a specified section. |
void |
setSectionParser(String section,
BaseFileSectionParser parser)
Adds a section parser. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final Map<String,BaseFileSectionParser> parsers
private AbsoluteProgressReporter progress
private Map<String,Integer> sectionCount
private Map<String,String> redefinedColumnNames
Constructor Detail |
---|
public BaseFileParser()
Method Detail |
---|
public void setSectionParser(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(String section)
section
- The name of the section
public void setRedefinedColumnName(String section, String defaultName, String redefinedName)
section
- The section the redefined name is valid fordefaultName
- The default name (eg. 'reporter')redefinedName
- The redefined name (ef. 'Reporter ID')public String getRedefinedColumnName(String section, String defaultName)
section
- The section the redefined name is valid fordefaultName
- The default name
public 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(InputStream in, String charset) throws IOException
in
- The data stream to parsecharset
- The character set used by the data, or null
to use the configured default
IOException
- If there is any problem with the parsingpublic int getSectionCount(String section)
section
- The name of the sectionprotected void increaseSectionCount(String section, int count)
section
- The name of the sectioncount
- The count to add to the current count@Deprecated public void checkInterrupted()
ThreadSignalHandler.checkInterrupted()
instead
SignalException
if it has.
public void setProgress(long completed, String message)
ProgressReporter
protected FlatFileParser getInitializedFlatFileParser(InputStream stream, String charset)
FlatFileParser
for parsing a BASEfile.
stream
- The stream that the parser should read from.
public String getRequiredHeader(FlatFileParser ffp, String header, String section, 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 List<String> getRequiredHeader(FlatFileParser ffp, String header, String split, String section, 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(List<String> values, String value, String header, String section, int line, 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)
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |