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

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

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

ByteBuf.clear介绍

[英]Sets the readerIndex and writerIndex of this buffer to 0. This method is identical to #setIndex(int,int).

Please note that the behavior of this method is different from that of NIO buffer, which sets the limit to the capacity of the buffer.
[中]将此缓冲区的readerIndex和writerIndex设置为0。此方法与#setIndex(int,int)相同。
请注意,此方法的行为与NIO buffer不同,后者设置了缓冲区容量的限制。

代码示例

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

@Override
public void clear() {
  buffer.clear();
}

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

@Override
public ByteBuf clear() {
  buf.clear();
  return this;
}

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

@Override
public final ByteBuf clear() {
  buf.clear();
  return this;
}

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

@Override
public final ByteBuf clear() {
  buf.clear();
  return this;
}

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

@Override
public ByteBuf clear() {
  buf.clear();
  return this;
}

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

@Override
public void handlerAdded(ChannelHandlerContext ctx) {
  this.ctx = ctx;
  // Ensure we use a heap based ByteBuf.
  buffer = Unpooled.wrappedBuffer(new byte[blockSize]);
  buffer.clear();
}

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

@Override
public ByteBuf clear() {
  buf.clear();
  return this;
}

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

@Override
public final ByteBuf clear() {
  buf.clear();
  return this;
}

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

@Override
public void clear() {
 buffer.clear();
}

代码示例来源:origin: micronaut-projects/micronaut-core

@Override
public final ByteBuf clear() {
  byteBuf.clear();
  return this;
}

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

@Override
public void handlerAdded(ChannelHandlerContext ctx) {
  this.ctx = ctx;
  // Ensure we use a heap based ByteBuf.
  buffer = Unpooled.wrappedBuffer(new byte[blockSize]);
  buffer.clear();
}

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

@Override
public void handlerAdded(ChannelHandlerContext ctx) {
  this.ctx = ctx;
  // Ensure we use a heap based ByteBuf.
  buffer = Unpooled.wrappedBuffer(new byte[blockSize]);
  buffer.clear();
}

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

@Override
public ByteBuf buffer() {
 buf.clear();
 return buf;
}

代码示例来源:origin: apache/hive

private void writeToChannel() throws IOException {
 if (closed) {
  throw new IOException("Already closed: " + id);
 }
 takeWriteResources(1);
 chc.writeAndFlush(buf.copy()).addListener(writeListener);
 buf.clear();
}

代码示例来源:origin: apache/drill

private void writeToChannel() throws IOException {
 if (closed) {
  throw new IOException("Already closed: " + id);
 }
 // Wait if we have exceeded our max pending write count
 waitForWritesToFinish(maxPendingWrites - 1);
 pendingWrites++;
 chc.writeAndFlush(buf.copy()).addListener(writeListener);
 buf.clear();
}

代码示例来源:origin: lettuce-io/lettuce-core

private void resetInternals() {
  rsm.reset();
  if (buffer.refCnt() > 0) {
    buffer.clear();
  }
}

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

@Override
public void clear() {
 changed();
 buffer.clear();
 buffer.setIndex(limit, limit);
}

代码示例来源:origin: AsyncHttpClient/async-http-client

private static long transferWithCopy(MultipartBody multipartBody, int bufferSize) throws IOException {
 long transferred = 0;
 final ByteBuf buffer = Unpooled.buffer(bufferSize);
 try {
  while (multipartBody.transferTo(buffer) != BodyState.STOP) {
   transferred += buffer.readableBytes();
   buffer.clear();
  }
  return transferred;
 } finally {
  buffer.release();
 }
}

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

out.setIntLE(idx + CHECKSUM_OFFSET, check);
out.writerIndex(idx + HEADER_LENGTH + compressedLength);
buffer.clear();

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test
public void testSingleRead() throws IOException {
 final int srcArraySize = chunkSize - 1;
 final byte[] srcArray = new byte[srcArraySize];
 random.nextBytes(srcArray);
 final ByteArrayBodyGenerator babGen = new ByteArrayBodyGenerator(srcArray);
 final Body body = babGen.createBody();
 final ByteBuf chunkBuffer = Unpooled.buffer(chunkSize);
 try {
  // should take 1 read to get through the srcArray
  body.transferTo(chunkBuffer);
  assertEquals(chunkBuffer.readableBytes(), srcArraySize, "bytes read");
  chunkBuffer.clear();
  assertEquals(body.transferTo(chunkBuffer), BodyState.STOP, "body at EOF");
 } finally {
  chunkBuffer.release();
 }
}

相关文章

ByteBuf类方法