コード例 #1
0
  public JsonObject serializeGraph(Graph graph) throws IOException {
    String graphJsonResult;
    try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
      GraphSONWriter.outputGraph(graph, os, graphsonMode);
      graphJsonResult = os.toString("UTF-8");
    }

    return new JsonObject().putObject("graph", new JsonObject(graphJsonResult));
  }
コード例 #2
0
ファイル: GraphsonWriter.java プロジェクト: CINERGI/SciGraph
 @Override
 public void writeTo(
     Graph data,
     Class<?> type,
     Type genericType,
     Annotation[] annotations,
     MediaType mediaType,
     MultivaluedMap<String, Object> headers,
     OutputStream out)
     throws IOException {
   GraphSONWriter.outputGraph(data, out, GraphSONMode.COMPACT);
   out.flush();
 }
コード例 #3
0
  public static String serializeGraph(Graph graph) throws IOException {
    OutputStream output =
        new OutputStream() {
          private StringBuilder string = new StringBuilder();

          @Override
          public void write(int b) throws IOException {
            this.string.append((char) b);
          }

          public String toString() {
            return this.string.toString();
          }
        };

    GraphSONWriter.outputGraph(graph, output);
    String json = output.toString();

    return json;
  }