public static long write(final KeyValue kv, final DataOutput out) throws IOException {
    // This is how the old Writables write used to serialize KVs. Need to figure way to make it
    // work for all implementations.
    int length = kv.getLength();
    out.writeInt(length);
    out.write(kv.getBuffer(), kv.getOffset(), length);
    return (long) length + Bytes.SIZEOF_INT;
  }
Write out a KeyValue in the manner in which we used to when KeyValue was a Writable.
@param kv  the KeyValue on which write is being requested
@param out OutputStream to write keyValue to
@return Length written on stream
@throws IOException if any IO error happen
@see #create(DataInput) for the inverse function
hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java