public static KeyValue create(int length, final DataInput in) throws IOException {

    if (length <= 0) {
      if (length == 0) {
        return null;
      }
      throw new IOException("Failed read " + length + " bytes, stream corrupt?");
    }

    // This is how the old Writables.readFrom used to deserialize. Didn't even vint.
    byte[] bytes = new byte[length];
    in.readFully(bytes);
    return new KeyValue(bytes, 0, length);
  }
Create a KeyValue reading <code>length</code> from <code>in</code>
@param length length of the Key
@param in     Input to read from
@return Created KeyValue OR if we find a length of zero, we will return null which can be
        useful marking a stream as done.
@throws IOException if any IO error happen
hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java