- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
以下语句将在图形服务器上创建一个新文件:
graph.io(IoCore.graphml()).writer().normalize(true).create().writeGraph(new FileOutputStream("export.graphml"), graph)
我想使用不同的 OutputStream直接在我的 gremlin 客户端中查看输出。我试过 DataOutputStream() 但得到了 NullPointerException。我如何从 writeGraph() 获得响应?
最佳答案
我最初读这个问题是想知道如何创建一个远程 OutputStream
以从服务器写回客户端上的某个本地文件,这可能有一些解决方案,但我不确定答案是什么。当我碰巧再次查看这个问题时,尽管赏金提示您对“将完整的 tinkerpop 图导出到控制台”感兴趣,在这种情况下,可能会满足不同的方法。
我会直接使用 Builder
直接构造一个 GraphMLWriter
,然后写入 byte[]
并将其作为 返回字符串
:
baos = new ByteArrayOutputStream()
graph.io(IoCore.graphml()).writer().normalize(true).create().writeGraph(baos, graph)
baos.toByteArray()
这是完整的控制台 session ,尽管我省略了一些 graphml 以帮助提高可读性:
gremlin> :remote connect tinkerpop.server conf/remote-objects.yaml session
==>Configured localhost/127.0.0.1:8182-[df3107c1-b25b-4f1c-a1f3-552353e9023d]
gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - [localhost/127.0.0.1:8182]-[df3107c1-b25b-4f1c-a1f3-552353e9023d] - type ':remote console' to return to local mode
gremlin> baos = new ByteArrayOutputStream();[]
gremlin> graph.io(IoCore.graphml()).writer().normalize(true).create().writeGraph(baos, graph);[]
gremlin> new String(baos.toByteArray(), java.nio.charset.StandardCharsets.UTF_8)
==><?xml version="1.0" ?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.1/graphml.xsd">
<key id="age" for="node" attr.name="age" attr.type="int"></key>
<key id="labelV" for="node" attr.name="labelV" attr.type="string"></key>
<key id="lang" for="node" attr.name="lang" attr.type="string"></key>
<key id="name" for="node" attr.name="name" attr.type="string"></key>
<key id="labelE" for="edge" attr.name="labelE" attr.type="string"></key>
<key id="weight" for="edge" attr.name="weight" attr.type="double"></key>
<graph id="G" edgedefault="directed">
<node id="1">
<data key="labelV">person</data>
<data key="age">29</data>
<data key="name">marko</data>
</node>
...
</graphml>
gremlin> :remote console
==>All scripts will now be evaluated locally - type ':remote console' to return to remote mode for Gremlin Server - [localhost/127.0.0.1:8182]-[df3107c1-b25b-4f1c-a1f3-552353e9023d]
gremlin> result
==>result{object=<?xml version="1.0" ?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.1/graphml.xsd">
<key id="age" for="node" attr.name="age" attr.type="int"></key>
<key id="labelV" for="node" attr.name="labelV" attr.type="string"></key>
<key id="lang" for="node" attr.name="lang" attr.type="string"></key>
<key id="name" for="node" attr.name="name" attr.type="string"></key>
<key id="labelE" for="edge" attr.name="labelE" attr.type="string"></key>
<key id="weight" for="edge" attr.name="weight" attr.type="double"></key>
<graph id="G" edgedefault="directed">
<node id="1">
<data key="labelV">person</data>
<data key="age">29</data>
<data key="name">marko</data>
</node>
...
</graphml> class=java.lang.String}
gremlin> result.get(0).getString()
==><?xml version="1.0" ?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.1/graphml.xsd">
<key id="age" for="node" attr.name="age" attr.type="int"></key>
<key id="labelV" for="node" attr.name="labelV" attr.type="string"></key>
<key id="lang" for="node" attr.name="lang" attr.type="string"></key>
<key id="name" for="node" attr.name="name" attr.type="string"></key>
<key id="labelE" for="edge" attr.name="labelE" attr.type="string"></key>
<key id="weight" for="edge" attr.name="weight" attr.type="double"></key>
<graph id="G" edgedefault="directed">
<node id="1">
<data key="labelV">person</data>
<data key="age">29</data>
<data key="name">marko</data>
</node>
...
</graph>
</graphml>
gremlin>
我的 Gremlin 控制台示例将脚本发送到服务器以在 session 中执行(因此这种方法也可以作为从驱动程序发送的脚本,假设它作为一个脚本发送,或者如果使用 session ,则每一行都可以单独发送)。请注意,从服务器返回的每一行的结果都存储在控制台的 result
变量中。为了使其正常工作,重要的是您连接到默认 remote-objects.yaml
中提供的配置,其中返回对象而不仅仅是字符串表示,尽管在这种情况下,因为最终object 是一个 String
它可能无关紧要。我想这是否取决于您打算如何处理结果本身。
需要考虑的一些注意事项:
Graph
API(即 graph.io()
)和/或直接使用 GraphWriter
实现,所以我想这些 API 可能会在未来的版本中消失,但考虑到目前没有更好的解决方案,恐怕没有太多选择。 关于gremlin - 使用 writeGraph() 将 Tinkerpop 图导出到不同的 OutputStream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61610552/
以下语句将在图形服务器上创建一个新文件: graph.io(IoCore.graphml()).writer().normalize(true).create().writeGraph(new Fil
我是一名优秀的程序员,十分优秀!