io.netty.buffer.ByteBuf.ensureWritable()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(143)

本文整理了Java中io.netty.buffer.ByteBuf.ensureWritable()方法的一些代码示例,展示了ByteBuf.ensureWritable()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuf.ensureWritable()方法的具体详情如下:
包路径:io.netty.buffer.ByteBuf
类名称:ByteBuf
方法名:ensureWritable

ByteBuf.ensureWritable介绍

[英]Makes sure the number of #writableBytes()is equal to or greater than the specified value. If there is enough writable bytes in this buffer, this method returns with no side effect. Otherwise, it raises an IllegalArgumentException.
[中]确保#writableBytes()的数目等于或大于指定值。如果此缓冲区中有足够的可写字节,则此方法返回时不会产生任何副作用。否则,它将引发IllegalArgumentException。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public DataBuffer ensureCapacity(int capacity) {
  this.byteBuf.ensureWritable(capacity);
  return this;
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public void ensureWritableBytes(int writableBytes) {
  buffer.ensureWritable(writableBytes);
}

代码示例来源:origin: netty/netty

@Override
public ByteBuf ensureWritable(int writableBytes) {
  buf.ensureWritable(writableBytes);
  return this;
}

代码示例来源:origin: netty/netty

@Override
public ByteBuf ensureWritable(int minWritableBytes) {
  buf.ensureWritable(minWritableBytes);
  return this;
}

代码示例来源:origin: netty/netty

@Override
public int ensureWritable(int minWritableBytes, boolean force) {
  return buf.ensureWritable(minWritableBytes, force);
}

代码示例来源:origin: netty/netty

@Override
public int ensureWritable(int minWritableBytes, boolean force) {
  return buf.ensureWritable(minWritableBytes, force);
}

代码示例来源:origin: redisson/redisson

@Override
public ByteBuf ensureWritable(int writableBytes) {
  buf.ensureWritable(writableBytes);
  return this;
}

代码示例来源:origin: redisson/redisson

@Override
public ByteBuf ensureWritable(int minWritableBytes) {
  buf.ensureWritable(minWritableBytes);
  return this;
}

代码示例来源:origin: redisson/redisson

@Override
public int ensureWritable(int minWritableBytes, boolean force) {
  return buf.ensureWritable(minWritableBytes, force);
}

代码示例来源:origin: redisson/redisson

@Override
public int ensureWritable(int minWritableBytes, boolean force) {
  return buf.ensureWritable(minWritableBytes, force);
}

代码示例来源:origin: org.springframework/spring-core

@Override
public DataBuffer ensureCapacity(int capacity) {
  this.byteBuf.ensureWritable(capacity);
  return this;
}

代码示例来源:origin: eclipse-vertx/vert.x

private void ensureWritable(int pos, int len) {
 int ni = pos + len;
 int cap = buffer.capacity();
 int over = ni - cap;
 if (over > 0) {
  buffer.writerIndex(cap);
  buffer.ensureWritable(over);
 }
 //We have to make sure that the writerindex is always positioned on the last bit of data set in the buffer
 if (ni > buffer.writerIndex()) {
  buffer.writerIndex(ni);
 }
}

代码示例来源:origin: netty/netty

@Override
protected void encode(
    ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
  int bodyLen = msg.readableBytes();
  int headerLen = computeRawVarint32Size(bodyLen);
  out.ensureWritable(headerLen + bodyLen);
  writeRawVarint32(out, bodyLen);
  out.writeBytes(msg, msg.readerIndex(), bodyLen);
}

代码示例来源:origin: Netflix/zuul

@Override
public ChannelFuture sendPing(ChannelHandlerContext ctx) {
  final ByteBuf newBuff = ctx.alloc().buffer();
  newBuff.ensureWritable(SSE_PING.length());
  newBuff.writeCharSequence(SSE_PING, Charsets.UTF_8);
  return ctx.channel().writeAndFlush(newBuff);
}

