Home / Class/ UnpooledDirectByteBuf Class — netty Architecture

UnpooledDirectByteBuf Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  9d6a7cd0_08a5_9155_3c10_b8a8fd6480e9["UnpooledDirectByteBuf"]
  d1f272cd_eff2_5324_298a_1988358426bf["UnpooledDirectByteBuf.java"]
  9d6a7cd0_08a5_9155_3c10_b8a8fd6480e9 -->|defined in| d1f272cd_eff2_5324_298a_1988358426bf
  92cb24e9_4705_60e3_ce33_766c568a1b37["UnpooledDirectByteBuf()"]
  9d6a7cd0_08a5_9155_3c10_b8a8fd6480e9 -->|method| 92cb24e9_4705_60e3_ce33_766c568a1b37
  21dba079_ef36_3b91_3f2a_6023192827de["ByteBuffer()"]
  9d6a7cd0_08a5_9155_3c10_b8a8fd6480e9 -->|method| 21dba079_ef36_3b91_3f2a_6023192827de
  ddfc072c_30c5_a321_aeaa_45191a292e14["freeDirect()"]
  9d6a7cd0_08a5_9155_3c10_b8a8fd6480e9 -->|method| ddfc072c_30c5_a321_aeaa_45191a292e14
  5f47200f_55b7_e627_bcb2_668c429f68a9["CleanableDirectBuffer()"]
  9d6a7cd0_08a5_9155_3c10_b8a8fd6480e9 -->|method| 5f47200f_55b7_e627_bcb2_668c429f68a9
  f0d503c9_f91b_cb88_9a7f_93dd2f6f04ac["setByteBuffer()"]
  9d6a7cd0_08a5_9155_3c10_b8a8fd6480e9 -->|method| f0d503c9_f91b_cb88_9a7f_93dd2f6f04ac
  c84504bb_e9ee_6008_445c_268d5561caaf["isDirect()"]
  9d6a7cd0_08a5_9155_3c10_b8a8fd6480e9 -->|method| c84504bb_e9ee_6008_445c_268d5561caaf
  af6b5fb6_9d9a_e5e0_9d6b_fec430cad59e["capacity()"]
  9d6a7cd0_08a5_9155_3c10_b8a8fd6480e9 -->|method| af6b5fb6_9d9a_e5e0_9d6b_fec430cad59e
  9227405f_42f2_925d_5a57_145999e5270e["ByteBuf()"]
  9d6a7cd0_08a5_9155_3c10_b8a8fd6480e9 -->|method| 9227405f_42f2_925d_5a57_145999e5270e
  9fed1b55_803a_6dd5_499c_2c4f80956f99["ByteBufAllocator()"]
  9d6a7cd0_08a5_9155_3c10_b8a8fd6480e9 -->|method| 9fed1b55_803a_6dd5_499c_2c4f80956f99
  b627496d_3d58_e9b2_4075_0e5d0d3c8a3c["ByteOrder()"]
  9d6a7cd0_08a5_9155_3c10_b8a8fd6480e9 -->|method| b627496d_3d58_e9b2_4075_0e5d0d3c8a3c
  2211f485_6ecf_e1c4_faf2_15d096266b1c["hasArray()"]
  9d6a7cd0_08a5_9155_3c10_b8a8fd6480e9 -->|method| 2211f485_6ecf_e1c4_faf2_15d096266b1c
  75e87141_8f09_39ab_83be_8362808dadcc["array()"]
  9d6a7cd0_08a5_9155_3c10_b8a8fd6480e9 -->|method| 75e87141_8f09_39ab_83be_8362808dadcc
  ed633a61_d03b_da4f_a64b_989aacb2a76e["arrayOffset()"]
  9d6a7cd0_08a5_9155_3c10_b8a8fd6480e9 -->|method| ed633a61_d03b_da4f_a64b_989aacb2a76e

Relationship Graph

Source Code

buffer/src/main/java/io/netty/buffer/UnpooledDirectByteBuf.java lines 39–777

public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf {

    private final ByteBufAllocator alloc;

    CleanableDirectBuffer cleanable;
    ByteBuffer buffer; // accessed by UnpooledUnsafeNoCleanerDirectByteBuf.reallocateDirect()
    private ByteBuffer tmpNioBuf;
    private int capacity;
    private boolean doNotFree;

    /**
     * Creates a new direct buffer.
     *
     * @param initialCapacity the initial capacity of the underlying direct buffer
     * @param maxCapacity     the maximum capacity of the underlying direct buffer
     */
    public UnpooledDirectByteBuf(ByteBufAllocator alloc, int initialCapacity, int maxCapacity) {
        super(maxCapacity);
        ObjectUtil.checkNotNull(alloc, "alloc");
        checkPositiveOrZero(initialCapacity, "initialCapacity");
        checkPositiveOrZero(maxCapacity, "maxCapacity");
        if (initialCapacity > maxCapacity) {
            throw new IllegalArgumentException(String.format(
                    "initialCapacity(%d) > maxCapacity(%d)", initialCapacity, maxCapacity));
        }

        this.alloc = alloc;
        setByteBuffer(allocateDirectBuffer(initialCapacity), false);
    }

    /**
     * Creates a new direct buffer by wrapping the specified initial buffer.
     *
     * @param maxCapacity the maximum capacity of the underlying direct buffer
     */
    protected UnpooledDirectByteBuf(ByteBufAllocator alloc, ByteBuffer initialBuffer, int maxCapacity) {
        this(alloc, initialBuffer, maxCapacity, false, true);
    }

    UnpooledDirectByteBuf(ByteBufAllocator alloc, ByteBuffer initialBuffer,
            int maxCapacity, boolean doFree, boolean slice) {
        super(maxCapacity);
        ObjectUtil.checkNotNull(alloc, "alloc");
        ObjectUtil.checkNotNull(initialBuffer, "initialBuffer");
        if (!initialBuffer.isDirect()) {
            throw new IllegalArgumentException("initialBuffer is not a direct buffer.");
        }
        if (initialBuffer.isReadOnly()) {
            throw new IllegalArgumentException("initialBuffer is a read-only buffer.");
        }

        int initialCapacity = initialBuffer.remaining();
        if (initialCapacity > maxCapacity) {
            throw new IllegalArgumentException(String.format(
                    "initialCapacity(%d) > maxCapacity(%d)", initialCapacity, maxCapacity));
        }

        this.alloc = alloc;
        doNotFree = !doFree;
        setByteBuffer((slice ? initialBuffer.slice() : initialBuffer).order(ByteOrder.BIG_ENDIAN), false);
        writerIndex(initialCapacity);
    }

    /**
     * Allocate a new direct {@link ByteBuffer} with the given initialCapacity.
     * @deprecated Use {@link #allocateDirectBuffer(int)} instead.
     */
    @Deprecated
    protected ByteBuffer allocateDirect(int initialCapacity) {
        return ByteBuffer.allocateDirect(initialCapacity);
    }

    /**
     * Free a direct {@link ByteBuffer}
     * @deprecated Use {@link #allocateDirectBuffer(int)} instead.
     */
    @Deprecated
    protected void freeDirect(ByteBuffer buffer) {
        PlatformDependent.freeDirectBuffer(buffer);
    }

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free