如何从 InputStream 创建 Vert.x ReadStream
How to create a Vert.x ReadStream from an InputStream
我想将本地进程的标准输出流式传输到 Vert.x HttpResponse。
要做到这一点,我认为我必须 stream/convert/pipe 一个 java.io.InputStream
(将进程标准输出流式传输)到一个 io.vertx.core.streams.ReadStream
,然后我可以将 ReadStream
传送到HttpResponse
.
我正在寻找一种对内存影响较小的解决方案,因此读取内存中的整个标准输出然后将其刷新到 HttpResponse 是不可能的。
谢谢
查看:
https://gist.github.com/Stwissel/a7f8ce79785afd49eb2ced69b56335de
以下是我的使用方法:
InputStream is = ...
AsyncInputStream ais = new AsyncInputStream(
vertx, vertx.getOrCreateContext(), is);
ais.pipeTo(response);
另一种方法是使用 vertx-java.io 库中的 OutputToReadStream
class(我是作者):
new OutputToReadStream(vertx).wrap(inputStream).pipeTo(response);
我想将本地进程的标准输出流式传输到 Vert.x HttpResponse。
要做到这一点,我认为我必须 stream/convert/pipe 一个 java.io.InputStream
(将进程标准输出流式传输)到一个 io.vertx.core.streams.ReadStream
,然后我可以将 ReadStream
传送到HttpResponse
.
我正在寻找一种对内存影响较小的解决方案,因此读取内存中的整个标准输出然后将其刷新到 HttpResponse 是不可能的。
谢谢
查看:
https://gist.github.com/Stwissel/a7f8ce79785afd49eb2ced69b56335de
以下是我的使用方法:
InputStream is = ...
AsyncInputStream ais = new AsyncInputStream(
vertx, vertx.getOrCreateContext(), is);
ais.pipeTo(response);
另一种方法是使用 vertx-java.io 库中的 OutputToReadStream
class(我是作者):
new OutputToReadStream(vertx).wrap(inputStream).pipeTo(response);