如何在不复制Java的情况下解码MappedByteBuffer
如何在Java中解码mappedbytebuffer
的UTF-8代码点,而无需复制缓冲区?将缓冲区复制到内存将打败映射内存的点,并且由于charsetDecoder
将要求我使用tochararray
方法复制缓冲区,因此它将失败映射的目的内存。有什么方法可以在不复制缓冲区的情况下有效地解码它?
How can I decode the UTF-8 codepoints of a MappedByteBuffer
in Java without copying the buffer? Copying the buffer into memory would defeat the point of mapping the memory, and since CharsetDecoder
would require me to copy the buffer with the toCharArray
method, it would defeat the purpose of mapping the memory. Is there any way to efficiently decode it without copying the buffer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个更完整的答案。
它读取块中的输入文件&将结果存储在
charbuffer
中。Here is a somewhat more complete answer.
It reads the Input-File in Chunks & stores the result in a
CharBuffer
.不是真的:本质上是
char []
需要从byte []
(直接或间接)构建,该(直接或间接)正在备份MappyByteBuffer。因此,必须采用以下内容:
以下片段演示了重复使用上面示例中使用的各种组件的可能性。
如Javadoc中所述,这是一个复杂的问题。
因此,仅应将其视为思想的集合&根据您的具体要求,各种JDK方法的调用可能会或可能不使用。
在使用以下内容之前,您确实需要深入了解charset等。
Not really: essentially a
char[]
needs to be built from thebyte[]
(either direct or indirect) which is backing the MappedByteBuffer.So something like the following is necessary:
The following snippet demonstrates the possibility to reuse various components used in the above example.
As stated in the Javadoc, this is a complex matter.
So it should only be considered as a collection of ideas & invocations of various JDK methods, which may or may not be of use, depending on your concrete requirements.
You really need an in-depth understanding of Charsets etc. before using the following...