當前位置: 首頁>>代碼示例>>Java>>正文


Java CompositeByteBuf.addComponents方法代碼示例

本文整理匯總了Java中io.netty.buffer.CompositeByteBuf.addComponents方法的典型用法代碼示例。如果您正苦於以下問題:Java CompositeByteBuf.addComponents方法的具體用法?Java CompositeByteBuf.addComponents怎麽用?Java CompositeByteBuf.addComponents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.buffer.CompositeByteBuf的用法示例。


在下文中一共展示了CompositeByteBuf.addComponents方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: encode

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
@Override
public List<Object> encode(ByteBufAllocator alloc) {
    ByteBuf meta = metadata(alloc);

    ByteBuf head = alloc.buffer(FastdfsConstants.FDFS_HEAD_LEN);
    head.writeLong(meta.readableBytes() + size);
    head.writeByte(cmd());
    head.writeByte(FastdfsConstants.ERRNO_OK);

    CompositeByteBuf cbb = alloc.compositeBuffer();
    cbb.addComponents(head, meta);
    cbb.writerIndex(head.readableBytes() + meta.readableBytes());

    List<Object> requests = new LinkedList<>();
    requests.add(cbb);
    requests.add(content);
    return requests;
}
 
開發者ID:rodbate,項目名稱:fastdfs-spring-boot,代碼行數:19,代碼來源:FileOperationEncoder.java

示例2: toByteBuf

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
/**
 * Turns the given BytesReference into a ByteBuf. Note: the returned ByteBuf will reference the internal
 * pages of the BytesReference. Don't free the bytes of reference before the ByteBuf goes out of scope.
 */
