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

x33g5p2x  于2022-01-17 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(169)

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

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

代码示例来源:origin: couchbase/couchbase-jvm-core

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

代码示例来源:origin: com.couchbase.client/core-io

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

代码示例来源:origin: com.couchbase.client/core-io

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

代码示例来源:origin: com.couchbase.client/core-io

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

代码示例来源:origin: com.couchbase.client/core-io

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

代码示例来源:origin: couchbase/couchbase-jvm-core

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

代码示例来源:origin: couchbase/couchbase-jvm-core

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

代码示例来源:origin: com.couchbase.client/core-io

private void ensureBuffer(ByteBufAllocator alloc) {
  if (decompressed == null) {
    decompressed = alloc.heapBuffer(DEFAULT_BUFFER_CAPACITY);
  }
  decompressed.ensureWritable(1);
}

代码示例来源:origin: couchbase/couchbase-jvm-core

private void ensureBuffer(ByteBufAllocator alloc) {
  if (decompressed == null) {
    decompressed = alloc.heapBuffer(DEFAULT_BUFFER_CAPACITY);
  }
  decompressed.ensureWritable(1);
}

代码示例来源:origin: couchbase/couchbase-jvm-core

/**
 * Encode a {@link CharSequence} in <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a> and write
 * it to a {@link ByteBuf}.
 *
 * This method returns the actual number of bytes written.
 */
public static int writeUtf8(ByteBuf buf, CharSequence seq) {
  final int len = seq.length();
  buf.ensureWritable(len * MAX_BYTES_PER_CHAR_UTF8);
  for (;;) {
    if (buf instanceof AbstractByteBuf) {
      return writeUtf8((AbstractByteBuf) buf, seq, len);
    } else if (buf instanceof WrappedByteBuf) {
      // Unwrap as the wrapped buffer may be an AbstractByteBuf and so we can use fast-path.
      buf = buf.unwrap();
    } else {
      byte[] bytes = seq.toString().getBytes(CharsetUtil.UTF_8);
      buf.writeBytes(bytes);
      return bytes.length;
    }
  }
}

代码示例来源:origin: com.couchbase.client/core-io

/**
 * Encode a {@link CharSequence} in <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a> and write
 * it to a {@link ByteBuf}.
 *
 * This method returns the actual number of bytes written.
 */
public static int writeUtf8(ByteBuf buf, CharSequence seq) {
  final int len = seq.length();
  buf.ensureWritable(len * MAX_BYTES_PER_CHAR_UTF8);
  for (;;) {
    if (buf instanceof AbstractByteBuf) {
      return writeUtf8((AbstractByteBuf) buf, seq, len);
    } else if (buf instanceof WrappedByteBuf) {
      // Unwrap as the wrapped buffer may be an AbstractByteBuf and so we can use fast-path.
      buf = buf.unwrap();
    } else {
      byte[] bytes = seq.toString().getBytes(CharsetUtil.UTF_8);
      buf.writeBytes(bytes);
      return bytes.length;
    }
  }
}

代码示例来源:origin: couchbase/couchbase-jvm-core

/**
 * Encode a {@link CharSequence} in <a href="http://en.wikipedia.org/wiki/ASCII">ASCII</a> and write it
 * to a {@link ByteBuf}.
 *
 * This method returns the actual number of bytes written.
 */
public static int writeAscii(ByteBuf buf, CharSequence seq) {
  // ASCII uses 1 byte per char
  final int len = seq.length();
  buf.ensureWritable(len);
  for (;;) {
    if (buf instanceof AbstractByteBuf) {
      writeAscii((AbstractByteBuf) buf, seq, len);
      break;
    } else if (buf instanceof WrappedByteBuf) {
      // Unwrap as the wrapped buffer may be an AbstractByteBuf and so we can use fast-path.
      buf = buf.unwrap();
    } else {
      byte[] bytes = seq.toString().getBytes(CharsetUtil.US_ASCII);
      buf.writeBytes(bytes);
      return bytes.length;
    }
  }
  return len;
}

代码示例来源:origin: com.couchbase.client/core-io

/**
 * Encode a {@link CharSequence} in <a href="http://en.wikipedia.org/wiki/ASCII">ASCII</a> and write it
 * to a {@link ByteBuf}.
 *
 * This method returns the actual number of bytes written.
 */
public static int writeAscii(ByteBuf buf, CharSequence seq) {
  // ASCII uses 1 byte per char
  final int len = seq.length();
  buf.ensureWritable(len);
  for (;;) {
    if (buf instanceof AbstractByteBuf) {
      writeAscii((AbstractByteBuf) buf, seq, len);
      break;
    } else if (buf instanceof WrappedByteBuf) {
      // Unwrap as the wrapped buffer may be an AbstractByteBuf and so we can use fast-path.
      buf = buf.unwrap();
    } else {
      byte[] bytes = seq.toString().getBytes(CharsetUtil.US_ASCII);
      buf.writeBytes(bytes);
      return bytes.length;
    }
  }
  return len;
}

代码示例来源:origin: com.couchbase.client/core-io

private ByteBuf encode(ByteBufAllocator alloc, int len) {
  ByteBuf compressed = alloc.heapBuffer(len);
  boolean release = true;
  try {
    while (compressInto(compressed)) {
      // Although unlikely, it's possible that the compressed size is larger than the decompressed size
      compressed.ensureWritable(compressed.capacity() << 1);
    }
    release = false;
    return compressed;
  } finally {
    if (release) {
      compressed.release();
    }
  }
}

代码示例来源:origin: couchbase/couchbase-jvm-core

private ByteBuf encode(ByteBufAllocator alloc, int len) {
  ByteBuf compressed = alloc.heapBuffer(len);
  boolean release = true;
  try {
    while (compressInto(compressed)) {
      // Although unlikely, it's possible that the compressed size is larger than the decompressed size
      compressed.ensureWritable(compressed.capacity() << 1);
    }
    release = false;
    return compressed;
  } finally {
    if (release) {
      compressed.release();
    }
  }
}

代码示例来源:origin: couchbase/couchbase-jvm-core

@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);
  }
}

代码示例来源:origin: com.couchbase.client/core-io

@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);
  }
}

代码示例来源:origin: couchbase/java-dcp-client

/**
 * Sets the content payload of the buffer, updating the content length as well.
 */
public static void setContent(ByteBuf content, ByteBuf buffer) {
  short keyLength = buffer.getShort(KEY_LENGTH_OFFSET);
  byte extrasLength = buffer.getByte(EXTRAS_LENGTH_OFFSET);
  int bodyLength = keyLength + extrasLength + content.readableBytes();
  int contentOffset = HEADER_SIZE + extrasLength + keyLength;
  buffer.setInt(BODY_LENGTH_OFFSET, bodyLength);
  buffer.writerIndex(contentOffset);
  buffer.ensureWritable(content.readableBytes());
  buffer.writeBytes(content);
  buffer.writerIndex(HEADER_SIZE + bodyLength);
}

代码示例来源:origin: com.couchbase.client/core-io

out.ensureWritable(engine.getSession().getPacketBufferSize());
  break;
default:

相关文章