private void loadGraph() { final File f = new File(graphLocation); if (f.exists() && f.isFile()) { try { if (graphFormat.equals("graphml")) { io(IoCore.graphml()).readGraph(graphLocation); } else if (graphFormat.equals("graphson")) { io(IoCore.graphson()).readGraph(graphLocation); } else if (graphFormat.equals("gryo")) { io(IoCore.gryo()).readGraph(graphLocation); } else { io(IoCore.createIoBuilder(graphFormat)).readGraph(graphLocation); } } catch (Exception ex) { throw new RuntimeException(String.format("Could not load graph at %s with %s", graphLocation, graphFormat), ex); } } }
private void saveGraph() { final File f = new File(graphLocation); if (f.exists()) { f.delete(); } else { final File parent = f.getParentFile(); // the parent would be null in the case of an relative path if the graphLocation was simply: "f.gryo" if (parent != null && !parent.exists()) { parent.mkdirs(); } } try { if (graphFormat.equals("graphml")) { io(IoCore.graphml()).writeGraph(graphLocation); } else if (graphFormat.equals("graphson")) { io(IoCore.graphson()).writeGraph(graphLocation); } else if (graphFormat.equals("gryo")) { io(IoCore.gryo()).writeGraph(graphLocation); } else { io(IoCore.createIoBuilder(graphFormat)).writeGraph(graphLocation); } } catch (Exception ex) { throw new RuntimeException(String.format("Could not save graph at %s with %s", graphLocation, graphFormat), ex); } }
@Parameterized.Parameters(name = "{0}") public static Iterable<Object[]> data() { return Arrays.asList(new Object[][]{ {"graphml", IoCore.graphml(), false, true, ".xml"}, {"graphsonv1d0", GraphSONIo.build(GraphSONVersion.V1_0), true, true, ".json"}, {"graphsonv2d0", GraphSONIo.build(GraphSONVersion.V2_0), true, true, ".json"}, {"graphsonv3d0", GraphSONIo.build(GraphSONVersion.V3_0), true, true, ".json"}, {"gryo-v3", GryoIo.build(GryoVersion.V1_0), false, false, ".kryo"}, {"gryo-v3", GryoIo.build(GryoVersion.V3_0), false, false, ".kryo"} }); }
@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() throws Exception { 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.graphml()).writer().create().writeGraph(os, source); try (ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray())) { target.io(IoCore.graphml()).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())); }
/** * flush the cache * * @throws Exception */ public void flush() throws Exception { getSystem().graph().io(IoCore.graphml()).writeGraph(file.getPath()); }
private void loadGraph() { final File f = new File(graphLocation); if (f.exists() && f.isFile()) { try { if (graphFormat.equals("graphml")) { io(IoCore.graphml()).readGraph(graphLocation); } else if (graphFormat.equals("graphson")) { io(IoCore.graphson()).readGraph(graphLocation); } else if (graphFormat.equals("gryo")) { io(IoCore.gryo()).readGraph(graphLocation); } else { io(IoCore.createIoBuilder(graphFormat)).readGraph(graphLocation); } } catch (Exception ex) { throw new RuntimeException(String.format("Could not load graph at %s with %s", graphLocation, graphFormat), ex); } } }
private void loadGraph() { final File f = new File(graphLocation); if (f.exists() && f.isFile()) { try { if (graphFormat.equals("graphml")) { io(IoCore.graphml()).readGraph(graphLocation); } else if (graphFormat.equals("graphson")) { io(IoCore.graphson()).readGraph(graphLocation); } else if (graphFormat.equals("gryo")) { io(IoCore.gryo()).readGraph(graphLocation); } else { io(IoCore.createIoBuilder(graphFormat)).readGraph(graphLocation); } } catch (Exception ex) { throw new RuntimeException(String.format("Could not load graph at %s with %s", graphLocation, graphFormat), ex); } } }
private void saveGraph() { final File f = new File(graphLocation); if (f.exists()) { f.delete(); } else { final File parent = f.getParentFile(); // the parent would be null in the case of an relative path if the graphLocation was simply: "f.gryo" if (parent != null && !parent.exists()) { parent.mkdirs(); } } try { if (graphFormat.equals("graphml")) { io(IoCore.graphml()).writeGraph(graphLocation); } else if (graphFormat.equals("graphson")) { io(IoCore.graphson()).writeGraph(graphLocation); } else if (graphFormat.equals("gryo")) { io(IoCore.gryo()).writeGraph(graphLocation); } else { io(IoCore.createIoBuilder(graphFormat)).writeGraph(graphLocation); } } catch (Exception ex) { throw new RuntimeException(String.format("Could not save graph at %s with %s", graphLocation, graphFormat), ex); } }
private void saveGraph() { final File f = new File(graphLocation); if (f.exists()) { f.delete(); } else { final File parent = f.getParentFile(); // the parent would be null in the case of an relative path if the graphLocation was simply: "f.gryo" if (parent != null && !parent.exists()) { parent.mkdirs(); } } try { if (graphFormat.equals("graphml")) { io(IoCore.graphml()).writeGraph(graphLocation); } else if (graphFormat.equals("graphson")) { io(IoCore.graphson()).writeGraph(graphLocation); } else if (graphFormat.equals("gryo")) { io(IoCore.gryo()).writeGraph(graphLocation); } else { io(IoCore.createIoBuilder(graphFormat)).writeGraph(graphLocation); } } catch (Exception ex) { throw new RuntimeException(String.format("Could not save graph at %s with %s", graphLocation, graphFormat), ex); } }
@Parameterized.Parameters(name = "{0}") public static Iterable<Object[]> data() { return Arrays.asList(new Object[][]{ {"graphml", IoCore.graphml(), false, true, ".xml"}, {"graphsonv1d0", GraphSONIo.build(GraphSONVersion.V1_0), true, true, ".json"}, {"graphsonv2d0", GraphSONIo.build(GraphSONVersion.V2_0), true, true, ".json"}, {"graphsonv3d0", GraphSONIo.build(GraphSONVersion.V3_0), true, true, ".json"}, {"gryo-v3", GryoIo.build(GryoVersion.V1_0), false, false, ".kryo"}, {"gryo-v3", GryoIo.build(GryoVersion.V3_0), false, false, ".kryo"} }); }
system.graph().io(IoCore.graphml()).readGraph(file.getPath()); final Holder<Exception> exceptionHolder=new Holder<Exception>();
@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() throws Exception { 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.graphml()).writer().create().writeGraph(os, source); try (ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray())) { target.io(IoCore.graphml()).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())); }
@Override protected void processGraph(String documentSourceName, Graph graph) { WriterBuilder<? extends GraphWriter> writer; switch (format) { case GYRO: writer = graph.io(IoCore.gryo()).writer(); break; case GRAPHSON: writer = graph.io(IoCore.graphson()).writer(); break; case GRAPHML: // FALL THROUGH default: writer = graph.io(IoCore.graphml()).writer().normalize(true); break; } try (final OutputStream os = createOutputStream(documentSourceName)) { writer.create().writeGraph(os, graph); } catch (IOException e) { getMonitor().error("Error writing graph", e); } }
@Override protected void processGraph(String documentSourceName, Graph graph) { WriterBuilder<? extends GraphWriter> writer; switch (format) { case GYRO: writer = graph.io(IoCore.gryo()).writer(); break; case GRAPHSON: writer = graph.io(IoCore.graphson()).writer(); break; case GRAPHML: // FALL THROUGH default: writer = graph.io(IoCore.graphml()).writer().normalize(true); break; } try (final OutputStream os = createOutputStream(documentSourceName)) { writer.create().writeGraph(os, graph); } catch (IOException e) { getMonitor().error("Error writing graph", e); } }
@Override protected void processGraph(String documentSourceName, Graph graph) { WriterBuilder<? extends GraphWriter> writer; switch (format) { case GYRO: writer = graph.io(IoCore.gryo()).writer(); break; case GRAPHSON: writer = graph.io(IoCore.graphson()).writer(); break; case GRAPHML: // FALL THROUGH default: writer = graph.io(IoCore.graphml()).writer().normalize(true); break; } try (final OutputStream os = createOutputStream(documentSourceName)) { writer.create().writeGraph(os, graph); } catch (IOException e) { getMonitor().error("Error writing graph", e); } }
@Override protected void processGraph(String documentSourceName, Graph graph) { WriterBuilder<? extends GraphWriter> writer; switch (format) { case GYRO: writer = graph.io(IoCore.gryo()).writer(); break; case GRAPHSON: writer = graph.io(IoCore.graphson()).writer(); break; case GRAPHML: // FALL THROUGH default: writer = graph.io(IoCore.graphml()).writer().normalize(true); break; } try (final OutputStream os = createOutputStream(documentSourceName)) { writer.create().writeGraph(os, graph); } catch (IOException e) { getMonitor().error("Error writing graph", e); } }