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


Java ChannelBuffers.EMPTY_BUFFER属性代码示例

本文整理汇总了Java中org.jboss.netty.buffer.ChannelBuffers.EMPTY_BUFFER属性的典型用法代码示例。如果您正苦于以下问题:Java ChannelBuffers.EMPTY_BUFFER属性的具体用法?Java ChannelBuffers.EMPTY_BUFFER怎么用?Java ChannelBuffers.EMPTY_BUFFER使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.jboss.netty.buffer.ChannelBuffers的用法示例。


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

示例1: toChannelBuffer

@Override
public ChannelBuffer toChannelBuffer() {
    // nothing to do
    if (length == 0) {
        return ChannelBuffers.EMPTY_BUFFER;
    }

    ChannelBuffer[] buffers;
    ChannelBuffer currentBuffer = null;
    BytesRef ref = new BytesRef();
    int pos = 0;

    // are we a slice?
    if (offset != 0) {
        // remaining size of page fragment at offset
        int fragmentSize = Math.min(length, PAGE_SIZE - (offset % PAGE_SIZE));
        bytearray.get(offset, fragmentSize, ref);
        currentBuffer = ChannelBuffers.wrappedBuffer(ref.bytes, ref.offset, fragmentSize);
        pos += fragmentSize;
    }

    // no need to create a composite buffer for a single page
    if (pos == length && currentBuffer != null) {
        return currentBuffer;
    }

    // a slice > pagesize will likely require extra buffers for initial/trailing fragments
    int numBuffers = countRequiredBuffers((currentBuffer != null ? 1 : 0), length - pos);

    buffers = new ChannelBuffer[numBuffers];
    int bufferSlot = 0;

    if (currentBuffer != null) {
        buffers[bufferSlot] = currentBuffer;
        bufferSlot++;
    }

    // handle remainder of pages + trailing fragment
    while (pos < length) {
        int remaining = length - pos;
        int bulkSize = (remaining > PAGE_SIZE) ? PAGE_SIZE : remaining;
        bytearray.get(offset + pos, bulkSize, ref);
        currentBuffer = ChannelBuffers.wrappedBuffer(ref.bytes, ref.offset, bulkSize);
        buffers[bufferSlot] = currentBuffer;
        bufferSlot++;
        pos += bulkSize;
    }

    // this would indicate that our numBuffer calculation is off by one.
    assert (numBuffers == bufferSlot);

    return ChannelBuffers.wrappedBuffer(NettyUtils.DEFAULT_GATHERING, buffers);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:53,代码来源:PagedBytesReference.java


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