当前位置: 首页>>代码示例>>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;未经允许,请勿转载。