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


Java CompositeByteBuf.writerIndex方法代碼示例

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


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

示例3: createContent

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
protected ByteBuf createContent(ByteBuf pathByteBuf, ByteBuf... restOfContent) {
    if (restOfContent == null || restOfContent.length == 0) {
        return pathByteBuf;
    } else {
        CompositeByteBuf composite = Unpooled.compositeBuffer(1 + restOfContent.length);
        composite.addComponent(pathByteBuf);
        composite.writerIndex(composite.writerIndex() + pathByteBuf.readableBytes());

        for (ByteBuf component : restOfContent) {
            composite.addComponent(component);
            composite.writerIndex(composite.writerIndex() + component.readableBytes());
        }

        return composite;
    }
}
 
開發者ID:couchbase,項目名稱:couchbase-jvm-core,代碼行數:17,代碼來源:AbstractSubdocRequest.java

示例4: encode

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
private static ByteBuf encode(List<LookupCommand> commands) {
    CompositeByteBuf compositeBuf = Unpooled.compositeBuffer(commands.size()); //FIXME pooled allocator?
    for (LookupCommand command : commands) {
        byte[] pathBytes = command.path().getBytes(CharsetUtil.UTF_8);
        short pathLength = (short) pathBytes.length;

        ByteBuf commandBuf = Unpooled.buffer(4 + pathLength); //FIXME a way of using the pooled allocator?
        commandBuf.writeByte(command.opCode());
        //flags
        if (command.xattr()) {
            commandBuf.writeByte(SUBDOC_FLAG_XATTR_PATH);
        } else {
            commandBuf.writeByte(0);
        }
        commandBuf.writeShort(pathLength);
        //no value length
        commandBuf.writeBytes(pathBytes);

        compositeBuf.addComponent(commandBuf);
        compositeBuf.writerIndex(compositeBuf.writerIndex() + commandBuf.readableBytes());
    }
    return compositeBuf;
}
 
開發者ID:couchbase,項目名稱:couchbase-jvm-core,代碼行數:24,代碼來源:SubMultiLookupRequest.java

示例5: encode

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
private static ByteBuf encode(EmbeddedChannel ch, Envelope... envelopes) {
	for (Envelope env : envelopes) {
		ch.writeOutbound(env);

		if (env.getBuffer() != null) {
			verify(env.getBuffer(), times(1)).recycleBuffer();
		}
	}

	CompositeByteBuf encodedEnvelopes = new CompositeByteBuf(ByteBufAllocator.DEFAULT, false, envelopes.length);

	ByteBuf buf;
	while ((buf = (ByteBuf) ch.readOutbound()) != null) {
		encodedEnvelopes.addComponent(buf);
	}

	return encodedEnvelopes.writerIndex(encodedEnvelopes.capacity());
}
 
開發者ID:citlab,項目名稱:vs.msc.ws14,代碼行數:19,代碼來源:InboundEnvelopeDecoderTest.java

示例6: encodePacket

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
public static ByteBuf encodePacket(final Packet packet) throws IOException {
  ByteBuf dataBytes = packet.getData();
  boolean hasData = dataBytes != null;

  CompositeByteBuf compositeByteBuf = PooledByteBufAllocator.DEFAULT.compositeBuffer(hasData ? 1 : 2);

  byte[] typeBytes = packet.getType().getValueAsBytes();
  int headerCapacity = typeBytes.length + DELIMITER_LENGTH + DELIMITER_LENGTH + (hasData ? DELIMITER_LENGTH : 0);
  ByteBuf headerByteBuf = PooledByteBufAllocator.DEFAULT.buffer(headerCapacity, headerCapacity);
  headerByteBuf.writeBytes(typeBytes);
  headerByteBuf.writeBytes(DELIMITER_BYTES);
  headerByteBuf.writeBytes(DELIMITER_BYTES);
  if (hasData) {
    headerByteBuf.writeBytes(DELIMITER_BYTES);
  }
  compositeByteBuf.addComponent(headerByteBuf);
  int compositeReadableBytes = headerByteBuf.readableBytes();

  if (hasData) {
    compositeByteBuf.addComponent(dataBytes);
    compositeReadableBytes += dataBytes.readableBytes();
  }

  compositeByteBuf.writerIndex(compositeReadableBytes);
  return compositeByteBuf;
}
 
開發者ID:scalecube,項目名稱:socketio,代碼行數:27,代碼來源:PacketEncoder.java

