当前位置: 首页>>代码示例>>Java>>正文


Java ByteBuf.isDirect方法代码示例

本文整理汇总了Java中io.netty.buffer.ByteBuf.isDirect方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuf.isDirect方法的具体用法?Java ByteBuf.isDirect怎么用?Java ByteBuf.isDirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.buffer.ByteBuf的用法示例。


在下文中一共展示了ByteBuf.isDirect方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readBytes

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public ByteBuffer readBytes(ByteBuf source) {
  int len = readInt(source);
  if (len < 0) {
    return null;
  }

  ByteBuf slice = source.readSlice(len);
  // if direct byte buffer, return underlying nioBuffer.
  if (slice.isDirect()) {
    return slice.nioBuffer();
  }
  // otherwise copy to a byte array and wrap it.
  final byte[] out = new byte[slice.readableBytes()];
  source.getBytes(source.readerIndex(), out, 0, len);
  return ByteBuffer.wrap(out);
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:18,代码来源:ByteBufCodec.java

示例2: inflate

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
 * Decompresses a buffer.
 *
 * @param buffer the buffer to decompress
 * @return the decompressed buffer
 * @throws DataFormatException if data could not be inflated
 */
public static ByteBuf inflate(ByteBuf buffer) throws DataFormatException {
    // Ensure that this buffer is direct.
    ByteBuf source = null;
    ByteBuf decompressed = PooledByteBufAllocator.DEFAULT.directBuffer();

    try {
        if (!buffer.isDirect()) {
            // We don't have a direct buffer. Create one.
            ByteBuf temporary = PooledByteBufAllocator.DEFAULT.directBuffer();
            temporary.writeBytes(buffer);
            source = temporary;
        } else {
            source = buffer;
        }

        inflaterLocal.get().process(source, decompressed);
        decompressed.resetReaderIndex();
        return decompressed;
    } catch (DataFormatException e) {
        decompressed.release();
        throw e;
    } finally {
        if (source != null && source != buffer) {
            source.release();
        }
    }
}
 
开发者ID:KernelFreeze,项目名称:BedrockProxy,代码行数:35,代码来源:Compression.java

示例3: deflate

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
 * Compresses a {@link ByteBuf}.
 *
 * @param toCompress the buffer to compress
 * @param into       the buffer to compress into
 * @throws DataFormatException if data could not be deflated
 */
public static void deflate(ByteBuf toCompress, ByteBuf into) throws DataFormatException {
    ByteBuf destination = null;
    ByteBuf source = null;

    try {
        if (!toCompress.isDirect()) {
            // Source is not a direct buffer. Work on a temporary direct buffer and then write the contents out.
            source = PooledByteBufAllocator.DEFAULT.directBuffer();
            source.writeBytes(toCompress);
        } else {
            source = toCompress;
        }

        if (!into.isDirect()) {
            // Destination is not a direct buffer. Work on a temporary direct buffer and then write the contents out.
            destination = PooledByteBufAllocator.DEFAULT.directBuffer();
        } else {
            destination = into;
        }

        deflaterLocal.get().process(source, destination);

        if (destination != into) {
            into.writeBytes(destination);
        }
    } finally {
        if (source != null && source != toCompress) {
            source.release();
        }
        if (destination != null && destination != into) {
            destination.release();
            destination.resetReaderIndex();
        }
    }
}
 
开发者ID:KernelFreeze,项目名称:BedrockProxy,代码行数:43,代码来源:Compression.java

示例4: encrypt

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public ByteBuf encrypt(ByteBuf data) {
    if (encCipher == null) {
        byte[] iv = EncryptUtils.randomBytes(getIvLength());
        encCipher = createCipher(iv, true);
        CompositeByteBuf bufs = new CompositeByteBuf(data.alloc(), data.isDirect(), 2);
        bufs.addComponents(true, Unpooled.wrappedBuffer(iv), process(encCipher, data));
        return bufs;
    }

    return process(encCipher, data);
}
 
开发者ID:zhoulifu,项目名称:ss-java,代码行数:13,代码来源:AbstractCrypto.java

示例5: isSingleDirectBuffer

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
/**
 * Checks if the specified buffer is a direct buffer and is composed of a single NIO buffer.
 * (We check this because otherwise we need to make it a non-composite buffer.)
 */
private static boolean isSingleDirectBuffer(ByteBuf buf) {
    return buf.isDirect() && buf.nioBufferCount() == 1;
}
 
开发者ID:szhnet,项目名称:kcp-netty,代码行数:8,代码来源:UkcpClientUdpChannel.java


注:本文中的io.netty.buffer.ByteBuf.isDirect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。