org.graphstream.stream.file
Class FileSourceEdge

java.lang.Object
  extended by org.graphstream.stream.SourceBase
      extended by org.graphstream.stream.file.FileSourceBase
          extended by org.graphstream.stream.file.FileSourceEdge
All Implemented Interfaces:
FileSource, Source

public class FileSourceEdge
extends FileSourceBase

Reader for the "edge" graph format.

The edge graph format is a very simple and lightweight format where each line describes an edge by giving two node names. The nodes are created implicitly.

This reader also understands the derivative format where a line contains a first node name, followed by several node names separated by spaces. In this case it links the first node with all other node name following on the line.

Also, the format does not specify any direction for edges. By default all edges are undirected. You can choose to make all edges directed by passing "true" as the first arguments to constructors FileSourceEdge(boolean) or FileSourceEdge(boolean, boolean) . The direction of edges goes from the first node name on each line toward the second (or more) node names on each line.

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 constructor FileSourceEdge(boolean, boolean), and giving "false" for the second argument.

The usual file name extension for this format is ".edge".


Nested Class Summary
 
Nested classes/interfaces inherited from class org.graphstream.stream.SourceBase
SourceBase.ElementType
 
Constructor Summary
FileSourceEdge()
          New reader for the "edge" format.
FileSourceEdge(boolean edgesAreDirected)
          New reader for the "edge" format.
FileSourceEdge(boolean edgesAreDirected, boolean declareNodes)
          New reader for the "edge" format.
 
Method Summary
 void begin(InputStream stream)
          Begin reading the file stopping as soon as possible.
 void begin(Reader reader)
          Begin reading the file stopping as soon as possible.
 void begin(String filename)
          Begin reading the file stopping as soon as possible.
 void begin(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).
 boolean nextEvents()
          Try to process one graph event, or as few as possible, if more must be read at once.
 boolean nextStep()
          Try to process all the events occurring during one time step.
 
Methods inherited from class org.graphstream.stream.file.FileSourceBase
addAttributeClass, readAll, readAll, readAll, readAll
 
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, sendStepBegins
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.graphstream.stream.Source
addAttributeSink, addElementSink, addSink, clearAttributeSinks, clearElementSinks, clearSinks, removeAttributeSink, removeElementSink, removeSink
 

Constructor Detail

FileSourceEdge

public FileSourceEdge()
New reader for the "edge" format.


FileSourceEdge

public FileSourceEdge(boolean edgesAreDirected)
New reader for the "edge" format.

Parameters:
edgesAreDirected - If true (default=false) edges are considered directed.

FileSourceEdge

public FileSourceEdge(boolean edgesAreDirected,
                      boolean declareNodes)
New reader for the "edge" format.

Parameters:
edgesAreDirected - If true (default=false) edges are considered directed.
declareNodes - If true (default=true) this reader outputs nodeAdded events.
Method Detail

nextEvents

public boolean nextEvents()
                   throws IOException
Description copied from interface: FileSource
Try 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 called FileSource.begin(InputStream) or FileSource.begin(String) before. This method return true while there are still events to read.

Specified by:
nextEvents in interface FileSource
Specified by:
nextEvents in class FileSourceBase
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

public void begin(String filename)
           throws IOException
Description copied from interface: FileSource
Begin reading the file stopping as soon as possible. Next graph events stored in the file will be sent by calling 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.

Specified by:
begin in interface FileSource
Overrides:
begin in class FileSourceBase
Parameters:
filename - Name of the file to read.
Throws:
IOException - If an I/O error occurs while reading.

begin

public void begin(URL url)
           throws IOException
Description copied from interface: FileSource
Begin reading the file stopping as soon as possible. Next graph events stored in the file will be sent by calling 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.

Specified by:
begin in interface FileSource
Overrides:
begin in class FileSourceBase
Parameters:
url - The URL of the file to read.
Throws:
IOException - If an I/O error occurs while reading.

begin

public void begin(InputStream stream)
           throws IOException
Description copied from interface: FileSource
Begin reading the file stopping as soon as possible. Next graph events stored in the file will be sent by calling 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.

Specified by:
begin in interface FileSource
Overrides:
begin in class FileSourceBase
Parameters:
stream - The input stream to use for reading.
Throws:
IOException - If an I/O error occurs while reading.

begin

public void begin(Reader reader)
           throws IOException
Description copied from interface: FileSource
Begin reading the file stopping as soon as possible. Next graph events stored in the file will be sent by calling 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.

Specified by:
begin in interface FileSource
Overrides:
begin in class FileSourceBase
Parameters:
reader - The file reader to use.
Throws:
IOException - If an I/O error occurs while reading.

nextStep

public boolean nextStep()
                 throws IOException
Description copied from interface: FileSource
Try 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

public void end()
         throws IOException
Description copied from interface: FileSource
Finish the reading process (even if FileSource.nextEvents() or FileSource.nextStep() did not returned false). You must call this method after reading.

Specified by:
end in interface FileSource
Overrides:
end in class FileSourceBase
Throws:
IOException - If an I/O error occurs while closing the file.


Copyright © 2013. All Rights Reserved.