Class UnpooledUnsafeDirectByteBuf

All Implemented Interfaces:
ByteBufConvertible, ReferenceCounted, Comparable<ByteBuf>
Direct Known Subclasses:
ByteBufUtil.ThreadLocalUnsafeDirectByteBuf, UnpooledByteBufAllocator.InstrumentedUnpooledUnsafeDirectByteBuf, UnpooledUnsafeNoCleanerDirectByteBuf, WrappedUnpooledUnsafeDirectByteBuf

public class UnpooledUnsafeDirectByteBuf extends UnpooledDirectByteBuf
A NIO ByteBuffer based buffer. It is recommended to use AbstractByteBufAllocator.directBuffer(int, int), Unpooled.directBuffer(int) and Unpooled.wrappedBuffer(ByteBuffer) instead of calling the constructor explicitly.}
  • Field Details

    • memoryAddress

      long memoryAddress
  • Constructor Details

    • UnpooledUnsafeDirectByteBuf

      public UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, int initialCapacity, int maxCapacity)
      Creates a new direct buffer.
      Parameters:
      initialCapacity - the initial capacity of the underlying direct buffer
      maxCapacity - the maximum capacity of the underlying direct buffer
    • UnpooledUnsafeDirectByteBuf

      protected UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, ByteBuffer initialBuffer, int maxCapacity)
      Creates a new direct buffer by wrapping the specified initial buffer.
      Parameters:
      maxCapacity - the maximum capacity of the underlying direct buffer
    • UnpooledUnsafeDirectByteBuf

      UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, ByteBuffer initialBuffer, int maxCapacity, boolean doFree)
  • Method Details

    • setByteBuffer

      final void setByteBuffer(ByteBuffer buffer, boolean tryFree)
      Overrides:
      setByteBuffer in class UnpooledDirectByteBuf
    • hasMemoryAddress

      public boolean hasMemoryAddress()
      Description copied from class: ByteBuf
      Returns true if and only if this buffer has a reference to the low-level memory address that points to the backing data.
      Overrides:
      hasMemoryAddress in class UnpooledDirectByteBuf
    • memoryAddress

      public long memoryAddress()
      Description copied from class: ByteBuf
      Returns the low-level memory address that point to the first byte of ths backing data.
      Overrides:
      memoryAddress in class UnpooledDirectByteBuf
    • getByte

      public byte getByte(int index)
      Description copied from class: ByteBuf
      Gets a byte at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Overrides:
      getByte in class UnpooledDirectByteBuf
    • _getByte

      protected byte _getByte(int index)
      Overrides:
      _getByte in class UnpooledDirectByteBuf
    • getShort

      public short getShort(int index)
      Description copied from class: ByteBuf
      Gets a 16-bit short integer at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Overrides:
      getShort in class UnpooledDirectByteBuf
    • _getShort

      protected short _getShort(int index)
      Overrides:
      _getShort in class UnpooledDirectByteBuf
    • _getShortLE

      protected short _getShortLE(int index)
      Overrides:
      _getShortLE in class UnpooledDirectByteBuf
    • getUnsignedMedium

      public int getUnsignedMedium(int index)
      Description copied from class: ByteBuf
      Gets an unsigned 24-bit medium integer at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Overrides:
      getUnsignedMedium in class UnpooledDirectByteBuf
    • _getUnsignedMedium

      protected int _getUnsignedMedium(int index)
      Overrides:
      _getUnsignedMedium in class UnpooledDirectByteBuf
    • _getUnsignedMediumLE

      protected int _getUnsignedMediumLE(int index)
      Overrides:
      _getUnsignedMediumLE in class UnpooledDirectByteBuf
    • getInt

      public int getInt(int index)
      Description copied from class: ByteBuf
      Gets a 32-bit integer at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Overrides:
      getInt in class UnpooledDirectByteBuf
    • _getInt

      protected int _getInt(int index)
      Overrides:
      _getInt in class UnpooledDirectByteBuf
    • _getIntLE

      protected int _getIntLE(int index)
      Overrides:
      _getIntLE in class UnpooledDirectByteBuf
    • getLong

      public long getLong(int index)
      Description copied from class: ByteBuf
      Gets a 64-bit long integer at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Overrides:
      getLong in class UnpooledDirectByteBuf
    • _getLong

      protected long _getLong(int index)
      Overrides:
      _getLong in class UnpooledDirectByteBuf
    • _getLongLE

      protected long _getLongLE(int index)
      Overrides:
      _getLongLE in class UnpooledDirectByteBuf
    • getBytes

      public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length)
      Description copied from class: ByteBuf
      Transfers this buffer's data to the specified destination starting at the specified absolute index. This method does not modify readerIndex or writerIndex of both the source (i.e. this) and the destination.
      Overrides:
      getBytes in class UnpooledDirectByteBuf
      Parameters:
      dstIndex - the first index of the destination
      length - the number of bytes to transfer
    • getBytes

      void getBytes(int index, byte[] dst, int dstIndex, int length, boolean internal)
      Overrides:
      getBytes in class UnpooledDirectByteBuf
    • getBytes

      void getBytes(int index, ByteBuffer dst, boolean internal)
      Overrides:
      getBytes in class UnpooledDirectByteBuf
    • setByte

      public ByteBuf setByte(int index, int value)
      Description copied from class: ByteBuf
      Sets the specified byte at the specified absolute index in this buffer. The 24 high-order bits of the specified value are ignored. This method does not modify readerIndex or writerIndex of this buffer.
      Overrides:
      setByte in class UnpooledDirectByteBuf
    • _setByte

      protected void _setByte(int index, int value)
      Overrides:
      _setByte in class UnpooledDirectByteBuf
    • setShort

      public ByteBuf setShort(int index, int value)
      Description copied from class: ByteBuf
      Sets the specified 16-bit short integer at the specified absolute index in this buffer. The 16 high-order bits of the specified value are ignored. This method does not modify readerIndex or writerIndex of this buffer.
      Overrides:
      setShort in class UnpooledDirectByteBuf
    • _setShort

      protected void _setShort(int index, int value)
      Overrides:
      _setShort in class UnpooledDirectByteBuf
    • _setShortLE

      protected void _setShortLE(int index, int value)
      Overrides:
      _setShortLE in class UnpooledDirectByteBuf
    • setMedium

      public ByteBuf setMedium(int index, int value)
      Description copied from class: ByteBuf
      Sets the specified 24-bit medium integer at the specified absolute index in this buffer. Please note that the most significant byte is ignored in the specified value. This method does not modify readerIndex or writerIndex of this buffer.
      Overrides:
      setMedium in class UnpooledDirectByteBuf
    • _setMedium

      protected void _setMedium(int index, int value)
      Overrides:
      _setMedium in class UnpooledDirectByteBuf
    • _setMediumLE

      protected void _setMediumLE(int index, int value)
      Overrides:
      _setMediumLE in class UnpooledDirectByteBuf
    • setInt

      public ByteBuf setInt(int index, int value)
      Description copied from class: ByteBuf
      Sets the specified 32-bit integer at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Overrides:
      setInt in class UnpooledDirectByteBuf
    • _setInt

      protected void _setInt(int index, int value)
      Overrides:
      _setInt in class UnpooledDirectByteBuf
    • _setIntLE

      protected void _setIntLE(int index, int value)
      Overrides:
      _setIntLE in class UnpooledDirectByteBuf
    • setLong

      public ByteBuf setLong(int index, long value)
      Description copied from class: ByteBuf
      Sets the specified 64-bit long integer at the specified absolute index in this buffer. This method does not modify readerIndex or writerIndex of this buffer.
      Overrides:
      setLong in class UnpooledDirectByteBuf
    • _setLong

      protected void _setLong(int index, long value)
      Overrides:
      _setLong in class UnpooledDirectByteBuf
    • _setLongLE

      protected void _setLongLE(int index, long value)
      Overrides:
      _setLongLE in class UnpooledDirectByteBuf
    • setBytes

      public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length)
      Description copied from class: ByteBuf
      Transfers the specified source buffer's data to this buffer starting at the specified absolute index. This method does not modify readerIndex or writerIndex of both the source (i.e. this) and the destination.
      Overrides:
      setBytes in class UnpooledDirectByteBuf
      Parameters:
      srcIndex - the first index of the source
      length - the number of bytes to transfer
    • setBytes

      public ByteBuf setBytes(int index, byte[] src, int srcIndex, int length)
      Description copied from class: ByteBuf
      Transfers the specified source array's data to this buffer starting at the specified absolute index. This method does not modify readerIndex or writerIndex of this buffer.
      Overrides:
      setBytes in class UnpooledDirectByteBuf
    • setBytes

      public ByteBuf setBytes(int index, ByteBuffer src)
      Description copied from class: ByteBuf
      Transfers the specified source buffer's data to this buffer starting at the specified absolute index until the source buffer's position reaches its limit. This method does not modify readerIndex or writerIndex of this buffer.
      Overrides:
      setBytes in class UnpooledDirectByteBuf
    • getBytes

      void getBytes(int index, OutputStream out, int length, boolean internal) throws IOException
      Overrides:
      getBytes in class UnpooledDirectByteBuf
      Throws:
      IOException
    • setBytes

      public int setBytes(int index, InputStream in, int length) throws IOException
      Description copied from class: ByteBuf
      Transfers the content of the specified source stream to this buffer starting at the specified absolute index. This method does not modify readerIndex or writerIndex of this buffer.
      Overrides:
      setBytes in class UnpooledDirectByteBuf
      Parameters:
      length - the number of bytes to transfer
      Returns:
      the actual number of bytes read in from the specified channel. -1 if the specified InputStream reached EOF.
      Throws:
      IOException - if the specified stream threw an exception during I/O
    • copy

      public ByteBuf copy(int index, int length)
      Description copied from class: ByteBuf
      Returns a copy of this buffer's sub-region. Modifying the content of the returned buffer or this buffer does not affect each other at all. This method does not modify readerIndex or writerIndex of this buffer.
      Overrides:
      copy in class UnpooledDirectByteBuf
    • addr

      final long addr(int index)
    • newSwappedByteBuf

      protected SwappedByteBuf newSwappedByteBuf()
      Description copied from class: AbstractByteBuf
      Creates a new SwappedByteBuf for this ByteBuf instance.
      Overrides:
      newSwappedByteBuf in class AbstractByteBuf
    • setZero

      public ByteBuf setZero(int index, int length)
      Description copied from class: ByteBuf
      Fills this buffer with NUL (0x00) starting at the specified absolute index. This method does not modify readerIndex or writerIndex of this buffer.
      Overrides:
      setZero in class AbstractByteBuf
      Parameters:
      length - the number of NULs to write to the buffer
    • writeZero

      public ByteBuf writeZero(int length)
      Description copied from class: ByteBuf
      Fills this buffer with NUL (0x00) starting at the current writerIndex and increases the writerIndex by the specified length. If this.writableBytes is less than length, ByteBuf.ensureWritable(int) will be called in an attempt to expand capacity to accommodate.
      Overrides:
      writeZero in class AbstractByteBuf
      Parameters:
      length - the number of NULs to write to the buffer