获取发布者<ByteBuffer>来自输入流 [英] Get an Publisher<ByteBuffer> from InputStream
问题描述
我刚刚升级了我的 mongo-db-java-driver,现在方便的函数 GridFSBucket.uploadFromStream
已经消失了.因此我们现在得到了一个
I just upgraded my mongo-db-java-driver and now the handy function GridFSBucket.uploadFromStream
has gone. Therefore we now got a
GridFSUploadPublisher<ObjectId> uploadFromPublisher(String filename, Publisher<ByteBuffer> source);
任何想法如何将我的 InputStream 转换为 Publisher
?java驱动程序或Reactor中是否有任何实用程序?
Any ideas how to convert my InputStream into an Publisher<ByteBuffer>
? Is there any utilfunction in the java driver or Reactor?
推荐答案
为了让它工作,可以读取流并将数据存储在 byte[]
数组中,稍后可以用 包装ByteBuffer.wrap(byte[])
方法.我查看了较旧的 MongoDB 驱动程序的源代码,发现流被用作实际流,因此当时并没有偷偷地将其转换为 ByteBuffer.
To just make it work one could read stream and store data in byte[]
array which later can be wrapped with ByteBuffer.wrap(byte[])
method.
I've looked into older MongoDB driver's source code and found stream to be used as actual stream, so it was not sneakily converted to ByteBuffer under the hood back then.
似乎没有办法在数据到来时流式传输数据,现在除了将文件加载到内存中别无他法.我可以看到它在许多情况下如何成为问题,但也许我只是无法理解这种方法.
It seems there is no method to stream the data as it comes, there is no other way than to load file into memory now. I can see how it can be a problem in many scenarios, but maybe I just can't understand something about this approach.
这篇关于获取发布者<ByteBuffer>来自输入流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!