code: public static ByteBufToArray byteBufToByteArray(ByteBuf input) {
          byte[] inputBytes;
          int offset = 0;
          int length = input.readableBytes();
          if (input.hasArray()) {
              inputBytes = input.array();
              offset = input.arrayOffset() + input.readerIndex();
          } else {
              inputBytes = new byte[length];
              input.getBytes(input.readerIndex(), inputBytes);
          }
          return new ByteBufToArray(inputBytes, offset, length);
      }
docs: Converts a {@link ByteBuf} to a byte[] in the most straightforward manner available.
  @param input the ByteBuf to convert.
  @return a {@link ByteBufToArray} containing the byte[] array, as well as the offset and length to use (in case
  the actual array is longer than the data the ByteBuf represents for instance).