io.netty.buffer.ByteBufUtil#threadLocalDirectBuffer ( )源码实例Demo

下面列出了io.netty.buffer.ByteBufUtil#threadLocalDirectBuffer ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netty-4.1.22   文件: AbstractKQueueChannel.java
/**
 * Returns an off-heap copy of the specified {@link ByteBuf}, and releases the specified holder.
 * The caller must ensure that the holder releases the original {@link ByteBuf} when the holder is released by
 * this method.
 */
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;
}
 
源代码2 项目: netty-4.1.22   文件: AbstractEpollChannel.java
/**
 * Returns an off-heap copy of the specified {@link ByteBuf}, and releases the specified holder.
 * The caller must ensure that the holder releases the original {@link ByteBuf} when the holder is released by
 * this method.返回指定ByteBuf的堆外副本,并释放指定的holder。调用方必须确保持有者在通过此方法释放持有者时释放原始ByteBuf。
 */
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;
}
 
源代码3 项目: netty4.0.27Learn   文件: AbstractEpollChannel.java
/**
 * Returns an off-heap copy of the specified {@link ByteBuf}, and releases the specified holder.
 * The caller must ensure that the holder releases the original {@link ByteBuf} when the holder is released by
 * this method.
 */
protected final ByteBuf newDirectBuffer(Object holder, ByteBuf buf) {
    final int readableBytes = buf.readableBytes();
    if (readableBytes == 0) {
        ReferenceCountUtil.safeRelease(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;
}
 
源代码4 项目: sctalk   文件: DataBuffer.java
public DataBuffer() {
    buffer = ByteBufUtil.threadLocalDirectBuffer(); // ByteBufs.dynamicBuffer();
}
 
源代码5 项目: sctalk   文件: DataBuffer.java
public DataBuffer(int length) {
    buffer = ByteBufUtil.threadLocalDirectBuffer();// ByteBufs.buffer(length);
    buffer.capacity(length);
}
 
源代码6 项目: sctalk   文件: DataBuffer.java
public DataBuffer() {
    buffer = ByteBufUtil.threadLocalDirectBuffer(); // ByteBufs.dynamicBuffer();
}
 
源代码7 项目: sctalk   文件: DataBuffer.java
public DataBuffer(int length) {
    buffer = ByteBufUtil.threadLocalDirectBuffer();// ByteBufs.buffer(length);
    buffer.capacity(length);
}