本文整理了Java中io.netty.buffer.ByteBuf.internalNioBuffer()
方法的一些代码示例,展示了ByteBuf.internalNioBuffer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuf.internalNioBuffer()
方法的具体详情如下:
包路径:io.netty.buffer.ByteBuf
类名称:ByteBuf
方法名:internalNioBuffer
[英]Internal use only: Exposes the internal NIO buffer.
[中]仅限内部使用:公开内部NIO缓冲区。
代码示例来源:origin: netty/netty
@Override
public ByteBuffer internalNioBuffer(int index, int length) {
return buf.internalNioBuffer(index, length);
}
代码示例来源:origin: redisson/redisson
@Override
public ByteBuffer internalNioBuffer(int index, int length) {
return buf.internalNioBuffer(index, length);
}
代码示例来源:origin: netty/netty
@Override
public ByteBuffer internalNioBuffer(int index, int length) {
checkIndex(index, length);
return buffer.internalNioBuffer(index, length);
}
代码示例来源:origin: netty/netty
static ByteBuffer safeNioBuffer(ByteBuf buffer) {
return buffer.nioBufferCount() == 1 ? buffer.internalNioBuffer(buffer.readerIndex(), buffer.readableBytes())
: buffer.nioBuffer();
}
}
代码示例来源:origin: netty/netty
@Override
public ByteBuffer internalNioBuffer(int index, int length) {
if (buffers.length == 1) {
return buffer(0).internalNioBuffer(index, length);
}
throw new UnsupportedOperationException();
}
代码示例来源:origin: netty/netty
@Override
public ByteBuffer internalNioBuffer(int index, int length) {
switch (componentCount) {
case 0:
return EMPTY_NIO_BUFFER;
case 1:
Component c = components[0];
return c.buf.internalNioBuffer(c.idx(index), length);
default:
throw new UnsupportedOperationException();
}
}
代码示例来源:origin: redisson/redisson
static ByteBuffer safeNioBuffer(ByteBuf buffer) {
return buffer.nioBufferCount() == 1 ? buffer.internalNioBuffer(buffer.readerIndex(), buffer.readableBytes())
: buffer.nioBuffer();
}
}
代码示例来源:origin: redisson/redisson
@Override
public ByteBuffer internalNioBuffer(int index, int length) {
switch (componentCount) {
case 0:
return EMPTY_NIO_BUFFER;
case 1:
Component c = components[0];
return c.buf.internalNioBuffer(c.idx(index), length);
default:
throw new UnsupportedOperationException();
}
}
代码示例来源:origin: redisson/redisson
@Override
public ByteBuffer internalNioBuffer(int index, int length) {
checkIndex(index, length);
return buffer.internalNioBuffer(index, length);
}
代码示例来源:origin: redisson/redisson
@Override
public ByteBuffer internalNioBuffer(int index, int length) {
if (buffers.length == 1) {
return buffer(0).internalNioBuffer(index, length);
}
throw new UnsupportedOperationException();
}
代码示例来源:origin: redisson/redisson
private static ByteBuffer toByteBuffer(ByteBuf out, int index, int len) {
return out.nioBufferCount() == 1 ? out.internalNioBuffer(index, len) :
out.nioBuffer(index, len);
}
代码示例来源:origin: redisson/redisson
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
int decompressSize = buf.readInt();
ByteBuf out = ByteBufAllocator.DEFAULT.buffer(decompressSize);
try {
LZ4SafeDecompressor decompressor = factory.safeDecompressor();
ByteBuffer outBuffer = out.internalNioBuffer(out.writerIndex(), out.writableBytes());
int pos = outBuffer.position();
decompressor.decompress(buf.internalNioBuffer(buf.readerIndex(), buf.readableBytes()), outBuffer);
int compressedLength = outBuffer.position() - pos;
out.writerIndex(compressedLength);
return innerCodec.getValueDecoder().decode(out, state);
} finally {
out.release();
}
}
};
代码示例来源:origin: redisson/redisson
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
int decompressSize = buf.readInt();
ByteBuf out = ByteBufAllocator.DEFAULT.buffer(decompressSize);
try {
LZ4SafeDecompressor decompressor = factory.safeDecompressor();
ByteBuffer outBuffer = out.internalNioBuffer(out.writerIndex(), out.writableBytes());
int pos = outBuffer.position();
decompressor.decompress(buf.internalNioBuffer(buf.readerIndex(), buf.readableBytes()), outBuffer);
int compressedLength = outBuffer.position() - pos;
out.writerIndex(compressedLength);
return innerCodec.getValueDecoder().decode(out, state);
} finally {
out.release();
}
}
};
代码示例来源:origin: AsyncHttpClient/async-http-client
private void decodeHeap0(ByteBuf buf) {
int length = buf.readableBytes();
ensureCapacity(length);
if (buf.nioBufferCount() == 1) {
decodeSingleNioBuffer(buf.internalNioBuffer(buf.readerIndex(), length).duplicate());
} else {
decode(buf.nioBuffers());
}
charBuffer.flip();
}
代码示例来源:origin: redisson/redisson
protected final int doWriteBytes(ChannelOutboundBuffer in, ByteBuf buf) throws Exception {
if (buf.hasMemoryAddress()) {
int localFlushedAmount = socket.writeAddress(buf.memoryAddress(), buf.readerIndex(), buf.writerIndex());
if (localFlushedAmount > 0) {
in.removeBytes(localFlushedAmount);
return 1;
}
} else {
final ByteBuffer nioBuf = buf.nioBufferCount() == 1 ?
buf.internalNioBuffer(buf.readerIndex(), buf.readableBytes()) : buf.nioBuffer();
int localFlushedAmount = socket.write(nioBuf, nioBuf.position(), nioBuf.limit());
if (localFlushedAmount > 0) {
nioBuf.position(nioBuf.position() + localFlushedAmount);
in.removeBytes(localFlushedAmount);
return 1;
}
}
return WRITE_STATUS_SNDBUF_FULL;
}
代码示例来源:origin: redisson/redisson
protected final int doWriteBytes(ChannelOutboundBuffer in, ByteBuf buf) throws Exception {
if (buf.hasMemoryAddress()) {
int localFlushedAmount = socket.writeAddress(buf.memoryAddress(), buf.readerIndex(), buf.writerIndex());
if (localFlushedAmount > 0) {
in.removeBytes(localFlushedAmount);
return 1;
}
} else {
final ByteBuffer nioBuf = buf.nioBufferCount() == 1 ?
buf.internalNioBuffer(buf.readerIndex(), buf.readableBytes()) : buf.nioBuffer();
int localFlushedAmount = socket.write(nioBuf, nioBuf.position(), nioBuf.limit());
if (localFlushedAmount > 0) {
nioBuf.position(nioBuf.position() + localFlushedAmount);
in.removeBytes(localFlushedAmount);
return 1;
}
}
return WRITE_STATUS_SNDBUF_FULL;
}
代码示例来源:origin: netty/netty
@Override
protected boolean doWriteMessage(Object msg, ChannelOutboundBuffer in) throws Exception {
final SocketAddress remoteAddress;
final ByteBuf data;
if (msg instanceof AddressedEnvelope) {
@SuppressWarnings("unchecked")
AddressedEnvelope<ByteBuf, SocketAddress> envelope = (AddressedEnvelope<ByteBuf, SocketAddress>) msg;
remoteAddress = envelope.recipient();
data = envelope.content();
} else {
data = (ByteBuf) msg;
remoteAddress = null;
}
final int dataLen = data.readableBytes();
if (dataLen == 0) {
return true;
}
final ByteBuffer nioData = data.nioBufferCount() == 1 ? data.internalNioBuffer(data.readerIndex(), dataLen)
: data.nioBuffer(data.readerIndex(), dataLen);
final int writtenBytes;
if (remoteAddress != null) {
writtenBytes = javaChannel().send(nioData, remoteAddress);
} else {
writtenBytes = javaChannel().write(nioData);
}
return writtenBytes > 0;
}
代码示例来源:origin: redisson/redisson
/**
* Read bytes into the given {@link ByteBuf} and return the amount.
*/
protected final int doReadBytes(ByteBuf byteBuf) throws Exception {
int writerIndex = byteBuf.writerIndex();
int localReadAmount;
unsafe().recvBufAllocHandle().attemptedBytesRead(byteBuf.writableBytes());
if (byteBuf.hasMemoryAddress()) {
localReadAmount = socket.readAddress(byteBuf.memoryAddress(), writerIndex, byteBuf.capacity());
} else {
ByteBuffer buf = byteBuf.internalNioBuffer(writerIndex, byteBuf.writableBytes());
localReadAmount = socket.read(buf, buf.position(), buf.limit());
}
if (localReadAmount > 0) {
byteBuf.writerIndex(writerIndex + localReadAmount);
}
return localReadAmount;
}
代码示例来源:origin: redisson/redisson
/**
* Read bytes into the given {@link ByteBuf} and return the amount.
*/
protected final int doReadBytes(ByteBuf byteBuf) throws Exception {
int writerIndex = byteBuf.writerIndex();
int localReadAmount;
unsafe().recvBufAllocHandle().attemptedBytesRead(byteBuf.writableBytes());
if (byteBuf.hasMemoryAddress()) {
localReadAmount = socket.readAddress(byteBuf.memoryAddress(), writerIndex, byteBuf.capacity());
} else {
ByteBuffer buf = byteBuf.internalNioBuffer(writerIndex, byteBuf.writableBytes());
localReadAmount = socket.read(buf, buf.position(), buf.limit());
}
if (localReadAmount > 0) {
byteBuf.writerIndex(writerIndex + localReadAmount);
}
return localReadAmount;
}
代码示例来源:origin: netty/netty
@Override
protected int doReadMessages(List<Object> buf) throws Exception {
DatagramChannel ch = javaChannel();
DatagramChannelConfig config = config();
RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle();
ByteBuf data = allocHandle.allocate(config.getAllocator());
allocHandle.attemptedBytesRead(data.writableBytes());
boolean free = true;
try {
ByteBuffer nioData = data.internalNioBuffer(data.writerIndex(), data.writableBytes());
int pos = nioData.position();
InetSocketAddress remoteAddress = (InetSocketAddress) ch.receive(nioData);
if (remoteAddress == null) {
return 0;
}
allocHandle.lastBytesRead(nioData.position() - pos);
buf.add(new DatagramPacket(data.writerIndex(data.writerIndex() + allocHandle.lastBytesRead()),
localAddress(), remoteAddress));
free = false;
return 1;
} catch (Throwable cause) {
PlatformDependent.throwException(cause);
return -1;
} finally {
if (free) {
data.release();
}
}
}
内容来源于网络,如有侵权,请联系作者删除!