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


Java ByteBuf.ensureWritable方法代碼示例

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


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

示例1: encode

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

	if (!(msg instanceof ByteBuf)) return;
	ByteBuf in = (ByteBuf) msg;

	int readableBytes = in.readableBytes();
	int lengthByteSpace = getVarIntSize(readableBytes);

	if (lengthByteSpace > 3)
	{
		throw new IllegalArgumentException();
	}

	out.ensureWritable(lengthByteSpace + readableBytes);
	writeVarInt(readableBytes, out);
	out.writeBytes(in, in.readerIndex(), readableBytes);
}
 
開發者ID:Dytanic,項目名稱:CloudNet,代碼行數:19,代碼來源:ProtocolLengthSerializer.java

示例2: getDino

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
private static FullHttpResponse getDino(XrpcRequest request, List<Dino> dinos) {
  try {
    DinoGetRequest getRequest =
        DinoGetRequest.parseFrom(CodedInputStream.newInstance(request.getData().nioBuffer()));
    Optional<Dino> dinoOptional =
        dinos.stream().filter(xs -> xs.getName().equals(getRequest.getName())).findFirst();

    if (dinoOptional.isPresent()) {
      DinoGetReply getReply = DinoGetReply.newBuilder().setDino(dinoOptional.get()).build();
      ByteBuf resp = request.getByteBuf();
      resp.ensureWritable(CodedOutputStream.computeMessageSizeNoTag(getReply), true);
      getReply.writeTo(new ByteBufOutputStream(resp));

      return Recipes.newResponse(
          HttpResponseStatus.OK,
          request.getByteBuf().writeBytes(resp),
          Recipes.ContentType.Application_Octet_Stream);
    }

  } catch (IOException e) {
    return Recipes.newResponseBadRequest("Malformed GetDino Request: " + e.getMessage());
  }

  return Recipes.newResponseOk("Dino not Found");
}
 
開發者ID:Nordstrom,項目名稱:xrpc,代碼行數:26,代碼來源:Example.java

示例3: handleIFormat

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
private void handleIFormat ( final InformationTransfer msg, ByteBuf out )
{
    final ByteBuf data = msg.getData ();
    try
    {
        out = out.order ( ByteOrder.LITTLE_ENDIAN );

        final int len = data.readableBytes ();

        if ( len > Constants.APCI_MAX_DATA_LENGTH )
        {
            throw new EncoderException ( String.format ( "Packet too big - %s bytes", len ) );
        }

        out.ensureWritable ( 6 + len );
        out.writeByte ( Constants.START_BYTE );
        out.writeByte ( 4 + len );
        out.writeShort ( msg.getSendSequenceNumber () << 1 );
        out.writeShort ( msg.getReceiveSequenceNumber () << 1 );
        out.writeBytes ( data );
    }
    finally
    {
        ReferenceCountUtil.release ( msg.getData () );
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:27,代碼來源:APDUEncoder.java

示例4: encode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception
{
	int i = msg.readableBytes();
	int j = getVarIntSize(i);

	if (j > 3)
	{
		throw new IllegalArgumentException("unable to compress varint of " + i + " bytes into maximum 3 bytes");
	}
	else
	{
		out.ensureWritable(j + i);
		writeVarInt(i, out);
		out.writeBytes(msg, msg.readerIndex(), i);
	}
}
 
開發者ID:andykuo1,項目名稱:candlelight,代碼行數:18,代碼來源:VarInt21FrameEncoder.java

示例5: encode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void encode(
        ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
    int bodyLen = msg.readableBytes();
    int headerLen = CodedOutputStream.computeRawVarint32Size(bodyLen);
    out.ensureWritable(headerLen + bodyLen);

    CodedOutputStream headerOut =
            CodedOutputStream.newInstance(new ByteBufOutputStream(out), headerLen);
    headerOut.writeRawVarint32(bodyLen);
    headerOut.flush();

    out.writeBytes(msg, msg.readerIndex(), bodyLen);
}
 
開發者ID:ninelook,項目名稱:wecard-server,代碼行數:15,代碼來源:ProtobufVarint32LengthFieldPrepender.java

示例6: handleSFormat

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
private void handleSFormat ( final Supervisory msg, ByteBuf out )
{
    out = out.order ( ByteOrder.LITTLE_ENDIAN );

    out.ensureWritable ( 6 );
    out.writeByte ( Constants.START_BYTE );
    out.writeByte ( 4 );
    out.writeBytes ( new byte[] { 0x01, 0x00 } );
    out.writeShort ( msg.getReceiveSequenceNumber () << 1 );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:11,代碼來源:APDUEncoder.java

示例7: handleUFormat

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
private void handleUFormat ( final UnnumberedControl msg, final ByteBuf out )
{
    out.ensureWritable ( 6 );
    out.writeByte ( Constants.START_BYTE );
    out.writeByte ( 4 );
    out.writeByte ( msg.getFunction ().getNumericValue () | 0x03 /* bits 1 and 2*/);
    out.writeZero ( 3 );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:9,代碼來源:APDUEncoder.java

示例8: encode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
protected void encode(ChannelHandlerContext paramChannelHandlerContext, ByteBuf paramByteBuf1, ByteBuf paramByteBuf2)
        throws Exception {
    int i = paramByteBuf1.readableBytes();
    int j = CodedOutputStream.computeRawVarint32Size(i);
    paramByteBuf2.ensureWritable(j + i);

    CodedOutputStream localCodedOutputStream = CodedOutputStream.newInstance(new ByteBufOutputStream(paramByteBuf2), j);

    localCodedOutputStream.writeRawVarint32(i);
    localCodedOutputStream.flush();

    paramByteBuf2.writeBytes(paramByteBuf1, paramByteBuf1.readerIndex(), i);
}
 
開發者ID:Superioz,項目名稱:MooProject,代碼行數:14,代碼來源:Varint32LengthFieldPrepender.java

示例9: encode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
protected void encode(ChannelHandlerContext paramChannelHandlerContext, ByteBuf paramByteBuf1, ByteBuf paramByteBuf2)
        throws Exception {
    int i = paramByteBuf1.readableBytes();
    int j = CodedOutputStream.computeRawVarint32Size(i);
    paramByteBuf2.ensureWritable(j + i);

    CodedOutputStream localCodedOutputStream = CodedOutputStream.newInstance(new ByteBufOutputStream(paramByteBuf2), j);

    localCodedOutputStream.writeRawVarint32(i);
    localCodedOutputStream.flush();

    paramByteBuf2.writeBytes(paramByteBuf1, paramByteBuf1.readerIndex(), i);
    paramByteBuf2.release();
}
 
開發者ID:Superioz,項目名稱:MooProject,代碼行數:15,代碼來源:ProtobufVarint32LengthFieldPrepender.java

示例10: encode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void encode( ChannelHandlerContext channelHandlerContext, ByteBuf a, ByteBuf byteBuf ) throws Exception {
    int i = a.readableBytes();
    int j = Message.getVarIntSize( i );
    if ( j > 3 ) {
        throw new IllegalArgumentException( "unable to fit " + i + " into " + 3 );
    }

    byteBuf.ensureWritable( j + i );
    Message.writeVarInt( i, byteBuf );
    byteBuf.writeBytes( a, a.readerIndex(), i );
}
 
開發者ID:lukas81298,項目名稱:FlexMC,代碼行數:13,代碼來源:MessagePrepender.java


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