code: public static byte[] byteBufToArray(ByteBuf byteBuf) {
          int length = byteBuf.readableBytes();
          byte[] byteArray = new byte[length];
          byteBuf.getBytes(byteBuf.readerIndex(), byteArray);
          return byteArray;
      }
docs: Gets the content of the provided ByteBuf as a byte array.
  This method will create a new byte array even if the ByteBuf can
  have optionally backing array.
  
  
  @param byteBuf the byte buffer
  @return the byte array