示例7: encode

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {

  if (RpcConstants.EXTRA_DEBUGGING) {
    logger.debug("ChunkCreationHandler called with msg {} of size {} with chunkSize {}",
        msg, msg.readableBytes(), chunkSize);
  }

  if (!ctx.channel().isOpen()) {
    logger.debug("Channel closed, skipping encode inside {}.", RpcConstants.CHUNK_CREATION_HANDLER);
    msg.release();
    return;
  }

  // Calculate the number of chunks based on configured chunk size and input msg size
  int numChunks = (int) Math.ceil((double) msg.readableBytes() / chunkSize);

  // Initialize a composite buffer to hold numChunks chunk.
  final CompositeByteBuf cbb = ctx.alloc().compositeBuffer(numChunks);

  int cbbWriteIndex = 0;
  int currentChunkLen = min(msg.readableBytes(), chunkSize);

  // Create slices of chunkSize from input msg and add it to the composite buffer.
  while (numChunks > 0) {
    final ByteBuf chunkBuf = msg.slice(msg.readerIndex(), currentChunkLen);
    chunkBuf.retain();
    cbb.addComponent(chunkBuf);
    cbbWriteIndex += currentChunkLen;
    msg.skipBytes(currentChunkLen);
    --numChunks;
    currentChunkLen = min(msg.readableBytes(), chunkSize);
  }

  // Update the writerIndex of composite byte buffer. Netty doesn't do it automatically.
  cbb.writerIndex(cbbWriteIndex);

  // Add the final composite bytebuf into output buffer.
  out.add(cbb);
}
 
開發者ID:axbaretto,項目名稱:drill,代碼行數:41,代碼來源:ChunkCreationHandler.java

示例8: testSimpleSendCompositeDirectByteBuf

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
public void testSimpleSendCompositeDirectByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable {
    CompositeByteBuf buf = Unpooled.compositeBuffer();
    buf.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 0, 2));
    buf.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 2, 2));
    buf.writerIndex(4);
    testSimpleSend0(sb, cb, buf, true, BYTES, 1);

    CompositeByteBuf buf2 = Unpooled.compositeBuffer();
    buf2.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 0, 2));
    buf2.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 2, 2));
    buf2.writerIndex(4);
    testSimpleSend0(sb, cb, buf2, true, BYTES, 4);
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:14,代碼來源:DatagramUnicastTest.java

示例9: testSimpleSendCompositeHeapByteBuf

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
public void testSimpleSendCompositeHeapByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable {
    CompositeByteBuf buf = Unpooled.compositeBuffer();
    buf.addComponent(Unpooled.buffer().writeBytes(BYTES, 0, 2));
    buf.addComponent(Unpooled.buffer().writeBytes(BYTES, 2, 2));
    buf.writerIndex(4);
    testSimpleSend0(sb, cb, buf, true, BYTES, 1);

    CompositeByteBuf buf2 = Unpooled.compositeBuffer();
    buf2.addComponent(Unpooled.buffer().writeBytes(BYTES, 0, 2));
    buf2.addComponent(Unpooled.buffer().writeBytes(BYTES, 2, 2));
    buf2.writerIndex(4);
    testSimpleSend0(sb, cb, buf2, true, BYTES, 4);
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:14,代碼來源:DatagramUnicastTest.java

示例10: testSimpleSendCompositeMixedByteBuf

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
public void testSimpleSendCompositeMixedByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable {
    CompositeByteBuf buf = Unpooled.compositeBuffer();
    buf.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 0, 2));
    buf.addComponent(Unpooled.buffer().writeBytes(BYTES, 2, 2));
    buf.writerIndex(4);
    testSimpleSend0(sb, cb, buf, true, BYTES, 1);

    CompositeByteBuf buf2 = Unpooled.compositeBuffer();
    buf2.addComponent(Unpooled.directBuffer().writeBytes(BYTES, 0, 2));
    buf2.addComponent(Unpooled.buffer().writeBytes(BYTES, 2, 2));
    buf2.writerIndex(4);
    testSimpleSend0(sb, cb, buf2, true, BYTES, 4);
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:14,代碼來源:DatagramUnicastTest.java

