- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
虽然存在 ByteBuffer.put(ByteBuffer)
方法,但 ByteBuffer.get(ByteBuffer)
似乎丢失了?我应该如何从较大的 ByteBuffer
读取较小的 ByteBuffer
?
最佳答案
存在ByteBuffer#put
方法:
public ByteBuffer put(ByteBuffer src) : This method transfers the bytes remaining in the given source buffer into this buffer
您正在寻找类似的东西
public ByteBuffer get(ByteBuffer dst) : This method transfers the bytes remaining in this buffer into the given target buffer
但请考虑操作 get
和 put
在某种程度上是对称的。
ByteBuffer src = ...
ByteBuffer dst = ...
//src.get(dst); // Does not exist
dst.put(src); // Use this instead
您明确谈论了较小和较大缓冲区。因此,我假设 dst 缓冲区小于 src 缓冲区。在这种情况下,您只需相应地设置源缓冲区的限制即可:
ByteBuffer src = ...
ByteBuffer dst = ...
int oldLimit = src.limit();
src.limit(src.position()+dst.remaining());
dst.put(src);
src.limit(oldLimit);
可以使用替代公式(例如使用原始缓冲区的ByteBuffer#slice()
)。但无论如何,您不必必须将缓冲区内容复制到新的字节数组中才能将其传输到另一个缓冲区!
关于java - 如何从较大的 ByteBuffer 中读取较小的 ByteBuffer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21857854/
我正在通过 PHP 将 .csv 中的两行插入到表中。 我还会跟踪任何错误,如果发生错误,我不会提交事务。插入表后,我检索结果行的 ID(全部在一个事务中提交),并且 csv 的第一行对应于第二个 I
一个应用程序托管一个具有三个接口(interface)的 Web 服务,用于三个单独且独立的操作,所有这些操作都在应用程序的不同组件中实现,彼此独立,例如在不同的包等中,所以他们对彼此了解不多,只共享
我希望在单击特定表格数据单元格时同时选中单选按钮和单选按钮单击事件。我已经使用以下方法实现了这一点: $(document).ready(function() { $("td").click(
JSFiddle:https://jsfiddle.net/oyp1zxaq/ 本质上,我只是想在较大的 div 中放置四个具有定义宽度的较小 div,但我希望它们在其中间隔开。 我想知道是否有一种方
我在一个布局中有两个 View 。我将分别称它们为 View A 和 View B。 ┌──────┐ │┌─┐┌─┐│ ││A││B││ │└─┘└─┘│ └──────┘ 父布局(包括View A
我是一名优秀的程序员,十分优秀!