来自MappedByteBuffer的DataInputStream

时间:2012-08-03 07:34:38

标签: java memory-mapped-files bytebuffer datainputstream

我想知道是否可以创建由MappedByteBuffer实例支持的DataInputStream?

MappedByteBuffer buff = (initialize...);
ByteArrayInputStream bis = new ByteArrayInputStream(buff.array());

此代码段抛出UnsupportedOperationException,因为映射的字节缓冲区不受可访问数组的支持。

然后我尝试通过调用load方法将字节加载到pyhsical内存是没有用的。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

您可以覆盖DataInputStream中的方法以使用MappedByteBuffer。

但是,最简单的方法是直接使用MappedByteBuffer,因为它几乎支持所有相同的方法。