示例11: testStreamStartIsOnlyWrittenOnce

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
@Test
public void testStreamStartIsOnlyWrittenOnce() throws Exception {
    ByteBuf in = Unpooled.wrappedBuffer(new byte[] {
        'n', 'e', 't', 't', 'y'
    });

    channel.writeOutbound(in.copy());
    in.readerIndex(0); // rewind the buffer to write the same data
    channel.writeOutbound(in.copy());
    assertTrue(channel.finish());

    ByteBuf expected = Unpooled.wrappedBuffer(new byte[] {
        (byte) 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
         0x01, 0x09, 0x00, 0x00, 0x6f, -0x68, -0x7e, -0x5e, 'n', 'e', 't', 't', 'y',
         0x01, 0x09, 0x00, 0x00, 0x6f, -0x68, -0x7e, -0x5e, 'n', 'e', 't', 't', 'y',
    });

    CompositeByteBuf actual = Unpooled.compositeBuffer();
    for (;;) {
        ByteBuf m = (ByteBuf) channel.readOutbound();
        if (m == null) {
            break;
        }
        actual.addComponent(m);
        actual.writerIndex(actual.writerIndex() + m.readableBytes());
    }
    assertEquals(releaseLater(expected), releaseLater(actual));
    in.release();
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:30,代碼來源:SnappyFramedEncoderTest.java

示例12: add

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
private void add(CompositeByteBuf buf, HttpObject httpObject) {
    if (httpObject instanceof HttpContent) {
        HttpContent httpContent = (HttpContent) httpObject;
        ByteBuf content = httpContent.content();
        if (content.isReadable()) {
            buf.addComponent(content.retain());
            buf.writerIndex(buf.writerIndex() + content.readableBytes());
        }
    }
}
 
開發者ID:sanaehirotaka,項目名稱:logbook-kai,代碼行數:11,代碼來源:NettyProxyServer.java

示例13: encode

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
public static ByteBuf encode(ByteBufAllocator allocator, TFrame frame) {
    ByteBuf buffer = allocator.buffer(TFrame.FRAME_HEADER_LENGTH, TFrame.FRAME_HEADER_LENGTH);

    // size:2
    buffer.writeShort(frame.size + TFrame.FRAME_HEADER_LENGTH);

    // type:1
    buffer.writeByte(frame.type);

    // reserved:1
    buffer.writeZero(1);

    // id:4
    buffer.writeInt((int) frame.id);

    // reserved:8
    buffer.writeZero(8);

    // TODO: refactor
    if (frame.payload instanceof CompositeByteBuf) {
        CompositeByteBuf cbf = (CompositeByteBuf) frame.payload;
        cbf.addComponent(0, buffer);
        cbf.writerIndex(cbf.writerIndex() + TFrame.FRAME_HEADER_LENGTH);
        return cbf;
    }

    return Unpooled.wrappedBuffer(buffer, frame.payload);
}
 
開發者ID:uber,項目名稱:tchannel-java,代碼行數:29,代碼來源:TFrameCodec.java

示例14: 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

示例15: testStreamStartIsOnlyWrittenOnce

import io.netty.buffer.CompositeByteBuf; //導入方法依賴的package包/類
@Test
public void testStreamStartIsOnlyWrittenOnce() throws Exception {
    ByteBuf in = Unpooled.wrappedBuffer(new byte[] {
        'n', 'e', 't', 't', 'y'
    });

    channel.writeOutbound(in.copy());
    in.readerIndex(0); // rewind the buffer to write the same data
    channel.writeOutbound(in.copy());
    assertTrue(channel.finish());

    ByteBuf expected = Unpooled.wrappedBuffer(new byte[] {
        -0x80, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
         0x01, 0x09, 0x00, 0x00, 0x6f, -0x68, -0x7e, -0x5e, 'n', 'e', 't', 't', 'y',
         0x01, 0x09, 0x00, 0x00, 0x6f, -0x68, -0x7e, -0x5e, 'n', 'e', 't', 't', 'y',
    });

    CompositeByteBuf actual = Unpooled.compositeBuffer();
    for (;;) {
        ByteBuf m = (ByteBuf) channel.readOutbound();
        if (m == null) {
            break;
        }
        actual.addComponent(m);
        actual.writerIndex(actual.writerIndex() + m.readableBytes());
    }
    assertEquals(releaseLater(expected), releaseLater(actual));
    in.release();
}
 
開發者ID:kyle-liu,項目名稱:netty4study,代碼行數:30,代碼來源:SnappyFramedEncoderTest.java


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