public static ByteBuf toByteBuf(final BytesReference reference) {
    if (reference.length() == 0) {
        return Unpooled.EMPTY_BUFFER;
    }
    if (reference instanceof ByteBufBytesReference) {
        return ((ByteBufBytesReference) reference).toByteBuf();
    } else {
        final BytesRefIterator iterator = reference.iterator();
        // usually we have one, two, or three components from the header, the message, and a buffer
        final List<ByteBuf> buffers = new ArrayList<>(3);
        try {
            BytesRef slice;
            while ((slice = iterator.next()) != null) {
                buffers.add(Unpooled.wrappedBuffer(slice.bytes, slice.offset, slice.length));
            }
            final CompositeByteBuf composite = Unpooled.compositeBuffer(buffers.size());
            composite.addComponents(true, buffers);
            return composite;
        } catch (IOException ex) {
            throw new AssertionError("no IO happens here", ex);
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:28,代碼來源:Netty4Utils.java

示例3: encode

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
@Override
public List<Object> encode(ByteBufAllocator alloc) {
    ByteBuf meta = metadata(alloc);

    ByteBuf head = alloc.buffer(FDFS_HEAD_LEN);
    head.writeLong(meta.readableBytes() + size);
    head.writeByte(cmd());
    head.writeByte(ERRNO_OK);

    CompositeByteBuf cbb = alloc.compositeBuffer();
    cbb.addComponents(head, meta);
    cbb.writerIndex(head.readableBytes() + meta.readableBytes());

    List<Object> requests = new LinkedList<>();
    requests.add(cbb);
    requests.add(content);
    return requests;
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:19,代碼來源:FileOperationEncoder.java

示例4: encrypt

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
@Override
public ByteBuf encrypt(ByteBuf data) {
    if (encCipher == null) {
        byte[] iv = EncryptUtils.randomBytes(getIvLength());
        encCipher = createCipher(iv, true);
        CompositeByteBuf bufs = new CompositeByteBuf(data.alloc(), data.isDirect(), 2);
        bufs.addComponents(true, Unpooled.wrappedBuffer(iv), process(encCipher, data));
        return bufs;
    }

    return process(encCipher, data);
}
 
開發者ID:zhoulifu,項目名稱:ss-java,代碼行數:13,代碼來源:AbstractCrypto.java

示例5: byteBufComposite

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
/**
 * Listing 5.4
 */
public static void byteBufComposite(ByteBuf headerBuf, ByteBuf bodyBuf) {
    CompositeByteBuf messageBuf = Unpooled.compositeBuffer();
    messageBuf.addComponents(headerBuf, bodyBuf);
    // ....
    messageBuf.removeComponent(0); // remove the header				//2

    for (int i = 0; i < messageBuf.numComponents(); i++) {						//3
        System.out.println(messageBuf.component(i).toString());
    }
}
 
開發者ID:zy416548283,項目名稱:NettyStudy,代碼行數:14,代碼來源:ByteBufExamples.java

示例6: createDotStuffedBuffer

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
/**
 * Returns a {@link CompositeByteBuf} that contains the same data as {@code sourceBuffer}, but with
 * SMTP dot-stuffing applied, and (if {@code} appendCRLF is true) a CRLF appended.
 *
 * <p>If dot-stuffing is not required, and {@code appendCRLF} is false, {@code sourceBuffer} is
 * returned. In all other cases, {@code allocator} will be used to create a new {@code ByteBuf}
 * with a {@code refCnt} of one.
 *
 * <p>The {@code previousBytes} parameter is used to maintain dot-stuffing across a series
 * of buffers. Pass the last two bytes of a previous buffer here to ensure an initial dot
 * will be escaped if necessary. Passing null indicates this is the first or only buffer
 * for this message.
 *
 * @param allocator the {@code ByteBufAllocator} to use for new {@code ByteBuf}s
 * @param sourceBuffer the source message data
 * @param previousBytes the previous two bytes of the message, or null
 * @param termination whether to append CRLF to the end of the returned buffer
 */
public static ByteBuf createDotStuffedBuffer(ByteBufAllocator allocator, ByteBuf sourceBuffer, byte[] previousBytes, MessageTermination termination) {
  int dotIndex = findDotAtBeginningOfLine(sourceBuffer, 0, normalisePreviousBytes(previousBytes));

  try {
    if (dotIndex == -1) {
      if (termination == MessageTermination.ADD_CRLF) {
        return allocator.compositeBuffer(2).addComponents(true, sourceBuffer.retainedSlice(), CR_LF_BUFFER.slice());
      } else {
        return sourceBuffer.retainedSlice();
      }
    }

    // Build a CompositeByteBuf to avoid copying
    CompositeByteBuf compositeByteBuf = allocator.compositeBuffer();
    compositeByteBuf.addComponents(true, sourceBuffer.retainedSlice(0, dotIndex), DOT_DOT_BUFFER.slice());

    int nextDotIndex;
    while ((nextDotIndex = findDotAtBeginningOfLine(sourceBuffer, dotIndex + 1, NOT_CR_LF)) != -1) {
      compositeByteBuf.addComponents(true, sourceBuffer.retainedSlice(dotIndex + 1, nextDotIndex - dotIndex - 1), DOT_DOT_BUFFER.slice());
      dotIndex = nextDotIndex;
    }

    compositeByteBuf.addComponent(true, sourceBuffer.retainedSlice(dotIndex + 1, sourceBuffer.readableBytes() - dotIndex - 1));

    if (termination == MessageTermination.ADD_CRLF) {
      compositeByteBuf.addComponent(true, CR_LF_BUFFER.slice());
    }

    return compositeByteBuf;
  } finally {
    sourceBuffer.release();
  }
}
 
開發者ID:HubSpot,項目名稱:NioSmtpClient,代碼行數:52,代碼來源:DotStuffing.java

示例7: writeArgs

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
public static @NotNull ByteBuf writeArgs(
    @NotNull ByteBufAllocator allocator,
    @NotNull ByteBuf header,
    @NotNull List<ByteBuf> args
) {
    int writableBytes = TFrame.MAX_FRAME_PAYLOAD_LENGTH - header.readableBytes();
    List<ByteBuf> bufs = new ArrayList<>(7);
    bufs.add(header);

    while (!args.isEmpty()) {
        ByteBuf arg = args.get(0);
        int len = writeArg(allocator, arg, writableBytes, bufs);
        writableBytes -= len;
        if (writableBytes <= TFrame.FRAME_SIZE_LENGTH) {
            break;
        }

        if (arg.readableBytes() == 0) {
            args.remove(0);
        }
    }

    CompositeByteBuf comp = allocator.compositeBuffer();
    comp.addComponents(bufs);
    comp.writerIndex(TFrame.MAX_FRAME_PAYLOAD_LENGTH - writableBytes);

    return comp;
}
 
開發者ID:uber,項目名稱:tchannel-java,代碼行數:29,代碼來源:CodecUtils.java

示例8: compositeBuf

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
public void compositeBuf() {
    ByteBuf heapBuf = null; //...
    ByteBuf directBuf = null;
    CompositeByteBuf compBuf = null;
    compBuf.addComponents(heapBuf, directBuf);

    compBuf.removeComponent(0);

}
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:10,代碼來源:ByteBufExamples.java

示例9: main

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
/**
 * @param args
 */
public static void main(String[] args)
{
    byte[] bs1 = new byte[]
    { 1, 10, 11, 12 };
    byte[] bs2 = new byte[]
    { 2, 2, 2, 2 };
    byte[] bs3 = new byte[]
    { 3, 3, 3, 3 };
    byte[] bs4 = new byte[]
    { 4, 4, 4, 4 };
    byte[] bs5 = new byte[]
    { 5, 5, 5, 5 };
    byte[] bs6 = new byte[]
    { 6, 6, 6, 6 };

    ByteBuffer buffer1 = ByteBuffer.allocate(1024);
    buffer1.put(bs1);
    buffer1.flip();

    ByteBuf buf1 = Unpooled.copiedBuffer(buffer1);// .copiedBuffer(bs1);

    buffer1.put(bs3);

    ByteBuf buf2 = Unpooled.copiedBuffer(bs2);
    ByteBuf buf3 = Unpooled.copiedBuffer(bs3);
    ByteBuf buf4 = Unpooled.copiedBuffer(bs4);
    ByteBuf buf5 = Unpooled.copiedBuffer(bs5);
    ByteBuf buf6 = Unpooled.copiedBuffer(bs6);

    CompositeByteBuf cb = Unpooled.compositeBuffer();
    cb.addComponents(buf1, buf2, buf3);

    byte dd = cb.getByte(0);

    CompositeByteBuf cb2 = Unpooled.compositeBuffer();
    cb.addComponents(buf4, buf5, buf6);

    // cb.c
    // cb2.writerIndex(128 * 1024);

    cb.addComponent(cb2);

    Long number = cb2.readLong(); // causes IllegalBufferAccessException
                                  // here!

}
 
開發者ID:MyCATApache,項目名稱:Mycat-Balance,代碼行數:50,代碼來源:DecodeRunnable.java


注:本文中的io.netty.buffer.CompositeByteBuf.addComponents方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。