diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCell.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCell.java index 73fbf674dc1..d4913262ac8 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCell.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/ExtendedCell.java @@ -54,7 +54,7 @@ public interface ExtendedCell extends RawCell, HeapSize, Cloneable { PrivateCellUtil.writeFlatKey(this, out); // Value - out.write(getValueArray()); + out.write(getValueArray(), getValueOffset(), getValueLength()); // Tags length and tags byte array if (withTags && getTagsLength() > 0) { diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestIndividualBytesFieldCell.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestIndividualBytesFieldCell.java index f98c68e8654..9abf90843e8 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestIndividualBytesFieldCell.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestIndividualBytesFieldCell.java @@ -252,4 +252,24 @@ public class TestIndividualBytesFieldCell { assertEquals(cell.getSerializedSize(true), buf.length); } } + + @Test + public void testWriteValue() throws IOException { + byte[] value = Bytes.toBytes("---value---"); + int valueOffset = 3; + int valueLength = 5; + IndividualBytesFieldCell cell + = new IndividualBytesFieldCell(Bytes.toBytes("row"), 0, 3, + Bytes.toBytes("family"), 0, 6, + Bytes.toBytes("qualifier"), 0, 9, + 0L, KeyValue.Type.Put, 0, + value, valueOffset, valueLength, + Bytes.toBytes("value"), 0, 5); + + try (ByteArrayOutputStream output = new ByteArrayOutputStream(300)) { + cell.write(output, true); + byte[] buf = output.toByteArray(); + assertEquals(cell.getSerializedSize(true), buf.length); + } + } }