public abstract class FileSourceBase extends SourceBase implements FileSource
This class is a piece of crap. However it is still used in many places... :-( TODO use a parser generator to replace it.
This class provides parsing utilities to help the creation of new graph readers/parsers. It handles a stack of input files that allow to easily implements "includes" (that is interrupting the parsing of a file to input another one). It wraps stream tokenizers allowing to eat or get specific token types easily.
It is well suited for graph formats using text (not binary), but not for XML based files where a real XML parser would probably be better.
SourceBase.ElementType
Modifier and Type | Method and Description |
---|---|
void |
addAttributeClass(java.lang.String attribute,
java.lang.String attribute_class)
Declare that when
attribute is found, the corresponding
attribute_class must be instantiated and inserted in the current
element being parsed. |
void |
begin(java.io.InputStream stream)
Begin reading the file stopping as soon as possible.
|
void |
begin(java.io.Reader reader)
Begin reading the file stopping as soon as possible.
|
void |
begin(java.lang.String filename)
Begin reading the file stopping as soon as possible.
|
void |
begin(java.net.URL url)
Begin reading the file stopping as soon as possible.
|
void |
end()
Finish the reading process (even if
FileSource.nextEvents() or
FileSource.nextStep() did not returned false). |
abstract boolean |
nextEvents()
Try to process one graph event, or as few as possible, if more must be read
at once.
|
void |
readAll(java.io.InputStream stream)
Read the whole file in one big non-interruptible operation.
|
void |
readAll(java.io.Reader reader)
Read the whole file in one big non-interruptible operation.
|
void |
readAll(java.lang.String filename)
Read the whole file in one big non-interruptible operation.
|
void |
readAll(java.net.URL url)
Read the whole file in one big non-interruptible operation.
|
addAttributeSink, addElementSink, addSink, attributeSinks, clearAttributeSinks, clearElementSinks, clearSinks, elementSinks, removeAttributeSink, removeElementSink, removeSink, sendAttributeChangedEvent, sendAttributeChangedEvent, sendEdgeAdded, sendEdgeAdded, sendEdgeAttributeAdded, sendEdgeAttributeAdded, sendEdgeAttributeChanged, sendEdgeAttributeChanged, sendEdgeAttributeRemoved, sendEdgeAttributeRemoved, sendEdgeRemoved, sendEdgeRemoved, sendGraphAttributeAdded, sendGraphAttributeAdded, sendGraphAttributeChanged, sendGraphAttributeChanged, sendGraphAttributeRemoved, sendGraphAttributeRemoved, sendGraphCleared, sendGraphCleared, sendNodeAdded, sendNodeAdded, sendNodeAttributeAdded, sendNodeAttributeAdded, sendNodeAttributeChanged, sendNodeAttributeChanged, sendNodeAttributeRemoved, sendNodeAttributeRemoved, sendNodeRemoved, sendNodeRemoved, sendStepBegins, sendStepBegins
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
nextStep
addAttributeSink, addElementSink, addSink, clearAttributeSinks, clearElementSinks, clearSinks, removeAttributeSink, removeElementSink, removeSink
public void readAll(java.lang.String filename) throws java.io.IOException
FileSource
readAll
in interface FileSource
filename
- Name of the file to read.java.io.IOException
- If an I/O error occurs while reading.public void readAll(java.net.URL url) throws java.io.IOException
FileSource
readAll
in interface FileSource
url
- The URL of the file to read.java.io.IOException
- If an I/O error occurs while reading.public void readAll(java.io.InputStream stream) throws java.io.IOException
FileSource
readAll
in interface FileSource
stream
- The input stream to use for reading.java.io.IOException
- If an I/O error occurs while reading.public void readAll(java.io.Reader reader) throws java.io.IOException
FileSource
readAll
in interface FileSource
reader
- The reader to use.java.io.IOException
- If an I/O error occurs while reading.public void begin(java.lang.String filename) throws java.io.IOException
FileSource
FileSource.nextEvents()
or
FileSource.nextStep()
. Once begin() has been called, you must finish the
reading process using FileSource.end()
. You cannot call begin() twice without
having called FileSource.end()
in between.begin
in interface FileSource
filename
- Name of the file to read.java.io.IOException
- If an I/O error occurs while reading.public void begin(java.io.InputStream stream) throws java.io.IOException
FileSource
FileSource.nextEvents()
or
FileSource.nextStep()
. Once begin() has been called, you must finish the
reading process using FileSource.end()
. You cannot call begin() twice without
having called FileSource.end()
in between.begin
in interface FileSource
stream
- The input stream to use for reading.java.io.IOException
- If an I/O error occurs while reading.public void begin(java.net.URL url) throws java.io.IOException
FileSource
FileSource.nextEvents()
or
FileSource.nextStep()
. Once begin() has been called, you must finish the
reading process using FileSource.end()
. You cannot call begin() twice without
having called FileSource.end()
in between.begin
in interface FileSource
url
- The URL of the file to read.java.io.IOException
- If an I/O error occurs while reading.public void begin(java.io.Reader reader) throws java.io.IOException
FileSource
FileSource.nextEvents()
or
FileSource.nextStep()
. Once begin() has been called, you must finish the
reading process using FileSource.end()
. You cannot call begin() twice without
having called FileSource.end()
in between.begin
in interface FileSource
reader
- The file reader to use.java.io.IOException
- If an I/O error occurs while reading.public abstract boolean nextEvents() throws java.io.IOException
FileSource
FileSource.begin(InputStream)
or FileSource.begin(String)
before. This method
return true while there are still events to read.nextEvents
in interface FileSource
java.io.IOException
- If an I/O error occurs while reading.public void end() throws java.io.IOException
FileSource
FileSource.nextEvents()
or
FileSource.nextStep()
did not returned false). You must call this method after
reading.end
in interface FileSource
java.io.IOException
- If an I/O error occurs while closing the file.public void addAttributeClass(java.lang.String attribute, java.lang.String attribute_class)
attribute
is found, the corresponding
attribute_class
must be instantiated and inserted in the current
element being parsed. This is equivalent to the "map" keyword of the GML
file. An attribute appears in a GML file as a name followed by a "[...]"
block. The contents of this block defines sub-attributes that must map to
public fields of the attribute. Only attributes that are not handled
specifically by this parser can be added.attribute
- must name the attribute.attribute_class
- must be the complete name of a Java class that will represent the
attribute.