@Override
    public void writeVertices(final OutputStream outputStream, final Iterator<Vertex> vertexIterator, final Direction direction) throws IOException {
        final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream));
        try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
            if (wrapAdjacencyList) writer.write("{\"" + GraphSONTokens.VERTICES + "\":[");
            while (vertexIterator.hasNext()) {
                writeVertex(baos, vertexIterator.next(), direction);
                writer.write(new String(baos.toByteArray()));
                if (wrapAdjacencyList) {
                    if (vertexIterator.hasNext())
                        writer.write(",");
                } else {
                    writer.newLine();
                }
                baos.reset();
            }
            if (wrapAdjacencyList) writer.write("]}");
        }

        writer.flush();
    }
Writes a list of vertices in adjacency list format where vertices are written with edges from both
directions.  Under this serialization model, edges are grouped by label.

@param outputStream the stream to write to.
@param vertexIterator    a traversal that returns a list of vertices.
@param direction    if direction is null then no edges are written.
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONWriter.java