Class SynchronizedSpotDataParser
java.lang.Object
net.sf.basedb.util.importer.spotdata.SynchronizedSpotDataParser
- All Implemented Interfaces:
AutoCloseable
,BfsParser
A parser that synchronizes the parsing of multiple underlying
data parsers and a master reporter annotations parser. Before
it can be used a master parser must be set by
setMasterParser(AnnotationParser)
.
Then, one or more data parsers is needed addDataParser(DataParser)
.
All parsers must have been parsed to beginning-of-file
(eg. AnnotationParser.parseToBof()
and DataParser.parseToBof()
) before
they are added to this class. The parse(EventHandler)
method will then
call AnnotationParser.nextData()
and DataParser.nextData()
for each parser as long as data is returned. All parsers must resturn at least
as many data lines as the master parser or an exception is thrown.- Version:
- 2.15
- Author:
- Nicklas
- Last modified
- $Date: 2010-04-20 10:02:16 +0200 (ti, 20 apr 2010) $
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
This class holds information that is sent to the event handler whenDATA_EVENT
:s are sent. -
Field Summary
Modifier and TypeFieldDescriptionstatic final EventType<SynchronizedSpotDataParser.SynchronizedData[]>
Event type that is issued for each data line.private List<DataParser>
private AnnotationParser
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addDataParser
(DataParser parser) Adds a data parser.void
close()
Close the parser and relase underlying system resources that are associated with it.int
Get the current line number.Get the filename of the file that is being parsed.long
Get the size of the file that is being parsed.long
Get the number of parsed bytes so far.void
parse
(EventHandler handler) Begin parsing and issue events to the given event handler.void
setMasterParser
(AnnotationParser parser) Sets the master parser.
-
Field Details
-
DATA_EVENT
Event type that is issued for each data line. The event data is an array withSynchronizedSpotDataParser.SynchronizedData
objects. The first entry in the array contains information from the master parser, the following entries contain information for the data parsers in the order they were added. -
masterParser
-
dataParsers
-
-
Constructor Details
-
SynchronizedSpotDataParser
public SynchronizedSpotDataParser()Create a new synchronized data parser.
-
-
Method Details
-
setMasterParser
Sets the master parser. This parser should normally parse a reporter annotations file. -
addDataParser
Adds a data parser. The parser should parse a data file that has the same number of data lines as the master parser. Each line contains data identified by the corresponding reporter in the master parser file. -
getFilename
Description copied from interface:BfsParser
Get the filename of the file that is being parsed.- Specified by:
getFilename
in interfaceBfsParser
- Returns:
- Always null, since we are parsing multiple files
-
getFileSize
public long getFileSize()Description copied from interface:BfsParser
Get the size of the file that is being parsed.- Specified by:
getFileSize
in interfaceBfsParser
- Returns:
- The file size of the master parser
-
getCurrentLine
public int getCurrentLine()Description copied from interface:BfsParser
Get the current line number.- Specified by:
getCurrentLine
in interfaceBfsParser
- Returns:
- The current line number in the file parsed by the master parser
-
getParsedBytes
public long getParsedBytes()Description copied from interface:BfsParser
Get the number of parsed bytes so far.- Specified by:
getParsedBytes
in interfaceBfsParser
- Returns:
- The number of bytes parsed by the master parser
-
close
public void close()Description copied from interface:BfsParser
Close the parser and relase underlying system resources that are associated with it.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceBfsParser
-
parse
Begin parsing and issue events to the given event handler. For each data line aDATA_EVENT
is sent to the event handler. When the end-of-file has been aDataParser.END_OF_FILE_EVENT
is sent.- Parameters:
handler
- An event handler- Throws:
IOException
- If there is an error reading the stream dataNullPointerException
- If the event handler or master parser is null
-