Home / Class/ ByteBufUtil Class — netty Architecture

ByteBufUtil Class — netty Architecture

Architecture documentation for the ByteBufUtil class in ByteBufUtil.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  920454f6_25f6_4a9b_3d32_9684c3e11f6c["ByteBufUtil"]
  373e0ae1_9ed6_8f3b_aa9e_665e0d7416be["ByteBufUtil.java"]
  920454f6_25f6_4a9b_3d32_9684c3e11f6c -->|defined in| 373e0ae1_9ed6_8f3b_aa9e_665e0d7416be
  5aa64bba_7190_3430_6812_affa2bbfb849["threadLocalTempArray()"]
  920454f6_25f6_4a9b_3d32_9684c3e11f6c -->|method| 5aa64bba_7190_3430_6812_affa2bbfb849
  05d2db6a_ade4_e23b_5f83_d0e2cb79978d["isAccessible()"]
  920454f6_25f6_4a9b_3d32_9684c3e11f6c -->|method| 05d2db6a_ade4_e23b_5f83_d0e2cb79978d
  a25efb62_fa62_08c5_238f_d23c15a3569b["ByteBuf()"]
  920454f6_25f6_4a9b_3d32_9684c3e11f6c -->|method| a25efb62_fa62_08c5_238f_d23c15a3569b
  96cdf8e2_4e5f_72af_07c1_cc29b6248734["String()"]
  920454f6_25f6_4a9b_3d32_9684c3e11f6c -->|method| 96cdf8e2_4e5f_72af_07c1_cc29b6248734
  c1784e2a_c84e_371d_bc9a_1f64fbaef952["decodeHexByte()"]
  920454f6_25f6_4a9b_3d32_9684c3e11f6c -->|method| c1784e2a_c84e_371d_bc9a_1f64fbaef952
  02b2d761_be1b_b104_f9b8_bb3d233d01d4["decodeHexDump()"]
  920454f6_25f6_4a9b_3d32_9684c3e11f6c -->|method| 02b2d761_be1b_b104_f9b8_bb3d233d01d4
  602fdeb8_46f6_f44c_ca1a_ff6311d79663["ensureWritableSuccess()"]
  920454f6_25f6_4a9b_3d32_9684c3e11f6c -->|method| 602fdeb8_46f6_f44c_ca1a_ff6311d79663
  9cc4e575_38a7_bd57_0694_10c13faacf9f["hashCode()"]
  920454f6_25f6_4a9b_3d32_9684c3e11f6c -->|method| 9cc4e575_38a7_bd57_0694_10c13faacf9f
  01cd6f08_cabc_df56_318f_9666e83f47c5["indexOf()"]
  920454f6_25f6_4a9b_3d32_9684c3e11f6c -->|method| 01cd6f08_cabc_df56_318f_9666e83f47c5
  f163dca2_b01f_aece_57c8_a62f9d5a9b40["maxSuf()"]
  920454f6_25f6_4a9b_3d32_9684c3e11f6c -->|method| f163dca2_b01f_aece_57c8_a62f9d5a9b40
  c05c9b3e_b2a3_295c_5eb2_a427df9e1f52["equals()"]
  920454f6_25f6_4a9b_3d32_9684c3e11f6c -->|method| c05c9b3e_b2a3_295c_5eb2_a427df9e1f52
  6be7b2df_f943_8703_84b5_3a297dd217a5["compare()"]
  920454f6_25f6_4a9b_3d32_9684c3e11f6c -->|method| 6be7b2df_f943_8703_84b5_3a297dd217a5
  c4fcbc6c_e8c2_cce9_72e3_3385d517bd59["compareUintBigEndian()"]
  920454f6_25f6_4a9b_3d32_9684c3e11f6c -->|method| c4fcbc6c_e8c2_cce9_72e3_3385d517bd59

Relationship Graph

Source Code

buffer/src/main/java/io/netty/buffer/ByteBufUtil.java lines 59–2014

public final class ByteBufUtil {

