public abstract class FileSinkBase extends Object implements FileSink
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:
createWriter(OutputStream)
or
createWriter(String)
to replace the default instance of PrintStream
created for you.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.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.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 the output
field
to write to the file. This field has type OutputStream
but by
default is of type PrintStream
, as most of the file format
will be textual.Constructor and Description |
---|
FileSinkBase() |
Modifier and Type | Method and Description |
---|---|
void |
begin(OutputStream stream)
Begin the output of the given stream of graph events.
|
void |
begin(String fileName)
Begin the output of the given stream of graph events.
|
void |
begin(Writer writer)
Begin the output of the given stream of graph events.
|
protected Writer |
createWriter(OutputStream stream)
Create a writer from an existing output stream.
|
protected Writer |
createWriter(String fileName)
Create a a writer from a file name.
|
protected Writer |
createWriter(Writer writer)
Create a writer from an existing writer.
|
void |
end()
End the writing process started with
FileSink.begin(OutputStream) or
FileSink.begin(String) . |
protected void |
exportGraph(Graph graph)
Echo each element and attribute of the graph to the actual output.
|
void |
flush()
Ensure all data sent to the output are correctly written.
|
protected abstract void |
outputEndOfFile()
Method called at the end just before the
output field is flushed
and closed. |
protected abstract void |
outputHeader()
Method called at start just after the
output field is created. |
void |
writeAll(Graph graph,
OutputStream stream)
Write the current graph state in one big non-interruptible operation.
|
void |
writeAll(Graph graph,
String fileName)
Write the current graph state in one big non-interruptible operation.
|
void |
writeAll(Graph graph,
Writer writer)
Write the current graph state in one big non-interruptible operation.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
edgeAttributeAdded, edgeAttributeChanged, edgeAttributeRemoved, graphAttributeAdded, graphAttributeChanged, graphAttributeRemoved, nodeAttributeAdded, nodeAttributeChanged, nodeAttributeRemoved
edgeAdded, edgeRemoved, graphCleared, nodeAdded, nodeRemoved, stepBegins
public FileSinkBase()
public void writeAll(Graph graph, String fileName) throws IOException
FileSink
FileSink.begin(OutputStream)
or
FileSink.begin(String)
as soon as the graph appears (or any source of
graph event, any descendant of Source
will do).writeAll
in interface FileSink
graph
- The graph to send as events to the file.fileName
- Name of the file to write.IOException
- if an I/O error occurs while writing.public void writeAll(Graph graph, OutputStream stream) throws IOException
FileSink
FileSink.begin(Writer)
or
FileSink.begin(OutputStream)
or FileSink.begin(String)
as soon as the
graph appears (or any source of graph event, any descendant of
Source
will do).writeAll
in interface FileSink
graph
- The graph to send as events to the file.stream
- The stream where the graph is sent.IOException
- if an I/O error occurs while writing.public void writeAll(Graph graph, Writer writer) throws IOException
FileSink
FileSink.begin(Writer)
or
FileSink.begin(OutputStream)
or FileSink.begin(String)
as soon as the
graph appears (or any source of graph event, any descendant of
Source
will do).writeAll
in interface FileSink
graph
- The graph to send as events to the file.writer
- The writer where the graph is sent.IOException
- if an I/O error occurs while writing.protected void exportGraph(Graph graph)
graph
- The graph to export.public void begin(String fileName) throws IOException
FileSink
Source
or you can
directly use the methods inherited from Sink
. Once the writing is
started using begin(), you must close it using FileSink.end()
when done
to ensure data is correctly stored in the file.begin
in interface FileSink
fileName
- The name of the file where to output the graph events.IOException
- If an I/O error occurs while writing.public void begin(OutputStream stream) throws IOException
FileSink
Source
or you can
directly use the methods inherited from Sink
. Once the writing is
started using begin(), you must close it using FileSink.end()
when done
to ensure data is correctly stored in the file.begin
in interface FileSink
stream
- The file stream where to output the graph events.IOException
- If an I/O error occurs while writing.public void begin(Writer writer) throws IOException
FileSink
Source
or you can
directly use the methods inherited from Sink
. Once the writing is
started using begin(), you must close it using FileSink.end()
when done
to ensure data is correctly stored in the file.begin
in interface FileSink
writer
- The writer where to output the graph events.IOException
- If an I/O error occurs while writing.public void flush() throws IOException
FileSink
flush
in interface FileSink
IOException
- If an I/O error occurs during write.public void end() throws IOException
FileSink
FileSink.begin(OutputStream)
or
FileSink.begin(String)
.end
in interface FileSink
IOException
protected abstract void outputHeader() throws IOException
output
field is created.
Use it to output the header of the file.IOException
- If any I/O error occurs.protected abstract void outputEndOfFile() throws IOException
output
field is flushed
and closed. Use it to output any information that closes the file.IOException
- If any I/O error occurs.protected Writer createWriter(String fileName) throws IOException
begin(String)
and writeAll(Graph, String)
.fileName
- Name of the file to output to.IOException
- If any I/O error occurs.protected Writer createWriter(OutputStream stream) throws IOException
begin(OutputStream)
and
writeAll(Graph, OutputStream)
. This method does not create an
output stream if the given stream is already instance of PrintStream.stream
- An already existing output stream.IOException
- If any I/O error occurs.protected Writer createWriter(Writer writer) throws IOException
begin(Writer)
and writeAll(Graph, Writer)
. This method
does not create a new writer if the given writer is already instance of
PrintWriter.writer
- An already existing writer.IOException
- If any I/O error occurs.WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses