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


Java CompositeChannelBuffer类代码示例

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

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

示例1: encode

import org.jboss.netty.buffer.CompositeChannelBuffer; //导入依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
    Object retVal = super.encode(ctx, channel, msg);
    if (retVal instanceof CompositeChannelBuffer) {
        CompositeChannelBuffer ccb = (CompositeChannelBuffer) retVal;
        if (ccb.useGathering() != NettyUtils.DEFAULT_GATHERING) {
            List<ChannelBuffer> decompose = ccb.decompose(ccb.readerIndex(), ccb.readableBytes());
            return ChannelBuffers.wrappedBuffer(NettyUtils.DEFAULT_GATHERING,
                    decompose.toArray(new ChannelBuffer[decompose.size()]));
        }
    }
    return retVal;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:14,代码来源:ESHttpResponseEncoder.java


示例2: httpResponseToString

import org.jboss.netty.buffer.CompositeChannelBuffer; //导入依赖的package包/类
public static String httpResponseToString(DefaultHttpResponse response) {
    StringBuilder messageBuilder = new StringBuilder();

    messageBuilder.append("status: ").append(response.getStatus());
    messageBuilder.append("\n").append("protocol-version: ").append(response.getProtocolVersion());
    for (Map.Entry<String, String> header : response.getHeaders()) {
        messageBuilder.append("\n").append("header: '").append(header.getKey()).append("' -> '").append(header.getValue()).append("'");
    }
    messageBuilder.append("\n").append("content-type: ").append(response.getContent().toString());
    messageBuilder.append("\n").append("content:\n");
    if (response.getContent() instanceof CompositeChannelBuffer) {
        CompositeChannelBuffer ccb = (CompositeChannelBuffer) response.getContent();
        int capacity = ccb.capacity();
        Set<ChannelBuffer> processed = new LinkedHashSet<ChannelBuffer>();
        for (int i = 0; i < capacity; i++) {

            ChannelBuffer cb = ccb.getBuffer(i);
            if (processed.contains(cb)) {
                continue;
            }
            messageBuilder.append(new String(cb.array()));
            processed.add(cb);
        }
    } else {
        messageBuilder.append(new String(response.getContent().array()));
    }
    String result = messageBuilder.toString();
    result = result.replace(Character.toString(Character.MIN_VALUE), "");
    return result;
}
 
开发者ID:azubkov,项目名称:ptp_proxy,代码行数:31,代码来源:Utils.java



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