public static byte[] toBytes(ByteBuffer buffer, int offset, int length) {
    byte[] output = new byte[length];
    for (int i = 0; i < length; i++) {
      output[i] = buffer.get(offset + i);
    }
    return output;
  }
Copy the given number of bytes from specified offset into a new byte[]
@param buffer input bytebuffer to read
@param offset input offset where Bytes are
@param length the number of bytes to read
@return a new byte[] containing the bytes in the specified range
hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferUtils.java