当前位置: 首页>>代码示例>>Java>>正文


Java UnpooledHeapByteBuf类代码示例

本文整理汇总了Java中io.netty.buffer.UnpooledHeapByteBuf的典型用法代码示例。如果您正苦于以下问题:Java UnpooledHeapByteBuf类的具体用法?Java UnpooledHeapByteBuf怎么用?Java UnpooledHeapByteBuf使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UnpooledHeapByteBuf类属于io.netty.buffer包,在下文中一共展示了UnpooledHeapByteBuf类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: releaseOnConsumption_ByteBuf

import io.netty.buffer.UnpooledHeapByteBuf; //导入依赖的package包/类
@Test
public void releaseOnConsumption_ByteBuf() throws Exception {
    final ByteBuf buf = newPooledBuffer();
    StreamMessage<ByteBuf> stream = newStream(ImmutableList.of(buf));

    if (stream instanceof StreamWriter) {
        assertThat(((StreamWriter<ByteBuf>) stream).write(buf)).isTrue();
        ((StreamWriter<?>) stream).close();
    }
    assertThat(buf.refCnt()).isEqualTo(1);

    stream.subscribe(new Subscriber<ByteBuf>() {
        @Override
        public void onSubscribe(Subscription subscription) {
            subscription.request(1);
        }

        @Override
        public void onNext(ByteBuf o) {
            assertThat(o).isNotSameAs(buf);
            assertThat(o).isInstanceOf(UnpooledHeapByteBuf.class);
            assertThat(o.refCnt()).isEqualTo(1);
            assertThat(buf.refCnt()).isZero();
        }

        @Override
        public void onError(Throwable throwable) {
            Exceptions.throwUnsafely(throwable);
        }

        @Override
        public void onComplete() {
            completed = true;
        }
    });
    await().untilAsserted(() -> assertThat(completed).isTrue());
}
 
开发者ID:line,项目名称:armeria,代码行数:38,代码来源:AbstractStreamMessageTest.java

示例2: releaseOnConsumption_HttpData

import io.netty.buffer.UnpooledHeapByteBuf; //导入依赖的package包/类
@Test
public void releaseOnConsumption_HttpData() throws Exception {
    final ByteBufHttpData data = new ByteBufHttpData(newPooledBuffer(), false);
    StreamMessage<ByteBufHolder> stream = newStream(ImmutableList.of(data));

    if (stream instanceof StreamWriter) {
        assertThat(((StreamWriter<ByteBufHolder>) stream).write(data)).isTrue();
        ((StreamWriter<?>) stream).close();
    }
    assertThat(data.refCnt()).isEqualTo(1);

    stream.subscribe(new Subscriber<ByteBufHolder>() {
        @Override
        public void onSubscribe(Subscription subscription) {
            subscription.request(1);
        }

        @Override
        public void onNext(ByteBufHolder o) {
            assertThat(o).isNotSameAs(data);
            assertThat(o).isInstanceOf(ByteBufHttpData.class);
            assertThat(o.content()).isInstanceOf(UnpooledHeapByteBuf.class);
            assertThat(o.refCnt()).isEqualTo(1);
            assertThat(data.refCnt()).isZero();
        }

        @Override
        public void onError(Throwable throwable) {
            Exceptions.throwUnsafely(throwable);
        }

        @Override
        public void onComplete() {
            completed = true;
        }
    });
    await().untilAsserted(() -> assertThat(completed).isTrue());
}
 
开发者ID:line,项目名称:armeria,代码行数:39,代码来源:AbstractStreamMessageTest.java


注:本文中的io.netty.buffer.UnpooledHeapByteBuf类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。