public static ByteBuffer convertKvToByteBuffer(List<KeyValue> keyValues,
    boolean includesMemstoreTS) {
    int totalSize = 0;
    for (KeyValue kv : keyValues) {
      totalSize += kv.getLength();
      if (includesMemstoreTS) {
        totalSize += WritableUtils.getVIntSize(kv.getSequenceId());
      }
    }

    ByteBuffer result = ByteBuffer.allocate(totalSize);
    for (KeyValue kv : keyValues) {
      result.put(kv.getBuffer(), kv.getOffset(), kv.getLength());
      if (includesMemstoreTS) {
        ByteBufferUtils.writeVLong(result, kv.getSequenceId());
      }
    }
    return result;
  }
Convert list of KeyValues to byte buffer.
@param keyValues list of KeyValues to be converted.
@return buffer with content from key values
hbase-common/src/test/java/org/apache/hadoop/hbase/util/RedundantKVGenerator.java