title: Efficient way to convert io.netty.buffer.ByteBuf to java.nio.ByteBuffer
body: <p>I came across this query: <a href="https://stackoverflow.com/questions/15088065/create-a-bytebuf-in-netty-4-0-0-beta1">Create a ByteBuf in Netty 4.0</a> about conversion from byte[] to ByteBuf and ByteBuffer to ByteBuf. I was curious to know about the conversion the other way:</p>
  
  <p>io.netty.buffer.ByteBuf to java.nio.ByteBuffer</p>
  
  <p>and how to do it efficiently, with minimal/no copying? I did some reading and with some trial and error I found this inefficient way of converting it (with two copies):</p>
  
  <pre><code>// io.netty.handler.codec.http.FullHttpRequest fullHttpRequest;
  ByteBuf conByteBuf = fullHttpRequest.content ();                  
  int numReadBytes = conByteBuf.readableBytes ();
  conBytes = new byte[numReadBytes];
  conByteBuf .readBytes (conBytes);                                // First Copy
  ByteBuffer conByteBuffer = ByteBuffer.allocate (conBytes.length);
  conByteBuffer.put (conByteBuf);                                  // Second Copy
  </code></pre>
  
  <p>My question is, can we avoid one or both the copies and make the internal buffer of ByteBuffer to use the internal buffer of ByteBuf.</p>
  
  <p>Thanks!</p>