本文整理汇总了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);
}
示例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");
}
示例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 () );
}
}
示例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);
}
}
示例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);
}
示例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 );
}
示例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 );
}
示例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);
}
示例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();
}
示例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 );
}