當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。