當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。