public static void copyFromBufferToArray(byte[] out, ByteBuffer in, int sourceOffset,
    int destinationOffset, int length) {
    if (in.hasArray()) {
      System.arraycopy(in.array(), sourceOffset + in.arrayOffset(), out, destinationOffset, length);
    } else if (UNSAFE_AVAIL) {
      UnsafeAccess.copy(in, sourceOffset, out, destinationOffset, length);
    } else {
      ByteBuffer inDup = in.duplicate();
      inDup.position(sourceOffset);
      inDup.get(out, destinationOffset, length);
    }
  }
Copies specified number of bytes from given offset of 'in' ByteBuffer to the array. This
doesn't affect the position of buffer.
@param out               output array to copy input bytebuffer to
@param in                input bytebuffer to copy from
@param sourceOffset      offset of source bytebuffer
@param destinationOffset offset of destination array
@param length            the number of bytes to copy
hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferUtils.java