Package org.geotools.graph.io.standard
Class SerializedReaderWriter
- Object
-
- AbstractReaderWriter
-
- SerializedReaderWriter
-
- All Implemented Interfaces:
GraphReaderWriter
,FileReaderWriter
public class SerializedReaderWriter extends AbstractReaderWriter implements FileReaderWriter
An implementation of GraphReaderWriter that uses java serialization to read and write graph objects. During the graph serialization process edges are written to the object output stream. Along with the edges, the two nodes incident to the edge are also written. However, edge adjacency lists of nodes are not written to the output stream in order to prevent deep recursive calls that often result in a stack overflow. Therefore it is important that any implementation of the Node interface declare its edge adjacecny list (if any) as transient in order to support graph serializability.
Because edge adjacency lists are not serialized, they must be reconstructed upon deserialization in order to preserve the original graph structure.- Author:
- Justin Deoliveira, Refractions Research Inc, jdeolive@refractions.net
-
-
Field Summary
-
Fields inherited from class AbstractReaderWriter
BUILDER, EDGES, GENERATOR, NODES
-
Fields inherited from interface FileReaderWriter
FILENAME
-
-
Constructor Summary
Constructors Constructor Description SerializedReaderWriter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Graph
read()
Deserializes the graph and reconstructs the original structure.void
write(Graph graph)
Serializes the graph by writing each edge in the graph to an object output stream.-
Methods inherited from class AbstractReaderWriter
getProperty, setProperty, setProperty
-
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface GraphReaderWriter
getProperty, setProperty
-
-
-
-
Method Detail
-
read
public Graph read() throws Exception
Deserializes the graph and reconstructs the original structure.- Specified by:
read
in interfaceGraphReaderWriter
- Returns:
- The represented graph.
- Throws:
Exception
- See Also:
GraphReaderWriter.read()
-
write
public void write(Graph graph) throws Exception
Serializes the graph by writing each edge in the graph to an object output stream. If there any nodes of degree 0 in the graph, then they are appended to the end of the object output stream.- Specified by:
write
in interfaceGraphReaderWriter
- Parameters:
graph
- The graph to be- Throws:
Exception
- See Also:
GraphReaderWriter#write()
-
-