Java 中的内存流

编程入门 行业动态 更新时间:2024-10-24 04:45:00
本文介绍了Java 中的内存流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在寻找 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 中的内存流

本文发布于:2023-11-08 15:50:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569805.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内存   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!