b4e29bbe41d4da91404d95c89fd23c754fbdd0bc src/main/java/org/apache/hadoop/hbase/client/Result.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/org/apache/hadoop/hbase/client/Result.java b/src/main/java/org/apache/hadoop/hbase/client/Result.java index bf8bda3..e466ad1 100644 --- a/src/main/java/org/apache/hadoop/hbase/client/Result.java +++ b/src/main/java/org/apache/hadoop/hbase/client/Result.java @@ -36,6 +36,7 @@ import org.apache.hadoop.hbase.KeyValue.SplitKeyValue; import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.io.WritableWithSize; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.io.DataOutputBuffer; import org.apache.hadoop.io.Writable; /** @@ -401,6 +402,20 @@ public class Result implements Writable, WritableWithSize { * @return pointer to raw binary of Result */ public ImmutableBytesWritable getBytes() { + if (this.bytes == null && this.kvs != null) { + int totalLen = 0; + for(KeyValue kv : kvs) { + totalLen += kv.getLength() + Bytes.SIZEOF_INT; + } + DataOutputBuffer out = new DataOutputBuffer(totalLen); + try { + for(KeyValue kv : kvs) { + kv.write(out); + } + out.close(); + } catch (IOException e) { /* should never happen */ } + this.bytes = new ImmutableBytesWritable(out.getData(), 0, out.getLength()); + } return this.bytes; }