code: public static byte[] getBytes(ByteBuf buf, int start, int length, boolean copy) {
          int capacity = buf.capacity();
          if (isOutOfBounds(start, length, capacity)) {
              throw new IndexOutOfBoundsException("expected: " + "0 <= start(" + start + ") <= start + length(" + length
                      + ") <= " + "buf.capacity(" + capacity + ')');
          }
  
          if (buf.hasArray()) {
              if (copy || start != 0 || length != capacity) {
                  int baseOffset = buf.arrayOffset() + start;
                  return Arrays.copyOfRange(buf.array(), baseOffset, baseOffset + length);
              } else {
                  return buf.array();
              }
          }
  
          byte[] v = PlatformDependent.allocateUninitializedArray(length);
          buf.getBytes(start, v);
          return v;
      }
docs: Return an array of the underlying storage from {@code buf} into a byte array.
  The copy will start at {@code start} and copy {@code length} bytes.
  If {@code copy} is true a copy will be made of the memory.
  If {@code copy} is false the underlying storage will be shared, if possible.