graphdb/src/main/java/com/orientechnologies/orient/graph/graphml/OGraphSONReader.java
public void inputGraph(final InputStream jsonInputStream, int bufferSize, final Set<String> edgePropertyKeys,
      final Set<String> vertexPropertyKeys) throws IOException {

    final JsonParser jp = jsonFactory.createJsonParser(jsonInputStream);

    // if this is a transactional localGraph then we're buffering
    final BatchGraph batchGraph = BatchGraph.wrap(graph, bufferSize);

    final ElementFactory elementFactory = new GraphElementFactory(batchGraph);
    OGraphSONUtility graphson = new OGraphSONUtility(GraphSONMode.NORMAL, elementFactory, vertexPropertyKeys, edgePropertyKeys);

    long importedVertices = 0;
    long importedEdges = 0;

    while (jp.nextToken() != JsonToken.END_OBJECT) {
      final String fieldname = jp.getCurrentName() == null ? "" : jp.getCurrentName();
      if (fieldname.equals(GraphSONTokens.MODE)) {
        jp.nextToken();
        final GraphSONMode mode = GraphSONMode.valueOf(jp.getText());
        graphson = new OGraphSONUtility(mode, elementFactory, vertexPropertyKeys, edgePropertyKeys);
      } else if (fieldname.equals(GraphSONTokens.VERTICES)) {
        jp.nextToken();
        while (jp.nextToken() != JsonToken.END_ARRAY) {
          final JsonNode node = jp.readValueAsTree();
          graphson.vertexFromJson(node);
          importedVertices++;
          printStatus(jp, importedVertices, importedEdges);

          if (importedVertices % 1000 == 0)
            ODatabaseRecordThreadLocal.instance().get().getLocalCache().invalidate();
        }
      } else if (fieldname.equals(GraphSONTokens.EDGES)) {
        jp.nextToken();
        while (jp.nextToken() != JsonToken.END_ARRAY) {
          final JsonNode node = jp.readValueAsTree();
          final Vertex inV = batchGraph.getVertex(OGraphSONUtility.getTypedValueFromJsonNode(node.get(GraphSONTokens._IN_V)));
          final Vertex outV = batchGraph.getVertex(OGraphSONUtility.getTypedValueFromJsonNode(node.get(GraphSONTokens._OUT_V)));
          graphson.edgeFromJson(node, outV, inV);
          importedEdges++;
          printStatus(jp, importedVertices, importedEdges);

          if (importedEdges % 1000 == 0)
            ODatabaseRecordThreadLocal.instance().get().getLocalCache().invalidate();
        }
      }
    }

    jp.close();

    batchGraph.commit();
  }
public void inputGraph(final InputStream jsonInputStream, int bufferSize, final Set<String> edgePropertyKeys,
      final Set<String> vertexPropertyKeys) throws IOException {

    final JsonParser jp = jsonFactory.createJsonParser(jsonInputStream);

    // if this is a transactional localGraph then we're buffering
    final BatchGraph batchGraph = BatchGraph.wrap(graph, bufferSize);

    final ElementFactory elementFactory = new GraphElementFactory(batchGraph);
    OGraphSONUtility graphson = new OGraphSONUtility(GraphSONMode.NORMAL, elementFactory, vertexPropertyKeys, edgePropertyKeys);

    long importedVertices = 0;
    long importedEdges = 0;

    while (jp.nextToken() != JsonToken.END_OBJECT) {
      final String fieldname = jp.getCurrentName() == null ? "" : jp.getCurrentName();
      if (fieldname.equals(GraphSONTokens.MODE)) {
        jp.nextToken();
        final GraphSONMode mode = GraphSONMode.valueOf(jp.getText());
        graphson = new OGraphSONUtility(mode, elementFactory, vertexPropertyKeys, edgePropertyKeys);
      } else if (fieldname.equals(GraphSONTokens.VERTICES)) {
        jp.nextToken();
        while (jp.nextToken() != JsonToken.END_ARRAY) {
          final JsonNode node = jp.readValueAsTree();
          graphson.vertexFromJson(node);
          importedVertices++;
          printStatus(jp, importedVertices, importedEdges);

          if (importedVertices % 1000 == 0)
            ODatabaseRecordThreadLocal.instance().get().getLocalCache().invalidate();
        }
      } else if (fieldname.equals(GraphSONTokens.EDGES)) {
        jp.nextToken();
        while (jp.nextToken() != JsonToken.END_ARRAY) {
          final JsonNode node = jp.readValueAsTree();
          final Vertex inV = batchGraph.getVertex(OGraphSONUtility.getTypedValueFromJsonNode(node.get(GraphSONTokens._IN_V)));
          final Vertex outV = batchGraph.getVertex(OGraphSONUtility.getTypedValueFromJsonNode(node.get(GraphSONTokens._OUT_V)));
          graphson.edgeFromJson(node, outV, inV);
          importedEdges++;
          printStatus(jp, importedVertices, importedEdges);

          if (importedEdges % 1000 == 0)
            ODatabaseRecordThreadLocal.instance().get().getLocalCache().invalidate();
        }
      }
    }

    jp.close();

    batchGraph.commit();
  }
Input the JSON stream data into the graph. More control over how data is streamed is provided by this method.

@param jsonInputStream
an InputStream of JSON data
@param bufferSize
the amount of elements to hold in memory before committing a transactions (only valid for TransactionalGraphs)
@throws IOException
thrown when the JSON data is not correctly formatted