|
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.bfs.DataParser
public class DataParser
Parser implementation that parses BFS data files. Before parsing
is started the stream to parse must be specified by calling
setInputStream(InputStream)
. The actual parsing can be done
in two different ways:
parseToBof()
and nextData()
methods.
parse(EventHandler)
method.
This parser issues the following events:
DATA_EVENT
: For each data line that is parsed.
END_OF_FILE_EVENT
: When the end of the file has been reached.
MatrixModel
class implements a simple event handler that
collects the information from the data file and provides methods
for accessing it, though it is recommended only for small files.
This class may be subclassed to provide customized behaviour.
Field Summary | |
---|---|
static EventType<String[]> |
DATA_EVENT
Event type that is issued for each data line. |
private EncoderDecoder |
decoder
|
static EventType<Object> |
END_OF_FILE_EVENT
Event type that is issued when the end-of-file had been reached. |
private FlatFileParser |
ffp
|
private String |
filename
|
private long |
fileSize
|
private InputStream |
in
|
private int |
numColumns
|
Constructor Summary | |
---|---|
DataParser()
Create a new data parser. |
Method Summary | |
---|---|
void |
close()
Close the parser and relase underlying system resources that are associated with it. |
static DataParser |
create(File file)
Utility method for creating a data parser for a file in the BASE file system. |
static DataParser |
create(File file)
Utility method for creating a data parser for a file in the local file system. |
static DataParser |
create(InputStream in,
String filename,
long fileSize)
Utility method for creating a data parser when you have an input stream. |
protected FlatFileParser |
createFlatFileParser(InputStream in)
Create a new flat file parser that can parse BFS annotation files. |
String |
decodeValue(String value)
Decode an encoded value. |
int |
getCurrentLine()
Get the current line number. |
String |
getFilename()
Get the file name that this parser is reading from. |
long |
getFileSize()
Get the size in bytes of the file that this parser is reading from. |
long |
getParsedBytes()
Get the number of parsed bytes so far. |
protected void |
handleData(EventHandler handler,
String[] data)
Handle the data event. |
protected void |
handleEndOfFile(EventHandler handler)
Handle the end-of-file event. |
String[] |
nextData()
Get the next data line in the file. |
void |
parse(EventHandler handler)
Parse the input stream and notify the specified event handler with events. |
void |
parseToBof()
Initialize parsing of the data file. |
void |
setFilename(String filename)
Set the file name that this parser is reading from. |
void |
setFileSize(long fileSize)
Set the size of the file or -1 if not known. |
void |
setInputStream(InputStream in)
Set the input stream that should be parsed. |
void |
setNumColumns(int numColumns)
Set the number of data columns that are expected to be found in this file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final EventType<String[]> DATA_EVENT
public static final EventType<Object> END_OF_FILE_EVENT
private final EncoderDecoder decoder
private InputStream in
private String filename
private long fileSize
private FlatFileParser ffp
private int numColumns
Constructor Detail |
---|
public DataParser()
Method Detail |
---|
public static DataParser create(InputStream in, String filename, long fileSize)
in
- The input stream the parser should read fromfilename
- Optional, the name of the file the input stream
is reading frompublic static DataParser create(File file)
file
- The file in the BASE file systempublic static DataParser create(File file) throws IOException
file
- The file in the local file system
IOException
public String decodeValue(String value)
TabCrLfEncoderDecoder
.
value
- The encoded value
public String getFilename()
getFilename
in interface BfsParser
public void setFilename(String filename)
public long getFileSize()
getFileSize
in interface BfsParser
public void setFileSize(long fileSize)
public void close()
BfsParser
close
in interface BfsParser
public void setInputStream(InputStream in)
in
- The stream to parse (in UTF-8 format)public void setNumColumns(int numColumns)
numColumns
- The number of columns or -1 to let the parser
automatically detect this on the first data linepublic void parse(EventHandler handler) throws IOException
handler
- An event handler
IOException
- If there is an error reading the stream data
NullPointerException
- If the stream or event handler is nullpublic void parseToBof() throws IOException
setInputStream(InputStream)
again to reset the parser.
IOException
- If the header line is not found
or if there is any other IO error
IllegalStateException
- If the parsing has already started
NullPointerException
- If no input stream has been specifiedpublic String[] nextData() throws IOException
IOException
- If there is an IO error or if the data is invalid
IllegalStateException
- If not parseToBof()
has been calledpublic int getCurrentLine()
BfsParser
getCurrentLine
in interface BfsParser
public long getParsedBytes()
BfsParser
getParsedBytes
in interface BfsParser
protected FlatFileParser createFlatFileParser(InputStream in)
protected void handleData(EventHandler handler, String[] data)
DATA_EVENT
to the event handler
handler
- The event handler from the parse(EventHandler)
methoddata
- An array with the dataprotected void handleEndOfFile(EventHandler handler)
END_OF_FILE_EVENT
notification to the event handler.
handler
- The event handler from the parse(EventHandler)
method
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |