1

调整此缓冲区的容量。如果 {@code newCapacity} 小于当前容量,则此缓冲区的内容被截断。如果 {@code newCapacity} 大于当前容量,则缓冲区会附加长度为 {@code (newCapacity - currentCapacity)} 的未指定数据。

从上面对 ByteBuf.capacity(int newCapacity) 的注释来看,我们只是在这个方法之前的一个 ByteBuf 的内容在展开之后会保留。但是这个测试用例失败了。

ByteBuf bb =
    PooledByteBufAllocator.DEFAULT.directBuffer().order(
        ByteOrder.nativeOrder());

bb.setInt(4, 333);
TestCase.assertEquals(333, bb.getInt(4)); // passed
bb.capacity(4096);
TestCase.assertEquals(333, bb.getInt(4)); // failed

我们得到一个断言失败。

junit.framework.AssertionFailedError: expected:<333> but was:<0>

任何人都可以解释它并告诉我如何在不更改其内容的情况下放大 ByteBuf?

谢谢,敏

4

1 回答 1

0

我认为它与这个错误报告有关......我们目前正在调查它: https ://github.com/netty/netty/issues/1800

于 2013-09-10T07:19:11.930 回答