我正在寻找 Java 中的内存流实现.实施应该在 .NET 内存流 实现之后大致建模.
基本上我想要一个类 MemoryStream 必须工厂方法:
class MemoryStream {内存输入 createInput();内存输出 createOutput();}类 MemoryInput 扩展 InputStream {多头头寸();无效寻求(长位置);}类 MemoryOutput 扩展了 OutputStream {多头头寸();无效寻求(长位置);}所以一旦我从 MemoryStream 类中获得了一个实例,我应该能够同时创建输入和输出流,这也应该允许任意方向定位.内存流需要不是圆形的,它应该适用于小尺寸并自动增长.内存流只需要被限制在一个过程中.
有可用的开箱即用代码吗?
解决方案ByteArrayInputStream 和 ByteArrayOutputStream 就是你要找的.
这些是接口InputStream 和OutputStream 的实现,它们从内存中的字节数组中读取和写入.对于 ByteArrayOutputStream,当您将数据写入流时,数组将自动增长.
I am looking for a memory stream implementation in Java. The implementation should be roughly modeled after the .NET memory stream implementation.
Basically I would like to have a class MemoryStream which has to factory methods:
class MemoryStream { MemoryInput createInput(); MemoryOutput createOutput(); } class MemoryInput extends InputStream { long position(); void seek(long pos); } class MemoryOutput extends OutputStream { long position(); void seek(long pos); }So once I have an instance from the class MemoryStream I should be able to concurrently simultaneously create input and output streams, which should also allow positioning in any direction. The memory stream need not be circular, it should work for small sizes well and automatically grow. The memory stream need only be confined into one process.
Any out of the box code available?
解决方案ByteArrayInputStream and ByteArrayOutputStream is what you are looking for.
These are implementations of the interfaces InputStream and OutputStream that read from and write to a byte array in memory. For ByteArrayOutputStream, the array will grow automatically as you write data to the stream.
更多推荐
Java 中的内存流
发布评论