Example usage for io.netty.buffer ByteBufHolder content

List of usage examples for io.netty.buffer ByteBufHolder content

Introduction

In this page you can find the example usage for io.netty.buffer ByteBufHolder content.

Prototype

ByteBuf content();

Source Link

Document

Return the data which is held by this ByteBufHolder .

Usage

From source file:com.linecorp.armeria.common.stream.DefaultStreamMessageTest.java

License:Apache License

@Test
public void releaseOnConsumption_HttpData() throws Exception {
    final DefaultStreamMessage<ByteBufHolder> m = new DefaultStreamMessage<>();
    final ByteBufHttpData data = new ByteBufHttpData(newPooledBuffer(), false);

    assertThat(m.write(data)).isTrue();/*  w  w  w . j  ava  2s .c  om*/
    assertThat(data.refCnt()).isEqualTo(1);

    m.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() {
        }
    });
}

From source file:com.linecorp.armeria.internal.PooledObjects.java

License:Apache License

private static <T> T copyAndRelease(ByteBufHolder o) {
    try {/* w  w  w.j  a v a2 s .  c  o  m*/
        final ByteBuf content = Unpooled.wrappedBuffer(ByteBufUtil.getBytes(o.content()));
        @SuppressWarnings("unchecked")
        final T copy = (T) o.replace(content);
        return copy;
    } finally {
        ReferenceCountUtil.safeRelease(o);
    }
}

From source file:gedi.remote.ConfigLoggingHandler.java

License:Apache License

/**
 * Generates the default log message of the specified event whose argument is a {@link ByteBufHolder}.
 *///from w  w  w  .j ava 2  s  .c o m
private static String formatByteBufHolder(ChannelHandlerContext ctx, String eventName, ByteBufHolder msg,
        boolean writeHex) {
    String chStr = ctx.channel().toString();
    String msgStr = msg.toString();
    ByteBuf content = msg.content();
    int length = content.readableBytes();
    if (length == 0) {
        StringBuilder buf = new StringBuilder(
                chStr.length() + 1 + eventName.length() + 2 + msgStr.length() + 4);
        buf.append(chStr).append(' ').append(eventName).append(", ").append(msgStr).append(", 0B");
        return buf.toString();
    } else {
        int rows = length / 16 + (length % 15 == 0 ? 0 : 1) + 4;
        StringBuilder buf = new StringBuilder(
                chStr.length() + 1 + eventName.length() + 2 + msgStr.length() + 2 + 10 + 1 + 2 + rows * 80);

        buf.append(chStr).append(' ').append(eventName).append(": ");
        buf.append(msgStr).append(", ").append(length).append('B');
        if (writeHex)
            appendHexDump(buf, content);

        return buf.toString();
    }
}

From source file:io.advantageous.conekt.http.impl.ConektHttpHandler.java

License:Open Source License

private static ByteBuf safeBuffer(ByteBufHolder holder, ByteBufAllocator allocator) {
    return safeBuffer(holder.content(), allocator);
}

From source file:org.wso2.carbon.transport.http.netty.listener.HTTPTraceLoggingHandler.java

License:Open Source License

private static String formatPayload(ByteBufHolder msg) throws CharacterCodingException {
    String msgStr = msg.toString();
    ByteBuf content = msg.content();
    int length = content.readableBytes();
    if (length == 0) {
        StringBuilder stringBuilder = new StringBuilder(2 + msgStr.length() + 4);
        stringBuilder.append(msgStr).append(", 0B");
        return stringBuilder.toString();
    } else {/*w  ww  . ja v  a  2  s .  c om*/
        int rows = length / 16 + (length % 16 == 0 ? 0 : 1) + 4;
        StringBuilder stringBuilder = new StringBuilder(2 + msgStr.length() + 2 + 10 + 1 + 2 + rows * 80);

        stringBuilder.append(msgStr).append(", ").append(length).append('B').append(NEWLINE);
        appendPayload(stringBuilder, content);

        return stringBuilder.toString();
    }
}