本文整理汇总了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);
}
}
示例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);
}
示例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);
}
示例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
}
}
示例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;
}
示例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;
}
示例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;
}