/** * {@inheritDoc} */ @Override public void readGraph(final String file) throws IOException { try (final InputStream in = new FileInputStream(file)) { reader().create().readGraph(in, graph); } }
/** * Generate the graph in {@link #createGratefulDead()} into an existing graph. */ public static void generateGratefulDead(final TinkerGraph graph) { final InputStream stream = TinkerFactory.class.getResourceAsStream("grateful-dead.kryo"); try { graph.io(gryo()).reader().create().readGraph(stream, graph); } catch (Exception ex) { throw new IllegalStateException(ex); } }
@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final Configuration conf = new BaseConfiguration(); conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list"); final TinkerGraph graph = TinkerGraph.open(conf); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); } return graph; } }
@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final Configuration conf = new BaseConfiguration(); conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list"); final TinkerGraph graph = TinkerGraph.open(conf); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); } return graph; } }
@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final Configuration conf = new BaseConfiguration(); conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list"); final TinkerGraph graph = TinkerGraph.open(conf); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); } return graph; } }
@Test @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) @FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = FEATURE_STRING_VALUES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) public void shouldReadWriteSelfLoopingEdges() { final Graph source = graph; final Vertex v1 = source.addVertex(); final Vertex v2 = source.addVertex(); v1.addEdge("CONTROL", v2); v1.addEdge("SELFLOOP", v1); final Configuration targetConf = graphProvider.newGraphConfiguration("target", this.getClass(), name.getMethodName(), null); final Graph target = graphProvider.openTestGraph(targetConf); ; try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { source.io(IoCore.gryo()).writer().create().writeGraph(os, source); try (ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray())) { target.io(IoCore.gryo()).reader().create().readGraph(is, target); } } catch (IOException ioe) { throw new RuntimeException(ioe); } assertEquals(IteratorUtils.count(source.vertices()), IteratorUtils.count(target.vertices())); assertEquals(IteratorUtils.count(source.edges()), IteratorUtils.count(target.edges())); } }
/** * {@inheritDoc} */ @Override public void readGraph(final String file) throws IOException { try (final InputStream in = new FileInputStream(file)) { reader().create().readGraph(in, graph); } }
/** * Generate the graph in {@link #createGratefulDead()} into an existing graph. */ public static void generateGratefulDead(final TinkerGraph graph) { final InputStream stream = TinkerFactory.class.getResourceAsStream("grateful-dead.kryo"); try { graph.io(gryo()).reader().create().readGraph(stream, graph); } catch (Exception ex) { throw new IllegalStateException(ex); } }
/** * Generate the graph in {@link #createGratefulDead()} into an existing graph. */ public static void generateGratefulDead(final TinkerGraph graph) { final InputStream stream = TinkerFactory.class.getResourceAsStream("grateful-dead.kryo"); try { graph.io(gryo()).reader().create().readGraph(stream, graph); } catch (Exception ex) { throw new IllegalStateException(ex); } }
@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final Configuration conf = new BaseConfiguration(); conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list"); final TinkerGraph graph = TinkerGraph.open(conf); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); } return graph; } }
@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final Configuration conf = new BaseConfiguration(); conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list"); final TinkerGraph graph = TinkerGraph.open(conf); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); } return graph; } }
@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final Configuration conf = new BaseConfiguration(); conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list"); final TinkerGraph graph = TinkerGraph.open(conf); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); } return graph; } }
@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final Configuration conf = new BaseConfiguration(); conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list"); final TinkerGraph graph = TinkerGraph.open(conf); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); } return graph; } }
@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final Configuration conf = new BaseConfiguration(); conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list"); final TinkerGraph graph = TinkerGraph.open(conf); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); } return graph; } }
@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final Configuration conf = new BaseConfiguration(); conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list"); final TinkerGraph graph = TinkerGraph.open(conf); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); } return graph; } }
@Test @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) @FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = FEATURE_STRING_VALUES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) public void shouldReadWriteSelfLoopingEdges() { final Graph source = graph; final Vertex v1 = source.addVertex(); final Vertex v2 = source.addVertex(); v1.addEdge("CONTROL", v2); v1.addEdge("SELFLOOP", v1); final Configuration targetConf = graphProvider.newGraphConfiguration("target", this.getClass(), name.getMethodName(), null); final Graph target = graphProvider.openTestGraph(targetConf); ; try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { source.io(IoCore.gryo()).writer().create().writeGraph(os, source); try (ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray())) { target.io(IoCore.gryo()).reader().create().readGraph(is, target); } } catch (IOException ioe) { throw new RuntimeException(ioe); } assertEquals(IteratorUtils.count(source.vertices()), IteratorUtils.count(target.vertices())); assertEquals(IteratorUtils.count(source.edges()), IteratorUtils.count(target.edges())); } }