    private static final InternalLogger logger = InternalLoggerFactory.getInstance(ByteBufUtil.class);
    private static final FastThreadLocal<byte[]> BYTE_ARRAYS = new FastThreadLocal<byte[]>() {
        @Override
        protected byte[] initialValue() throws Exception {
            return PlatformDependent.allocateUninitializedArray(MAX_TL_ARRAY_LEN);
        }
    };

    private static final byte WRITE_UTF_UNKNOWN = (byte) '?';
    private static final int MAX_CHAR_BUFFER_SIZE;
    private static final int THREAD_LOCAL_BUFFER_SIZE;
    private static final int MAX_BYTES_PER_CHAR_UTF8 =
            (int) CharsetUtil.encoder(CharsetUtil.UTF_8).maxBytesPerChar();

    static final int WRITE_CHUNK_SIZE = 8192;
    static final ByteBufAllocator DEFAULT_ALLOCATOR;

    static {
        String allocType = SystemPropertyUtil.get(
                "io.netty.allocator.type", "adaptive");

        ByteBufAllocator alloc;
        if ("unpooled".equals(allocType)) {
            alloc = UnpooledByteBufAllocator.DEFAULT;
            logger.debug("-Dio.netty.allocator.type: {}", allocType);
        } else if ("pooled".equals(allocType)) {
            alloc = PooledByteBufAllocator.DEFAULT;
            logger.debug("-Dio.netty.allocator.type: {}", allocType);
        } else if ("adaptive".equals(allocType)) {
            alloc = new AdaptiveByteBufAllocator();
            logger.debug("-Dio.netty.allocator.type: {}", allocType);
        } else {
            alloc = PooledByteBufAllocator.DEFAULT;
            logger.debug("-Dio.netty.allocator.type: pooled (unknown: {})", allocType);
        }

        DEFAULT_ALLOCATOR = alloc;

        THREAD_LOCAL_BUFFER_SIZE = SystemPropertyUtil.getInt("io.netty.threadLocalDirectBufferSize", 0);
        logger.debug("-Dio.netty.threadLocalDirectBufferSize: {}", THREAD_LOCAL_BUFFER_SIZE);

        MAX_CHAR_BUFFER_SIZE = SystemPropertyUtil.getInt("io.netty.maxThreadLocalCharBufferSize", 16 * 1024);
        logger.debug("-Dio.netty.maxThreadLocalCharBufferSize: {}", MAX_CHAR_BUFFER_SIZE);
    }

    static final int MAX_TL_ARRAY_LEN = 1024;

    /**
     * Allocates a new array if minLength > {@link ByteBufUtil#MAX_TL_ARRAY_LEN}
     */
    static byte[] threadLocalTempArray(int minLength) {
        // Only make use of ThreadLocal if we use a FastThreadLocalThread to make the implementation
        // Virtual Thread friendly.
        // See https://github.com/netty/netty/issues/14609
        if (minLength <= MAX_TL_ARRAY_LEN && FastThreadLocalThread.currentThreadHasFastThreadLocal()) {
            return BYTE_ARRAYS.get();
        }
        return PlatformDependent.allocateUninitializedArray(minLength);
    }

    /**
     * @return whether the specified buffer has a nonzero ref count
     */
    public static boolean isAccessible(ByteBuf buffer) {
        return buffer.isAccessible();
    }

    /**
     * @throws IllegalReferenceCountException if the buffer has a zero ref count
     * @return the passed in buffer
     */
    public static ByteBuf ensureAccessible(ByteBuf buffer) {
        if (!buffer.isAccessible()) {
            throw new IllegalReferenceCountException(buffer.refCnt());
        }
        return buffer;
    }

    /**

Frequently Asked Questions

What is the ByteBufUtil class?
ByteBufUtil is a class in the netty codebase, defined in buffer/src/main/java/io/netty/buffer/ByteBufUtil.java.
Where is ByteBufUtil defined?
ByteBufUtil is defined in buffer/src/main/java/io/netty/buffer/ByteBufUtil.java at line 59.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free