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


Java ByteBuf.nioBuffer方法代码示例

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


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

示例1: readString

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private static String readString(ByteBuf cb, int length)
{
    if (length == 0)
        return "";

    ByteBuffer buffer = cb.nioBuffer(cb.readerIndex(), length);
    try
    {
        String str = decodeString(buffer);
        cb.readerIndex(cb.readerIndex() + length);
        return str;
    }
    catch (IllegalStateException | CharacterCodingException e)
    {
        throw new ProtocolException("Cannot decode string as UTF8: '" + ByteBufferUtil.bytesToHex(buffer) + "'; " + e);
    }
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:18,代码来源:CBUtil.java

示例2: 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

示例3: mapToMessage

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@SneakyThrows
public static Message mapToMessage(ByteBuf bb) {
    val buf = bb.nioBuffer();

    return new ObjectMapper().readValue(new InputStream() {

        public int read() throws IOException {
            if (!buf.hasRemaining()) {
                return -1;
            }
            return buf.get() & 0xFF;
        }

        public int read(byte[] bytes, int off, int len)
                throws IOException {
            if (!buf.hasRemaining()) {
                return -1;
            }

            len = Math.min(len, buf.remaining());
            buf.get(bytes, off, len);
            return len;
        }
    }, Message.class);
}
 
开发者ID:OlegDokuka,项目名称:reactive-playing,代码行数:26,代码来源:MessageEncoder.java

示例4: uncompressPage

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private ByteBuffer uncompressPage(PageHeader pageHeader, boolean isDataPage) throws IOException {
  final ByteBuf src = allocator.buffer(pageHeader.compressed_page_size);
  try {
    ByteBuffer srcBuffer = src.nioBuffer(0, pageHeader.compressed_page_size);
    readFully(srcBuffer, pageHeader.compressed_page_size);

    ByteBuf dest = allocator.buffer(pageHeader.uncompressed_page_size);
    ByteBuffer destBuffer = dest.nioBuffer(0, pageHeader.uncompressed_page_size);
    decompressor.decompress(
        srcBuffer,
        pageHeader.compressed_page_size,
        destBuffer,
        pageHeader.uncompressed_page_size
    );
    if (isDataPage) {
      lastDataPageUncompressed = dest;
    } else {
      dictionaryPageUncompressed = dest;
    }
    return destBuffer;
  } finally {
    src.release(); // we don't need this anymore
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:25,代码来源:ColumnChunkIncReadStore.java

示例5: allocate

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public ByteBuffer allocate(int sz) {
  ByteBuf bb = allocator.buffer(sz);
  ByteBuffer b = bb.nioBuffer(0, sz);
  final Key key = new Key(b);
  allocatedBuffers.put(key, bb);
  logger.debug("ParquetDirectByteBufferAllocator: Allocated {} bytes. Allocated ByteBuffer id: {}", sz, key.hash);
  return b;
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:10,代码来源:ParquetDirectByteBufferAllocator.java

示例6: copyByteBuf

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private int copyByteBuf(ByteBuf buf, WritableByteChannel target) throws IOException {
  ByteBuffer buffer = buf.nioBuffer();
  int written = (buffer.remaining() <= NIO_BUFFER_LIMIT) ?
    target.write(buffer) : writeNioBuffer(target, buffer);
  buf.skipBytes(written);
  return written;
}
 
开发者ID:spafka,项目名称:spark_deep,代码行数:8,代码来源:MessageWithHeader.java

示例7: allocate

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
  public ByteBuffer allocate(int sz) {
    ByteBuf bb = allocator.buffer(sz);
    ByteBuffer b = bb.nioBuffer(0, sz);
    final Key key = new Key(b);
    allocatedBuffers.put(key, bb);
//    logger.debug("ParquetDirectByteBufferAllocator: Allocated {} bytes. Allocated ByteBuffer id: {}", sz, key.hash);
    return b;
  }
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:10,代码来源:ParquetDirectByteBufferAllocator.java


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