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

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

本文整理了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

  1. @Override
  2. public ByteBuf ensureWritable(int writableBytes) {
  3. buf.ensureWritable(writableBytes);
  4. return this;
  5. }

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

  1. @Override
  2. public ByteBuf ensureWritable(int minWritableBytes) {
  3. buf.ensureWritable(minWritableBytes);
  4. return this;
  5. }

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

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

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

  1. @Override
  2. public ByteBuf ensureWritable(int writableBytes) {
  3. buf.ensureWritable(writableBytes);
  4. return this;
  5. }

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

  1. @Override
  2. public ByteBuf ensureWritable(int minWritableBytes) {
  3. buf.ensureWritable(minWritableBytes);
  4. return this;
  5. }

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

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

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

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

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

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

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

  1. private void ensureBuffer(ByteBufAllocator alloc) {
  2. if (decompressed == null) {
  3. decompressed = alloc.heapBuffer(DEFAULT_BUFFER_CAPACITY);
  4. }
  5. decompressed.ensureWritable(1);
  6. }

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

  1. private void ensureBuffer(ByteBufAllocator alloc) {
  2. if (decompressed == null) {
  3. decompressed = alloc.heapBuffer(DEFAULT_BUFFER_CAPACITY);
  4. }
  5. decompressed.ensureWritable(1);
  6. }

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

  1. /**
  2. * Encode a {@link CharSequence} in <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a> and write
  3. * it to a {@link ByteBuf}.
  4. *
  5. * This method returns the actual number of bytes written.
  6. */
  7. public static int writeUtf8(ByteBuf buf, CharSequence seq) {
  8. final int len = seq.length();
  9. buf.ensureWritable(len * MAX_BYTES_PER_CHAR_UTF8);
  10. for (;;) {
  11. if (buf instanceof AbstractByteBuf) {
  12. return writeUtf8((AbstractByteBuf) buf, seq, len);
  13. } else if (buf instanceof WrappedByteBuf) {
  14. // Unwrap as the wrapped buffer may be an AbstractByteBuf and so we can use fast-path.
  15. buf = buf.unwrap();
  16. } else {
  17. byte[] bytes = seq.toString().getBytes(CharsetUtil.UTF_8);
  18. buf.writeBytes(bytes);
  19. return bytes.length;
  20. }
  21. }
  22. }

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

  1. /**
  2. * Encode a {@link CharSequence} in <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a> and write
  3. * it to a {@link ByteBuf}.
  4. *
  5. * This method returns the actual number of bytes written.
  6. */
  7. public static int writeUtf8(ByteBuf buf, CharSequence seq) {
  8. final int len = seq.length();
  9. buf.ensureWritable(len * MAX_BYTES_PER_CHAR_UTF8);
  10. for (;;) {
  11. if (buf instanceof AbstractByteBuf) {
  12. return writeUtf8((AbstractByteBuf) buf, seq, len);
  13. } else if (buf instanceof WrappedByteBuf) {
  14. // Unwrap as the wrapped buffer may be an AbstractByteBuf and so we can use fast-path.
  15. buf = buf.unwrap();
  16. } else {
  17. byte[] bytes = seq.toString().getBytes(CharsetUtil.UTF_8);
  18. buf.writeBytes(bytes);
  19. return bytes.length;
  20. }
  21. }
  22. }

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

  1. /**
  2. * Encode a {@link CharSequence} in <a href="http://en.wikipedia.org/wiki/ASCII">ASCII</a> and write it
  3. * to a {@link ByteBuf}.
  4. *
  5. * This method returns the actual number of bytes written.
  6. */
  7. public static int writeAscii(ByteBuf buf, CharSequence seq) {
  8. // ASCII uses 1 byte per char
  9. final int len = seq.length();
  10. buf.ensureWritable(len);
  11. for (;;) {
  12. if (buf instanceof AbstractByteBuf) {
  13. writeAscii((AbstractByteBuf) buf, seq, len);
  14. break;
  15. } else if (buf instanceof WrappedByteBuf) {
  16. // Unwrap as the wrapped buffer may be an AbstractByteBuf and so we can use fast-path.
  17. buf = buf.unwrap();
  18. } else {
  19. byte[] bytes = seq.toString().getBytes(CharsetUtil.US_ASCII);
  20. buf.writeBytes(bytes);
  21. return bytes.length;
  22. }
  23. }
  24. return len;
  25. }

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

  1. /**
  2. * Encode a {@link CharSequence} in <a href="http://en.wikipedia.org/wiki/ASCII">ASCII</a> and write it
  3. * to a {@link ByteBuf}.
  4. *
  5. * This method returns the actual number of bytes written.
  6. */
  7. public static int writeAscii(ByteBuf buf, CharSequence seq) {
  8. // ASCII uses 1 byte per char
  9. final int len = seq.length();
  10. buf.ensureWritable(len);
  11. for (;;) {
  12. if (buf instanceof AbstractByteBuf) {
  13. writeAscii((AbstractByteBuf) buf, seq, len);
  14. break;
  15. } else if (buf instanceof WrappedByteBuf) {
  16. // Unwrap as the wrapped buffer may be an AbstractByteBuf and so we can use fast-path.
  17. buf = buf.unwrap();
  18. } else {
  19. byte[] bytes = seq.toString().getBytes(CharsetUtil.US_ASCII);
  20. buf.writeBytes(bytes);
  21. return bytes.length;
  22. }
  23. }
  24. return len;
  25. }

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

  1. private ByteBuf encode(ByteBufAllocator alloc, int len) {
  2. ByteBuf compressed = alloc.heapBuffer(len);
  3. boolean release = true;
  4. try {
  5. while (compressInto(compressed)) {
  6. // Although unlikely, it's possible that the compressed size is larger than the decompressed size
  7. compressed.ensureWritable(compressed.capacity() << 1);
  8. }
  9. release = false;
  10. return compressed;
  11. } finally {
  12. if (release) {
  13. compressed.release();
  14. }
  15. }
  16. }

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

  1. private ByteBuf encode(ByteBufAllocator alloc, int len) {
  2. ByteBuf compressed = alloc.heapBuffer(len);
  3. boolean release = true;
  4. try {
  5. while (compressInto(compressed)) {
  6. // Although unlikely, it's possible that the compressed size is larger than the decompressed size
  7. compressed.ensureWritable(compressed.capacity() << 1);
  8. }
  9. release = false;
  10. return compressed;
  11. } finally {
  12. if (release) {
  13. compressed.release();
  14. }
  15. }
  16. }

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

  1. @Override
  2. protected void encode(
  3. ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
  4. int bodyLen = msg.readableBytes();
  5. int headerLen = CodedOutputStream.computeRawVarint32Size(bodyLen);
  6. out.ensureWritable(headerLen + bodyLen);
  7. CodedOutputStream headerOut =
  8. CodedOutputStream.newInstance(new ByteBufOutputStream(out), headerLen);
  9. headerOut.writeRawVarint32(bodyLen);
  10. headerOut.flush();
  11. out.writeBytes(msg, msg.readerIndex(), bodyLen);
  12. }
  13. }

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

  1. @Override
  2. protected void encode(
  3. ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
  4. int bodyLen = msg.readableBytes();
  5. int headerLen = CodedOutputStream.computeRawVarint32Size(bodyLen);
  6. out.ensureWritable(headerLen + bodyLen);
  7. CodedOutputStream headerOut =
  8. CodedOutputStream.newInstance(new ByteBufOutputStream(out), headerLen);
  9. headerOut.writeRawVarint32(bodyLen);
  10. headerOut.flush();
  11. out.writeBytes(msg, msg.readerIndex(), bodyLen);
  12. }
  13. }

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

  1. /**
  2. * Sets the content payload of the buffer, updating the content length as well.
  3. */
  4. public static void setContent(ByteBuf content, ByteBuf buffer) {
  5. short keyLength = buffer.getShort(KEY_LENGTH_OFFSET);
  6. byte extrasLength = buffer.getByte(EXTRAS_LENGTH_OFFSET);
  7. int bodyLength = keyLength + extrasLength + content.readableBytes();
  8. int contentOffset = HEADER_SIZE + extrasLength + keyLength;
  9. buffer.setInt(BODY_LENGTH_OFFSET, bodyLength);
  10. buffer.writerIndex(contentOffset);
  11. buffer.ensureWritable(content.readableBytes());
  12. buffer.writeBytes(content);
  13. buffer.writerIndex(HEADER_SIZE + bodyLength);
  14. }

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

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

相关文章