当前位置: 首页>>代码示例>>Java>>正文


Java GraphWriter.writeObject方法代码示例

本文整理汇总了Java中org.apache.tinkerpop.gremlin.structure.io.GraphWriter.writeObject方法的典型用法代码示例。如果您正苦于以下问题:Java GraphWriter.writeObject方法的具体用法?Java GraphWriter.writeObject怎么用?Java GraphWriter.writeObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.tinkerpop.gremlin.structure.io.GraphWriter的用法示例。


在下文中一共展示了GraphWriter.writeObject方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldDeserializeGraphSONIntoTinkerGraphKeepingTypes

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入方法依赖的package包/类
/**
 * Thorough types verification for Vertex ids, Vertex props, Edge ids, Edge props
 */
@Test
public void shouldDeserializeGraphSONIntoTinkerGraphKeepingTypes() throws IOException {
    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    final Graph sampleGraph1 = TinkerFactory.createModern();
    final Vertex v1 = sampleGraph1.addVertex(T.id, 100, "name", "kevin", "theUUID", UUID.randomUUID());
    final Vertex v2 = sampleGraph1.addVertex(T.id, 101L, "name", "henri", "theUUID", UUID.randomUUID());
    v1.addEdge("hello", v2, T.id, 101L,
            "uuid", UUID.randomUUID());

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, sampleGraph1);
        final String json = out.toString();

        final TinkerGraph read = reader.readObject(new ByteArrayInputStream(json.getBytes()), TinkerGraph.class);
        assertTrue(approximateGraphsCheck(sampleGraph1, read));
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:23,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例2: deserializersTestsVertex

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入方法依赖的package包/类
@Test
public void deserializersTestsVertex() {
    final TinkerGraph tg = TinkerGraph.open();

    final Vertex v = tg.addVertex("vertexTest");
    v.property("born", LocalDateTime.of(1971, 1, 2, 20, 50));
    v.property("dead", LocalDateTime.of(1971, 1, 7, 20, 50));

    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, v);
        final String json = out.toString();

        // Object works, because there's a type in the payload now
        // Vertex.class would work as well
        // Anything else would not because we check the type in param here with what's in the JSON, for safety.
        final Vertex vRead = (Vertex)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
        assertEquals(v, vRead);
    } catch (IOException e) {
        e.printStackTrace();
        fail("Should not have thrown exception: " + e.getMessage());
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:26,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例3: deserializersTestsEdge

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入方法依赖的package包/类
@Test
public void deserializersTestsEdge() {
    final TinkerGraph tg = TinkerGraph.open();

    final Vertex v = tg.addVertex("vertexTest");
    final Vertex v2 = tg.addVertex("vertexTest");

    final Edge ed = v.addEdge("knows", v2, "time", LocalDateTime.now());

    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, ed);
        final String json = out.toString();

        // Object works, because there's a type in the payload now
        // Edge.class would work as well
        // Anything else would not because we check the type in param here with what's in the JSON, for safety.
        final Edge eRead = (Edge)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
        assertEquals(ed, eRead);
    } catch (IOException e) {
        e.printStackTrace();
        fail("Should not have thrown exception: " + e.getMessage());
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:27,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例4: deserializersTestsTinkerGraph

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入方法依赖的package包/类
@Test
public void deserializersTestsTinkerGraph() {
    final TinkerGraph tg = TinkerGraph.open();

    final Vertex v = tg.addVertex("vertexTest");
    final Vertex v2 = tg.addVertex("vertexTest");

    v.addEdge("knows", v2);

    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, tg);
        final String json = out.toString();

        final Graph gRead = (Graph)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
        assertTrue(approximateGraphsCheck(tg, gRead));
    } catch (IOException e) {
        e.printStackTrace();
        fail("Should not have thrown exception: " + e.getMessage());
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:24,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例5: deserializersTestsVertexProperty

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入方法依赖的package包/类
@Test
public void deserializersTestsVertexProperty() {
    final TinkerGraph tg = TinkerGraph.open();

    final Vertex v = tg.addVertex("vertexTest");

    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    final VertexProperty prop = v.property("born", LocalDateTime.of(1971, 1, 2, 20, 50));

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, prop);
        final String json = out.toString();

        final VertexProperty vPropRead = (VertexProperty)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
        //only classes and ids are checked, that's ok, full vertex property ser/de
        //is checked elsewhere.
        assertEquals(prop, vPropRead);
    } catch (IOException e) {
        e.printStackTrace();
        fail("Should not have thrown exception: " + e.getMessage());
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:25,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例6: deserializersTestsTraversalMetrics

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入方法依赖的package包/类
@Test
public void deserializersTestsTraversalMetrics() {
    final TinkerGraph tg = TinkerFactory.createModern();

    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    final TraversalMetrics tm = tg.traversal().V(1).as("a").has("name").as("b").
            out("knows").out("created").as("c").
            has("name", "ripple").values("name").as("d").
            identity().as("e").profile().next();

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, tm);
        final String json = out.toString();

        final TraversalMetrics traversalMetricsRead = (TraversalMetrics)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
        // toString should be enough to compare TraversalMetrics
        assertTrue(tm.toString().equals(traversalMetricsRead.toString()));
    } catch (IOException e) {
        e.printStackTrace();
        fail("Should not have thrown exception: " + e.getMessage());
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:25,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例7: deserializersTestsTree

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入方法依赖的package包/类
@Test
@org.junit.Ignore("https://issues.apache.org/jira/browse/TINKERPOP-1509")
public void deserializersTestsTree() {
    final TinkerGraph tg = TinkerFactory.createModern();

    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    final Tree t = tg.traversal().V().out().out().tree().next();

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, t);
        final String json = out.toString();

        final Tree treeRead = (Tree)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
        //Map's equals should check each component of the tree recursively
        //on each it will call "equals()" which for Vertices will compare ids, which
        //is ok. Complete vertex deser is checked elsewhere.
        assertEquals(t, treeRead);

    } catch (IOException e) {
        e.printStackTrace();
        fail("Should not have thrown exception: " + e.getMessage());
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:26,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例8: shouldToStringUnknownObjects

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入方法依赖的package包/类
@Test
public void shouldToStringUnknownObjects() {
    GraphSONMapper gm20 = GraphSONMapper.build().version(GraphSONVersion.V2_0).create();
    GraphSONMapper gm10 = GraphSONMapper.build().version(GraphSONVersion.V1_0).create();

    GraphWriter writer = GraphSONWriter.build().mapper(gm20).create();
    // subsequent creations of GraphWriters and GraphSONMappers should not affect
    // each other.
    GraphWriter writer2 = GraphSONWriter.build().mapper(gm10).create();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        writer.writeObject(baos, new FunObject("value"));
        assertEquals(baos.toString(), "\"value\"");
    } catch (Exception e) {
        fail("should have succeeded serializing the unknown object to a string");
    }
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:19,代码来源:GraphSONMessageSerializerV2d0Test.java

示例9: deserializersTestsProperty

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入方法依赖的package包/类
@Test
public void deserializersTestsProperty() {
    final TinkerGraph tg = TinkerGraph.open();

    final Vertex v = tg.addVertex("vertexTest");
    final Vertex v2 = tg.addVertex("vertexTest");

    final Edge ed = v.addEdge("knows", v2);

    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    final Property prop = ed.property("since", Year.parse("1993"));

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, prop);
        final String json = out.toString();

        final Property pRead = (Property)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
        //can't use equals here, because pRead is detached, its parent element has not been intentionally
        //serialized and "equals()" checks that.
        assertTrue(prop.key().equals(pRead.key()) && prop.value().equals(pRead.value()));
    } catch (IOException e) {
        e.printStackTrace();
        fail("Should not have thrown exception: " + e.getMessage());
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:28,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例10: deserializersTestsMetrics

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入方法依赖的package包/类
@Test
public void deserializersTestsMetrics() {
    final TinkerGraph tg = TinkerFactory.createModern();

    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    final TraversalMetrics tm = tg.traversal().V(1).as("a").has("name").as("b").
            out("knows").out("created").as("c").
            has("name", "ripple").values("name").as("d").
            identity().as("e").profile().next();

    final MutableMetrics m = new MutableMetrics(tm.getMetrics(0));
    // making sure nested metrics are included in serde
    m.addNested(new MutableMetrics(tm.getMetrics(1)));

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, m);
        final String json = out.toString();

        final Metrics metricsRead = (Metrics)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
        // toString should be enough to compare Metrics
        assertTrue(m.toString().equals(metricsRead.toString()));
    } catch (IOException e) {
        e.printStackTrace();
        fail("Should not have thrown exception: " + e.getMessage());
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:29,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例11: shouldSerializeTinkerGraphToGraphSONWithTypes

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入方法依赖的package包/类
@Test
public void shouldSerializeTinkerGraphToGraphSONWithTypes() throws Exception {
    final TinkerGraph graph = TinkerFactory.createModern();
    final Mapper<ObjectMapper> mapper = graph.io(IoCore.graphson()).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create();
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        final GraphWriter writer = GraphSONWriter.build().mapper(mapper).create();
        writer.writeObject(out, graph);
        try (final ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray())) {
            final GraphReader reader = GraphSONReader.build().mapper(mapper).create();
            final TinkerGraph target = reader.readObject(inputStream, TinkerGraph.class);
            IoTest.assertModernGraph(target, true, false);
        }
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:15,代码来源:TinkerGraphTest.java

示例12: shouldSerializeTinkerGraphToGraphSONWithTypes

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入方法依赖的package包/类
@Test
public void shouldSerializeTinkerGraphToGraphSONWithTypes() throws Exception {
    final TinkerGraph graph = TinkerFactory.createModern();
    final Mapper<ObjectMapper> mapper = graph.io(IoCore.graphson()).mapper().embedTypes(true).create();
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        final GraphWriter writer = GraphSONWriter.build().mapper(mapper).create();
        writer.writeObject(out, graph);
        try (final ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray())) {
            final GraphReader reader = GraphSONReader.build().mapper(mapper).create();
            final TinkerGraph target = reader.readObject(inputStream, TinkerGraph.class);
            IoTest.assertModernGraph(target, true, false);
        }
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:15,代码来源:TinkerGraphTest.java


注:本文中的org.apache.tinkerpop.gremlin.structure.io.GraphWriter.writeObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。