public class ChannelAdapters extends Object
Thread Safety
The channel implementations in this class are thread safe, as per the general requirement of theChannel
interface. However, in case a channel is based on
an underlying buffer, cautions must be taken to preserve thread safety:
Modifier and Type | Method and Description |
---|---|
static WritableByteChannel |
intoByteArray(byte[] output)
Adapts a byte array to be the destination of a
WritableByteChannel . |
static WritableByteChannel |
intoByteArray(byte[] output,
int offset,
int length)
Adapts a byte array to be the destination of a
WritableByteChannel . |
static WritableByteChannel |
intoByteBuf(io.netty.buffer.ByteBuf output)
todo(bowen): implement.
|
static WritableByteChannel |
intoByteBuffer(ByteBuffer output)
Adapts a ByteBuffer to be the destination of a
WritableByteChannel . |
public static WritableByteChannel intoByteBuffer(ByteBuffer output)
WritableByteChannel
.
WritableByteChannel.write(ByteBuffer)
method is called,
will copy p
bytes from the source buffer to the output buffer,
where p = min(src.remaining(), output.remaining())
. After the write is successful,
the positions of both the source and output buffer will have increased by p
.
If the output buffer has no space remaining, while the source
buffer has available bytes, ClosedChannelException
is thrown.output
- the output byte bufferpublic static WritableByteChannel intoByteArray(byte[] output)
WritableByteChannel
.
Bytes will be written from the beginning of the array and to the end.output
- output bufferpublic static WritableByteChannel intoByteArray(byte[] output, int offset, int length)
WritableByteChannel
.
Bytes will be written from index offset
to offset + length
.output
- output bufferoffset
- offset within the bufferlength
- length of the writable region within the bufferpublic static WritableByteChannel intoByteBuf(io.netty.buffer.ByteBuf output)
output
- outputCopyright © 2023. All Rights Reserved.