OioDatagramChannel channel, ChannelFuture future,
Object message, SocketAddress remoteAddress) {
try {
ChannelBuffer buf = (ChannelBuffer) message;
int length = buf.readableBytes();
ByteBuffer nioBuf = buf.toByteBuffer();
DatagramPacket packet;
if (nioBuf.hasArray()) {
// Avoid copy if the buffer is backed by an array.
packet = new DatagramPacket(
nioBuf.array(), nioBuf.arrayOffset(), length);