Creates a new buffer which wraps the specified memory address. If {@code doFree} is true the
memoryAddress will automatically be freed once the reference count of the {@link ByteBuf} reaches {@code 0}.
498832
public static ByteBuf wrappedBuffer(long memoryAddress, int size, boolean doFree) {
        return new WrappedUnpooledUnsafeDirectByteBuf(ALLOC, memoryAddress, size, doFree);
    }
1302237
protected void put(ByteBuffer bb) {
       if(_buffer.remaining() < bb.remaining()) {
           int newCapacity = Math.max(_buffer.capacity() << 1, _buffer.position() + bb.remaining());
           ByteBuffer b = ByteBuffer.allocate(newCapacity);
           _buffer.flip();
           b.put(_buffer);
           _buffer = b;
       }
       
       _buffer.put(bb);
    }
768523
public static Buffer wrap(final byte[] buffer) {
        if (buffer == null || buffer.length == 0) {
            throw new IllegalArgumentException("the buffer cannot be null or empty");
        }

        return new ByteBuffer(buffer);
    }
448510
public Promise<Void> write(ByteBuf buf) {
		return sanitize(ofBlockingRunnable(executor, () -> {
			synchronized (mutexLock) {
				try {
					int writtenBytes;
					do {
						ByteBuffer byteBuffer = buf.toReadByteBuffer();
						writtenBytes = channel.write(byteBuffer);
						buf.ofReadByteBuffer(byteBuffer);
					} while (writtenBytes != -1 && buf.canRead());
				} catch (IOException e) {
					throw new UncheckedException(e);
				} finally {
					buf.recycle();
				}
			}
		}));
	}
885796
public static ByteBuf copiedBuffer(ByteBuffer buffer) {
        int length = buffer.remaining();
        if (length == 0) {
            return EMPTY_BUFFER;
        }
        byte[] copy = PlatformDependent.allocateUninitializedArray(length);
        // Duplicate the buffer so we not adjust the position during our get operation.
        // See https://github.com/netty/netty/issues/3896
        ByteBuffer duplicate = buffer.duplicate();
        duplicate.get(copy);
        return wrappedBuffer(copy).order(duplicate.order());
    }
603193
public ByteBuffer readBuffer(long address, int length) {
    ByteBuffer[] buffers = readBuffers(address, length);
    if (buffers.length == 1) {
      return buffers[0];
    } else {
      ByteBuffer copy = ByteBuffer.allocate(length);
      for (ByteBuffer b : buffers) {
        copy.put(b);
      }
      return ((ByteBuffer) copy.flip()).asReadOnlyBuffer();
    }
  }
625148
private void newBuffer(int offset) {
    if (maxBufferSize >= 0) {
      buffer = new int[maxBufferSize];
      isByte = new boolean[maxBufferSize];
      bufferOffset = offset;
      currentBufferSize = 0;
    }
  }
365182
public static Slice wrappedBuffer(byte[] array, int offset, int length)
    {
        if (length == 0) {
            return EMPTY_SLICE;
        }
        return new Slice(array, offset, length);
    }
528241
@Override
    public SubsequentAddressMessage createSAM() {
        SubsequentAddressMessage msg = new SubsequentAddressMessageImpl(_SAM_HOLDER.mandatoryCodes,
                _SAM_HOLDER.mandatoryVariableCodes, _SAM_HOLDER.optionalCodes, _SAM_HOLDER.mandatoryCodeToIndex,
                _SAM_HOLDER.mandatoryVariableCodeToIndex, _SAM_HOLDER.optionalCodeToIndex);
        return msg;
    }
1097276
public ChannelBuffer wrap(ByteBuffer buffer) {
        if (buffer == null) {
            throw new NullPointerException("buffer");
        }

        int position = buffer.position();
        int limit = buffer.limit();

        this.order = buffer.order();
        this.buffer = buffer;
        this.capacity = buffer.capacity();
        setIndex(position, limit);
        return this;
    }
1223999
static public void dispose (ByteBuffer buffer) {
		if (!(buffer instanceof DirectBuffer)) return;
		if (cleanerMethod != null) {
			try {
				cleanMethod.invoke(cleanerMethod.invoke(buffer));
			} catch (Throwable ignored) {
			}
		}
	}
429405
static void offerFirstTemporaryDirectBuffer(ByteBuffer buf) {
        assert buf != null;
        BufferCache cache = bufferCache.get();
        if (!cache.offerFirst(buf)) {
            // cache is full
            free(buf);
        }
    }
530180
private DataBuffer withDataBufferFactory(ByteBufHttpData data) {
        final byte[] dataArray = ByteBufUtil.getBytes(data.content());
        data.release();
        return delegate.wrap(dataArray);
    }
1075999
@Override
	public boolean create() {
		if (super.create()) {
			// store local address if we are not running in local mode
			if (!getMobicentsCache().isLocalMode()) {
				setClusterNodeAddress(getMobicentsCache().getJBossCache().getLocalAddress());
			}
			return true;
		}
		else {
			return false;
		}
	}
1250816
protected final ByteBuf newDirectBuffer(Object holder, ByteBuf buf) {
        final int readableBytes = buf.readableBytes();
        if (readableBytes == 0) {
            ReferenceCountUtil.release(holder);
            return Unpooled.EMPTY_BUFFER;
        }

        final ByteBufAllocator alloc = alloc();
        if (alloc.isDirectBufferPooled()) {
            return newDirectBuffer0(holder, buf, alloc, readableBytes);
        }

        final ByteBuf directBuf = ByteBufUtil.threadLocalDirectBuffer();
        if (directBuf == null) {
            return newDirectBuffer0(holder, buf, alloc, readableBytes);
        }

        directBuf.writeBytes(buf, buf.readerIndex(), readableBytes);
        ReferenceCountUtil.safeRelease(holder);
        return directBuf;
    }
465923
public static UnsafeHeapBuffer wrap(byte[] bytes) {
    return new UnsafeHeapBuffer(UnsafeHeapBytes.wrap(bytes), 0, bytes.length, bytes.length);
  }
1317469
protected ByteBuf allocateBuffer(
        ChannelHandlerContext ctx,
        @SuppressWarnings("unused") AddressedEnvelope<DnsResponse, InetSocketAddress> msg) throws Exception {
        return ctx.alloc().ioBuffer(1024);
    }