Package org.graphstream.stream.file
Class FileSourceNCol
java.lang.Object
org.graphstream.stream.SourceBase
org.graphstream.stream.file.FileSourceBase
org.graphstream.stream.file.FileSourceNCol
- All Implemented Interfaces:
FileSource,Source
public class FileSourceNCol extends FileSourceBase
Reader for the "ncol" graph format.
The ncol graph format is a simple format where each line describes an edge by giving two node names and an optional third parameters giving the edge weight. The nodes are created implicitly.
Also, the format does not specify any direction for edges. By default all edges are undirected. It is specified in the format that you will never have directed edges and that the lines:
node1Name node2Name
and
node2Name node1Name
Cannot both appear at the same time in a file.
This format only contains edges. To ensure the "add node" events are sent before an edge referencing two nodes is created via an "add edge" event, this reader has a hash set of already encountered nodes. The hash set allows to issue "add node" events only when a node is encountered for the first time.
This hash set consumes memory, but is the only way to ensure "add node" events are correctly issued. If this input is directly connected to a graph, as graphs can create non-existing nodes automatically, you can disable the hash set of nodes using the constructorFileSourceNCol(boolean), and
giving "false" for the first argument.
The usual file name extension for this format is ".ncol".-
Nested Class Summary
Nested classes/interfaces inherited from class org.graphstream.stream.SourceBase
SourceBase.ElementType -
Constructor Summary
Constructors Constructor Description FileSourceNCol()New reader for the "ncol" format.FileSourceNCol(boolean declareNodes)New reader for the "ncol" format. -
Method Summary
Modifier and Type Method Description 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).booleannextEvents()Try to process one graph event, or as few as possible, if more must be read at once.booleannextStep()Try to process all the events occurring during one time step.Methods inherited from class org.graphstream.stream.file.FileSourceBase
addAttributeClass, readAll, readAll, readAll, readAllMethods 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
-
Constructor Details
-
FileSourceNCol
public FileSourceNCol()New reader for the "ncol" format. -
FileSourceNCol
public FileSourceNCol(boolean declareNodes)New reader for the "ncol" format.- Parameters:
declareNodes- If true (default=true) this reader outputs nodeAdded events.
-
-
Method Details
-
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- Specified by:
nextEventsin classFileSourceBase- 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.
-
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- Overrides:
beginin classFileSourceBase- 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- Overrides:
beginin classFileSourceBase- 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- Overrides:
beginin classFileSourceBase- 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- Overrides:
beginin classFileSourceBase- Parameters:
reader- The file reader to use.- Throws:
IOException- If an I/O error occurs while reading.
-
nextStep
Description copied from interface:FileSourceTry to process all the events occurring during one time step. In GraphStream, a time step is a group of events that are considered occurring at the same time. Most file formats do not have this notion of step. The DGS format designed for GraphStream handles steps. This method return true while there are still events to read.- 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- Overrides:
endin classFileSourceBase- Throws:
IOException- If an I/O error occurs while closing the file.
-