代码示例来源:origin: Netflix/zuul

@Override
public ChannelFuture sendPushMessage(ChannelHandlerContext ctx, ByteBuf mesg) {
  final ByteBuf newBuff = ctx.alloc().buffer();
  newBuff.ensureWritable(SSE_PREAMBLE.length());
  newBuff.writeCharSequence(SSE_PREAMBLE, Charsets.UTF_8);
  newBuff.ensureWritable(mesg.writableBytes());
  newBuff.writeBytes(mesg);
  newBuff.ensureWritable(SSE_TERMINATION.length());
  newBuff.writeCharSequence(SSE_TERMINATION, Charsets.UTF_8);
  mesg.release();
  return ctx.channel().writeAndFlush(newBuff);
}

代码示例来源:origin: redisson/redisson

@Override
protected void encode(
    ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
  int bodyLen = msg.readableBytes();
  int headerLen = computeRawVarint32Size(bodyLen);
  out.ensureWritable(headerLen + bodyLen);
  writeRawVarint32(out, bodyLen);
  out.writeBytes(msg, msg.readerIndex(), bodyLen);
}

代码示例来源:origin: redisson/redisson

private static boolean attemptCopyToCumulation(ByteBuf cumulation, ByteBuf next, int wrapDataSize) {
  final int inReadableBytes = next.readableBytes();
  final int cumulationCapacity = cumulation.capacity();
  if (wrapDataSize - cumulation.readableBytes() >= inReadableBytes &&
      // Avoid using the same buffer if next's data would make cumulation exceed the wrapDataSize.
      // Only copy if there is enough space available and the capacity is large enough, and attempt to
      // resize if the capacity is small.
      (cumulation.isWritable(inReadableBytes) && cumulationCapacity >= wrapDataSize ||
          cumulationCapacity < wrapDataSize &&
              ensureWritableSuccess(cumulation.ensureWritable(inReadableBytes, false)))) {
    cumulation.writeBytes(next);
    next.release();
    return true;
  }
  return false;
}

代码示例来源:origin: eclipse-vertx/vert.x

static void encoderHeader(CharSequence name, CharSequence value, ByteBuf buf) {
 final int nameLen = name.length();
 final int valueLen = value.length();
 final int entryLen = nameLen + valueLen + 4;
 buf.ensureWritable(entryLen);
 int offset = buf.writerIndex();
 writeAscii(buf, offset, name);
 offset += nameLen;
 ByteBufUtil.setShortBE(buf, offset, COLON_AND_SPACE_SHORT);
 offset += 2;
 writeAscii(buf, offset, value);
 offset += valueLen;
 ByteBufUtil.setShortBE(buf, offset, CRLF_SHORT);
 offset += 2;
 buf.writerIndex(offset);
}

代码示例来源:origin: Netflix/zuul

@Override
public ChannelFuture sendPushMessage(ChannelHandlerContext ctx, ByteBuf mesg) {
  final ByteBuf newBuff = ctx.alloc().buffer();
  newBuff.ensureWritable(SSE_PREAMBLE.length());
  newBuff.writeCharSequence(SSE_PREAMBLE, Charsets.UTF_8);
  newBuff.ensureWritable(mesg.writableBytes());
  newBuff.writeBytes(mesg);
  newBuff.ensureWritable(SSE_TERMINATION.length());
  newBuff.writeCharSequence(SSE_TERMINATION, Charsets.UTF_8);
  mesg.release();
  return ctx.channel().writeAndFlush(newBuff);
}

代码示例来源:origin: Netflix/zuul

@Override
public ChannelFuture sendPing(ChannelHandlerContext ctx) {
  final ByteBuf newBuff = ctx.alloc().buffer();
  newBuff.ensureWritable(SSE_PING.length());
  newBuff.writeCharSequence(SSE_PING, Charsets.UTF_8);
  return ctx.channel().writeAndFlush(newBuff);
}

相关文章

ByteBuf类方法