Package org.graphstream.stream.file
Class FileSinkBase
java.lang.Object
org.graphstream.stream.file.FileSinkBase
- All Implemented Interfaces:
AttributeSink,ElementSink,FileSink,Sink
- Direct Known Subclasses:
FileSinkBaseFiltered,FileSinkDGS,FileSinkDOT,FileSinkGEXF,FileSinkGML,FileSinkGraphML,FileSinkTikZ,FileSinkUnstyledSVG
public abstract class FileSinkBase extends Object implements FileSink
Base implementation for graph output to files.
This class provides base services to write graphs into files using a specific file format. It allows to create an output stream. By default a print stream for easy text output, but binary files are possible.
It handles completely the writeAll(Graph, OutputStream),
writeAll(Graph, String), begin(OutputStream),
begin(String), flush() and end() methods. You
should not have to modify or override these.
In order to implement an output you have to:
- Eventually override
createWriter(OutputStream)orcreateWriter(String)to replace the default instance of PrintStream created for you. - Implement the
outputHeader()method. This method is called at start, before any graph event is sent to output. Use it to output the header of your file. - Implement the
outputEndOfFile()method. This method is called at the end of the output, just before closing the output stream. Use it to output any terminating syntax for the file format you implement. - Implement all the methods of
Sink. All these methods will be called for each graph event and must export these events to the file you are writing. You should use theoutputfield to write to the file. This field has typeOutputStreambut by default is of typePrintStream, as most of the file format will be textual.
-
Constructor Summary
Constructors Constructor Description FileSinkBase() -
Method Summary
Modifier and Type Method Description voidbegin(OutputStream stream)Begin the output of the given stream of graph events.voidbegin(Writer writer)Begin the output of the given stream of graph events.voidbegin(String fileName)Begin the output of the given stream of graph events.voidend()End the writing process started withFileSink.begin(OutputStream)orFileSink.begin(String).voidflush()Ensure all data sent to the output are correctly written.voidwriteAll(Graph graph, OutputStream stream)Write the current graph state in one big non-interruptible operation.voidwriteAll(Graph graph, Writer writer)Write the current graph state in one big non-interruptible operation.voidwriteAll(Graph graph, String fileName)Write the current graph state in one big non-interruptible operation.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.graphstream.stream.AttributeSink
edgeAttributeAdded, edgeAttributeChanged, edgeAttributeRemoved, graphAttributeAdded, graphAttributeChanged, graphAttributeRemoved, nodeAttributeAdded, nodeAttributeChanged, nodeAttributeRemovedMethods inherited from interface org.graphstream.stream.ElementSink
edgeAdded, edgeRemoved, graphCleared, nodeAdded, nodeRemoved, stepBegins
-
Constructor Details
-
FileSinkBase
public FileSinkBase()
-
-
Method Details
-
writeAll
Description copied from interface:FileSinkWrite the current graph state in one big non-interruptible operation. This operation is a "snapshot" of the graph, it will never convey the dynamics of the graph. To ensure you store the graph "as it evolves in time" you must use theFileSink.begin(OutputStream)orFileSink.begin(String)as soon as the graph appears (or any source of graph event, any descendant ofSourcewill do).- Specified by:
writeAllin interfaceFileSink- Parameters:
graph- The graph to send as events to the file.fileName- Name of the file to write.- Throws:
IOException- if an I/O error occurs while writing.
-
writeAll
Description copied from interface:FileSinkWrite the current graph state in one big non-interruptible operation. This operation is a "snapshot" of the graph, it will never convey the dynamics of the graph. To ensure you store the graph "as it evolves in time" you must use theFileSink.begin(Writer)orFileSink.begin(OutputStream)orFileSink.begin(String)as soon as the graph appears (or any source of graph event, any descendant ofSourcewill do).- Specified by:
writeAllin interfaceFileSink- Parameters:
graph- The graph to send as events to the file.stream- The stream where the graph is sent.- Throws:
IOException- if an I/O error occurs while writing.
-
writeAll
Description copied from interface:FileSinkWrite the current graph state in one big non-interruptible operation. This operation is a "snapshot" of the graph, it will never convey the dynamics of the graph. To ensure you store the graph "as it evolves in time" you must use theFileSink.begin(Writer)orFileSink.begin(OutputStream)orFileSink.begin(String)as soon as the graph appears (or any source of graph event, any descendant ofSourcewill do).- Specified by:
writeAllin interfaceFileSink- Parameters:
graph- The graph to send as events to the file.writer- The writer where the graph is sent.- Throws:
IOException- if an I/O error occurs while writing.
-
begin
Description copied from interface:FileSinkBegin the output of the given stream of graph events. The graph events can come from any input (implementation ofSourceor you can directly use the methods inherited fromSink. Once the writing is started using begin(), you must close it usingFileSink.end()when done to ensure data is correctly stored in the file.- Specified by:
beginin interfaceFileSink- Parameters:
fileName- The name of the file where to output the graph events.- Throws:
IOException- If an I/O error occurs while writing.
-
begin
Description copied from interface:FileSinkBegin the output of the given stream of graph events. The graph events can come from any input (implementation ofSourceor you can directly use the methods inherited fromSink. Once the writing is started using begin(), you must close it usingFileSink.end()when done to ensure data is correctly stored in the file.- Specified by:
beginin interfaceFileSink- Parameters:
stream- The file stream where to output the graph events.- Throws:
IOException- If an I/O error occurs while writing.
-
begin
Description copied from interface:FileSinkBegin the output of the given stream of graph events. The graph events can come from any input (implementation ofSourceor you can directly use the methods inherited fromSink. Once the writing is started using begin(), you must close it usingFileSink.end()when done to ensure data is correctly stored in the file.- Specified by:
beginin interfaceFileSink- Parameters:
writer- The writer where to output the graph events.- Throws:
IOException- If an I/O error occurs while writing.
-
flush
Description copied from interface:FileSinkEnsure all data sent to the output are correctly written.- Specified by:
flushin interfaceFileSink- Throws:
IOException- If an I/O error occurs during write.
-
end
Description copied from interface:FileSinkEnd the writing process started withFileSink.begin(OutputStream)orFileSink.begin(String).- Specified by:
endin interfaceFileSink- Throws:
IOException
-