public static void copyFromBufferToBuffer(ByteBuffer in, ByteBuffer out, int sourceOffset,
    int length) {
    if (in.hasArray() && out.hasArray()) {
      System.arraycopy(in.array(), sourceOffset + in.arrayOffset(), out.array(),
        out.position() + out.arrayOffset(), length);
      skip(out, length);
    } else if (UNSAFE_AVAIL) {
      UnsafeAccess.copy(in, sourceOffset, out, out.position(), length);
      skip(out, length);
    } else {
      ByteBuffer inDup = in.duplicate();
      inDup.position(sourceOffset).limit(sourceOffset + length);
      out.put(inDup);
    }
  }
Copy from one buffer to another from given offset.
<p>
Note : This will advance the position marker of {@code out} but not change the position maker
for {@code in}
@param in           source buffer
@param out          destination buffer
@param sourceOffset offset in the source buffer
@param length       how many bytes to copy
hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferUtils.java