创建 shim 流
我正在使用的解压缩 API 具有以下 API:
Decode(Stream inStream,Stream outStream)
我想围绕该 API 创建一个包装器,以便我可以创建自己的 Stream 类来提供解码的数据。
Stream decodedStream=new BlaDecodeStream(inStream);
这样我就可以使用该流作为 XmlReader 构造函数的参数,就像使用 System.IO.Compression.GZipStream 一样。据我所知,唯一的其他选项是将 outStream 流设置为 MemoryStream 或 FileStream 并进行两跳。我正在处理的文件非常大,因此这两个选项都不是特别有吸引力。
在我重新发明轮子之前,是否有任何我可以借鉴的现有技术,或者 BCL 中我可能错过的东西? CircularStream
实现这里会提供一些帮助,但我'我真的在寻找类似的东西,当流的内部缓冲区在读取时为“空”时会阻塞(而不是溢出/欠载),而在写入时内部缓冲区已满时会阻塞。
通过这种方式,它可以用作参数 outStream
并且同时(即从另一个线程)可以由 XmlReader
读取。
A decompression API that I am using has the following API:
Decode(Stream inStream,Stream outStream)
I'd like to create a wrapper around this API, such that I can create my own Stream
class which offers up the decoded data.
Stream decodedStream=new BlaDecodeStream(inStream);
So that I can than use this stream as a parameter to the XmlReader constructor in the same way one might use the System.IO.Compression.GZipStream
. As far as I can tell, the only other option is set outStream stream to a MemoryStream or to a FileStream and go in two hops. The files I am dealing with are enormous, so neither of these options are particularly attractive.
Before I go reinventing the wheel, is there any prior art that I might be able to draw from, or something in the BCL I might have missed? The CircularStream
implementation here would go some of the way to helping, but I'm really looking for something similar that would block (as opposed to over/underrun) when the Stream's internal buffer is 'empty' when reading from it and block when the internal buffer is full when writing to it.
In this way it could serve as parameter outStream
and simultaneously (i.e. from another thread) could be read from by the XmlReader
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我询问了阻塞流阅读器不久前。我实施了其中一项建议,效果很好。
I asked about a blocking stream reader a while ago. I implemented one of the suggestions and it works fine.