public final void to()

in src/main/java/org/apache/commons/graph/export/AbstractExporter.java [128:196]


    public final void to( Writer writer )
        throws GraphExportException
    {
        this.writer = checkNotNull( writer, "Impossibe to export the graph in a null stream" );

        try
        {
            startSerialization();
            comment( format( "Graph generated by Apache Commons Graph on %s%n", new Date() ) );

            startGraph( name );

            // this is basically for the GraphML



            // END

            for ( V vertex : graph.getVertices() )
            {
                Map<String, Object> properties = new HashMap<String, Object>( vertexProperties.size() );

                for ( Entry<String, Mapper<V, ?>> vertexProperty : vertexProperties.entrySet() )
                {
                    properties.put( vertexProperty.getKey(),
                                    vertexProperty.getValue().map( vertex ) );
                }

                vertex( vertex, properties );
            }

            for ( E edge : graph.getEdges() )
            {
                VertexPair<V> vertices = graph.getVertices( edge );

                Map<String, Object> properties = new HashMap<String, Object>( edgeProperties.size() );

                for ( Entry<String, Mapper<E, ?>> edgeProperty : edgeProperties.entrySet() )
                {
                    properties.put( edgeProperty.getKey(),
                                    edgeProperty.getValue().map( edge ) );
                }

                edge( edge, vertices.getHead(), vertices.getTail(), properties );
            }

            endGraph();

            endSerialization();
        }
        catch ( Exception e )
        {
            throw new GraphExportException( e, "an error occurred while exporting graph %s (named %s) to writer %s",
                                            graph,
                                            name,
                                            writer );
        }
        finally
        {
            try
            {
                writer.close();
            }
            catch ( IOException e )
            {
                // swallow it
            }
        }
    }