use of com.fasterxml.jackson.core.JsonParser in project blueprints by tinkerpop.
the class GraphSONReader method inputGraph.
/**
* Input the JSON stream data into the graph.
* More control over how data is streamed is provided by this method.
*
* @param inputGraph the graph to populate with the JSON data
* @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
*/
public static void inputGraph(final Graph inputGraph, final InputStream jsonInputStream, int bufferSize, final Set<String> edgePropertyKeys, final Set<String> vertexPropertyKeys) throws IOException {
if (jsonInputStream == null) {
throw new IllegalArgumentException("InputStream must not be null");
}
final JsonParser jp = jsonFactory.createJsonParser(jsonInputStream);
// if this is a transactional graph then we're buffering
final BatchGraph graph = BatchGraph.wrap(inputGraph, bufferSize);
final ElementFactory elementFactory = new GraphElementFactory(graph);
GraphSONUtility graphson = new GraphSONUtility(GraphSONMode.NORMAL, elementFactory, vertexPropertyKeys, edgePropertyKeys);
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 GraphSONUtility(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);
}
} else if (fieldname.equals(GraphSONTokens.EDGES)) {
jp.nextToken();
while (jp.nextToken() != JsonToken.END_ARRAY) {
final JsonNode node = jp.readValueAsTree();
final Vertex inV = graph.getVertex(GraphSONUtility.getTypedValueFromJsonNode(node.get(GraphSONTokens._IN_V)));
final Vertex outV = graph.getVertex(GraphSONUtility.getTypedValueFromJsonNode(node.get(GraphSONTokens._OUT_V)));
graphson.edgeFromJson(node, outV, inV);
}
}
}
jp.close();
graph.commit();
;
}
use of com.fasterxml.jackson.core.JsonParser in project blueprints by tinkerpop.
the class GraphSONUtility method vertexFromJson.
/**
* Creates a vertex from GraphSON using settings supplied in the constructor.
*/
public Vertex vertexFromJson(final String json) throws IOException {
final JsonParser jp = jsonFactory.createParser(json);
final JsonNode node = jp.readValueAsTree();
return this.vertexFromJson(node);
}
use of com.fasterxml.jackson.core.JsonParser in project LoganSquare by bluelinelabs.
the class JsonMapper method parseMap.
/**
* Parse a map of objects from a byte array. Note: parsing from an InputStream should be preferred over parsing from a byte array if possible.
*
* @param byteArray The byte array string being parsed.
*/
public Map<String, T> parseMap(byte[] byteArray) throws IOException {
JsonParser jsonParser = LoganSquare.JSON_FACTORY.createParser(byteArray);
jsonParser.nextToken();
return parseMap(jsonParser);
}
use of com.fasterxml.jackson.core.JsonParser in project LoganSquare by bluelinelabs.
the class JsonMapper method parse.
/**
* Parse an object from a byte array. Note: parsing from an InputStream should be preferred over parsing from a byte array if possible.
*
* @param byteArray The byte array being parsed.
*/
public T parse(byte[] byteArray) throws IOException {
JsonParser jsonParser = LoganSquare.JSON_FACTORY.createParser(byteArray);
jsonParser.nextToken();
return parse(jsonParser);
}
use of com.fasterxml.jackson.core.JsonParser in project LoganSquare by bluelinelabs.
the class JsonMapper method parseMap.
/**
* Parse a map of objects from an InputStream.
*
* @param is The inputStream, most likely from your networking library.
*/
public Map<String, T> parseMap(InputStream is) throws IOException {
JsonParser jsonParser = LoganSquare.JSON_FACTORY.createParser(is);
jsonParser.nextToken();
return parseMap(jsonParser);
}
Aggregations