Package org.graphstream.stream.file
Class FileSourceBase
java.lang.Object
org.graphstream.stream.SourceBase
org.graphstream.stream.file.FileSourceBase
- All Implemented Interfaces:
FileSource,Source
- Direct Known Subclasses:
FileSourceDGS1And2,FileSourceEdge,FileSourceLGL,FileSourceNCol,OldFileSourceDGS
public abstract class FileSourceBase extends SourceBase implements FileSource
Base for various graph file input.
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.graphstream.stream.SourceBase
SourceBase.ElementType -
Method Summary
Modifier and Type Method Description voidaddAttributeClass(String attribute, String attribute_class)Declare that whenattributeis found, the correspondingattribute_classmust be instantiated and inserted in the current element being parsed.voidbegin(InputStream stream)Begin reading the file stopping as soon as possible.voidbegin(Reader reader)Begin reading the file stopping as soon as possible.voidbegin(String filename)Begin reading the file stopping as soon as possible.voidbegin(URL url)Begin reading the file stopping as soon as possible.voidend()Finish the reading process (even ifFileSource.nextEvents()orFileSource.nextStep()did not returned false).abstract booleannextEvents()Try to process one graph event, or as few as possible, if more must be read at once.voidreadAll(InputStream stream)Read the whole file in one big non-interruptible operation.voidreadAll(Reader reader)Read the whole file in one big non-interruptible operation.voidreadAll(String filename)Read the whole file in one big non-interruptible operation.voidreadAll(URL url)Read the whole file in one big non-interruptible operation.Methods inherited from class org.graphstream.stream.SourceBase
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, sendStepBeginsMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.graphstream.stream.Source
addAttributeSink, addElementSink, addSink, clearAttributeSinks, clearElementSinks, clearSinks, removeAttributeSink, removeElementSink, removeSink
-
Method Details
-
readAll
Description copied from interface:FileSourceRead the whole file in one big non-interruptible operation.- Specified by:
readAllin interfaceFileSource- Parameters:
filename- Name of the file to read.- Throws:
IOException- If an I/O error occurs while reading.
-
readAll
Description copied from interface:FileSourceRead the whole file in one big non-interruptible operation.- Specified by:
readAllin interfaceFileSource- Parameters:
url- The URL of the file to read.- Throws:
IOException- If an I/O error occurs while reading.
-
readAll
Description copied from interface:FileSourceRead the whole file in one big non-interruptible operation.- Specified by:
readAllin interfaceFileSource- Parameters:
stream- The input stream to use for reading.- Throws:
IOException- If an I/O error occurs while reading.
-
readAll
Description copied from interface:FileSourceRead the whole file in one big non-interruptible operation.- Specified by:
readAllin interfaceFileSource- Parameters:
reader- The reader to use.- Throws:
IOException- If an I/O error occurs while reading.
-
begin
Description copied from interface:FileSourceBegin reading the file stopping as soon as possible. Next graph events stored in the file will be sent by callingFileSource.nextEvents()orFileSource.nextStep(). Once begin() has been called, you must finish the reading process usingFileSource.end(). You cannot call begin() twice without having calledFileSource.end()in between.- Specified by:
beginin interfaceFileSource- Parameters:
filename- Name of the file to read.- Throws:
IOException- If an I/O error occurs while reading.
-
begin
Description copied from interface:FileSourceBegin reading the file stopping as soon as possible. Next graph events stored in the file will be sent by callingFileSource.nextEvents()orFileSource.nextStep(). Once begin() has been called, you must finish the reading process usingFileSource.end(). You cannot call begin() twice without having calledFileSource.end()in between.- Specified by:
beginin interfaceFileSource- Parameters:
stream- The input stream to use for reading.- Throws:
IOException- If an I/O error occurs while reading.
-
begin
Description copied from interface:FileSourceBegin reading the file stopping as soon as possible. Next graph events stored in the file will be sent by callingFileSource.nextEvents()orFileSource.nextStep(). Once begin() has been called, you must finish the reading process usingFileSource.end(). You cannot call begin() twice without having calledFileSource.end()in between.- Specified by:
beginin interfaceFileSource- Parameters:
url- The URL of the file to read.- Throws:
IOException- If an I/O error occurs while reading.
-
begin
Description copied from interface:FileSourceBegin reading the file stopping as soon as possible. Next graph events stored in the file will be sent by callingFileSource.nextEvents()orFileSource.nextStep(). Once begin() has been called, you must finish the reading process usingFileSource.end(). You cannot call begin() twice without having calledFileSource.end()in between.- Specified by:
beginin interfaceFileSource- Parameters:
reader- The file reader to use.- Throws:
IOException- If an I/O error occurs while reading.
-
nextEvents
Description copied from interface:FileSourceTry to process one graph event, or as few as possible, if more must be read at once. For this method to work, you must have calledFileSource.begin(InputStream)orFileSource.begin(String)before. This method return true while there are still events to read.- Specified by:
nextEventsin interfaceFileSource- Returns:
- true if there are still events to read, false as soon as the file is finished.
- Throws:
IOException- If an I/O error occurs while reading.
-
end
Description copied from interface:FileSourceFinish the reading process (even ifFileSource.nextEvents()orFileSource.nextStep()did not returned false). You must call this method after reading.- Specified by:
endin interfaceFileSource- Throws:
IOException- If an I/O error occurs while closing the file.
-
addAttributeClass
Declare that whenattributeis found, the correspondingattribute_classmust 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.- Parameters:
attribute- must name the attribute.attribute_class- must be the complete name of a Java class that will represent the attribute.
-