You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by me...@apache.org on 2012/11/13 02:13:35 UTC
svn commit: r1408529 - in /accumulo/trunk/core/src:
main/java/org/apache/accumulo/core/data/Mutation.java
test/java/org/apache/accumulo/core/data/MutationTest.java
Author: medined
Date: Tue Nov 13 01:13:34 2012
New Revision: 1408529
URL: http://svn.apache.org/viewvc?rev=1408529&view=rev
Log:
ACCUMULO-851: Add Mutation Constructor Accepting Byte Array.
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/data/Mutation.java
accumulo/trunk/core/src/test/java/org/apache/accumulo/core/data/MutationTest.java
Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/data/Mutation.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/data/Mutation.java?rev=1408529&r1=1408528&r2=1408529&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/data/Mutation.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/data/Mutation.java Tue Nov 13 01:13:34 2012
@@ -199,6 +199,16 @@ public class Mutation implements Writabl
}
}
+ public Mutation(byte[] byteBuffer) {
+ this(byteBuffer, 0, byteBuffer.length);
+ }
+
+ public Mutation(byte[] byteBuffer, int start, int length) {
+ this.row = new byte[length];
+ System.arraycopy(byteBuffer, start, this.row, 0, length);
+ buffer = new ByteBuffer();
+ }
+
public Mutation(Text row) {
this.row = new byte[row.getLength()];
System.arraycopy(row.getBytes(), 0, this.row, 0, row.getLength());
Modified: accumulo/trunk/core/src/test/java/org/apache/accumulo/core/data/MutationTest.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/test/java/org/apache/accumulo/core/data/MutationTest.java?rev=1408529&r1=1408528&r2=1408529&view=diff
==============================================================================
--- accumulo/trunk/core/src/test/java/org/apache/accumulo/core/data/MutationTest.java (original)
+++ accumulo/trunk/core/src/test/java/org/apache/accumulo/core/data/MutationTest.java Tue Nov 13 01:13:34 2012
@@ -31,6 +31,28 @@ import org.apache.hadoop.io.Text;
public class MutationTest extends TestCase {
+ private static String toHexString(byte[] ba) {
+ StringBuilder str = new StringBuilder();
+ for (int i = 0; i < ba.length; i++) {
+ str.append(String.format("%x", ba[i]));
+ }
+ return str.toString();
+ }
+
+ /* Test constructing a Mutation using a byte buffer. The byte array
+ * returned as the row is converted to a hexadecimal string for easy
+ * comparision.
+ */
+ public void testByteConstructor() {
+ Mutation m = new Mutation("0123456789".getBytes());
+ assertEquals("30313233343536373839", toHexString(m.getRow()));
+ }
+
+ public void testLimitedByteConstructor() {
+ Mutation m = new Mutation("0123456789".getBytes(), 2, 5);
+ assertEquals("3233343536", toHexString(m.getRow()));
+ }
+
public void test1() {
Mutation m = new Mutation(new Text("r1"));
m.put(new Text("cf1"), new Text("cq1"), new Value("v1".getBytes()));