|
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.AnnotationParser
public class AnnotationParser
Parser implementation that parses a BFS annotation 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:
HEADER_EVENT
: When the header-line (should be the first line)
has been found.
DATA_EVENT
: For each data line that is parsed.
END_OF_FILE_EVENT
: When the end of the file has been reached.
AnnotationModel
class implements a simple event handler that
collects the information from the annotations file and provides methods
for accessing it.
This class may be subclassed to provide customized behaviour.
Field Summary | |
---|---|
static EventType<String[]> |
DATA_EVENT
Event thep 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
|
static EventType<String[]> |
HEADER_EVENT
Event type that is issued when the header line is found. |
private InputStream |
in
|
private int |
numColumns
|
private Set<Integer> |
usedIds
|
Constructor Summary | |
---|---|
AnnotationParser()
Create a new annotation parser. |
Method Summary | |
---|---|
void |
close()
Close the parser and relase underlying system resources that are associated with it. |
static AnnotationParser |
create(File file)
Utility method for creating an annotation parser for a file in the BASE file system. |
static AnnotationParser |
create(File file)
Utility method for creating an annotation parser for a file in the local file system. |
static AnnotationParser |
create(InputStream in,
String filename,
long size)
Utility method for creating an annotation 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. |
protected void |
handleHeader(EventHandler handler,
String[] headers)
Handle the header-found event. |
String[] |
nextData()
Get the next data line in the annotations file. |
void |
parse(EventHandler handler)
Parse the input stream and notify the specified event handler with events. |
String[] |
parseToBof()
Parse the header line of the annotations 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. |
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[]> HEADER_EVENT
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
private Set<Integer> usedIds
Constructor Detail |
---|
public AnnotationParser()
Method Detail |
---|
public static AnnotationParser create(InputStream in, String filename, long size)
in
- The input stream the parser should read fromfilename
- Optional, the name of the file the input stream
is reading fromsize
- The size of the file in bytes, or -1 if not
knownpublic static AnnotationParser create(File file)
file
- The file in the BASE file systempublic static AnnotationParser 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 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 String[] 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 handleHeader(EventHandler handler, String[] headers)
HEADER_EVENT
to the event handler
handler
- The event handler from the parse(EventHandler)
methodheaders
- An array with the column headersprotected 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 |