accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From medi...@apache.org
Subject svn commit: r1408900 - /accumulo/trunk/core/src/main/java/org/apache/accumulo/core/data/Mutation.java
Date Tue, 13 Nov 2012 19:20:00 GMT
Author: medined
Date: Tue Nov 13 19:19:59 2012
New Revision: 1408900

URL: http://svn.apache.org/viewvc?rev=1408900&view=rev
Log:
ACCUMULO-851: Add Mutation Constructor Accepting Byte Array. Followup to have put() use byte
arrays too.

Modified:
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/data/Mutation.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=1408900&r1=1408899&r2=1408900&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 19:19:59 2012
@@ -27,7 +27,6 @@ import java.util.List;
 import org.apache.accumulo.core.data.thrift.TMutation;
 import org.apache.accumulo.core.security.ColumnVisibility;
 import org.apache.accumulo.core.util.ByteBufferUtil;
-import org.apache.accumulo.core.util.TextUtil;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.io.WritableUtils;
@@ -87,12 +86,6 @@ public class Mutation implements Writabl
       
     }
     
-    void add(byte[] b) {
-      reserve(b.length);
-      System.arraycopy(b, 0, data, offset, b.length);
-      offset += b.length;
-    }
-    
     public void add(byte[] bytes, int off, int length) {
       reserve(length);
       System.arraycopy(bytes, off, data, offset, length);
@@ -238,14 +231,20 @@ public class Mutation implements Writabl
     return row;
   }
   
+  public 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();
+  }
+
   private void put(byte b[]) {
-    buffer.writeVLong(b.length);
-    buffer.add(b);
+    put(b, b.length);
   }
   
-  private void put(Text t) {
-    buffer.writeVLong(t.getLength());
-    buffer.add(t.getBytes(), 0, t.getLength());
+  private void put(byte b[], int length) {
+    buffer.writeVLong(length);
+    buffer.add(b, 0, length);
   }
   
   private void put(boolean b) {
@@ -260,24 +259,36 @@ public class Mutation implements Writabl
     buffer.writeVLong(l);
   }
   
+  private void put(byte[] cf, byte[] cq, byte[] cv, boolean hasts, long ts, boolean deleted,
byte[] val) {
+    put(cf, cf.length, cq, cq.length, cv, hasts, ts, deleted, val);
+  }
+
+  /*
+   * When dealing with Text object the length must be gotten from the object, not from the
byte array.
+   */
   private void put(Text cf, Text cq, byte[] cv, boolean hasts, long ts, boolean deleted,
byte[] val) {
-    
-    if (buffer == null)
+    put(cf.getBytes(), cf.getLength(), cq.getBytes(), cq.getLength(), cv, hasts, ts, deleted,
val);
+  }
+  
+  private void put(byte[] cf, int cfLength, byte[] cq, int cqLength, byte[] cv, boolean hasts,
long ts, boolean deleted, byte[] val) {
+    if (buffer == null) {
       throw new IllegalStateException("Can not add to mutation after serializing it");
-    
-    put(cf);
-    put(cq);
+    }
+    put(cf, cfLength);
+    put(cq, cqLength);
     put(cv);
     put(hasts);
-    if (hasts)
+    if (hasts) {
       put(ts);
+    }
     put(deleted);
     
     if (val.length < VALUE_SIZE_COPY_CUTOFF) {
       put(val);
     } else {
-      if (values == null)
+      if (values == null) {
         values = new ArrayList<byte[]>();
+      }
       byte copy[] = new byte[val.length];
       System.arraycopy(val, 0, copy, 0, val.length);
       values.add(copy);
@@ -287,14 +298,6 @@ public class Mutation implements Writabl
     entries++;
   }
   
-  private void put(CharSequence cf, CharSequence cq, byte[] cv, boolean hasts, long ts, boolean
deleted, byte[] val) {
-    put(new Text(cf.toString()), new Text(cq.toString()), cv, hasts, ts, deleted, val);
-  }
-  
-  private void put(CharSequence cf, CharSequence cq, byte[] cv, boolean hasts, long ts, boolean
deleted, CharSequence val) {
-    put(cf, cq, cv, hasts, ts, deleted, TextUtil.getBytes(new Text(val.toString())));
-  }
-  
   public void put(Text columnFamily, Text columnQualifier, Value value) {
     put(columnFamily, columnQualifier, EMPTY_BYTES, false, 0l, false, value.get());
   }
@@ -328,51 +331,51 @@ public class Mutation implements Writabl
   }
   
   public void put(CharSequence columnFamily, CharSequence columnQualifier, Value value) {
-    put(columnFamily, columnQualifier, EMPTY_BYTES, false, 0l, false, value.get());
+    put(columnFamily.toString().getBytes(), columnQualifier.toString().getBytes(), EMPTY_BYTES,
false, 0l, false, value.get());
   }
   
   public void put(CharSequence columnFamily, CharSequence columnQualifier, ColumnVisibility
columnVisibility, Value value) {
-    put(columnFamily, columnQualifier, columnVisibility.getExpression(), false, 0l, false,
value.get());
+    put(columnFamily.toString().getBytes(), columnQualifier.toString().getBytes(), columnVisibility.getExpression(),
false, 0l, false, value.get());
   }
   
   public void put(CharSequence columnFamily, CharSequence columnQualifier, long timestamp,
Value value) {
-    put(columnFamily, columnQualifier, EMPTY_BYTES, true, timestamp, false, value.get());
+    put(columnFamily.toString().getBytes(), columnQualifier.toString().getBytes(), EMPTY_BYTES,
true, timestamp, false, value.get());
   }
   
   public void put(CharSequence columnFamily, CharSequence columnQualifier, ColumnVisibility
columnVisibility, long timestamp, Value value) {
-    put(columnFamily, columnQualifier, columnVisibility.getExpression(), true, timestamp,
false, value.get());
+    put(columnFamily.toString().getBytes(), columnQualifier.toString().getBytes(), columnVisibility.getExpression(),
true, timestamp, false, value.get());
   }
   
   public void putDelete(CharSequence columnFamily, CharSequence columnQualifier) {
-    put(columnFamily, columnQualifier, EMPTY_BYTES, false, 0l, true, EMPTY_BYTES);
+    put(columnFamily.toString().getBytes(), columnQualifier.toString().getBytes(), EMPTY_BYTES,
false, 0l, true, EMPTY_BYTES);
   }
   
   public void putDelete(CharSequence columnFamily, CharSequence columnQualifier, ColumnVisibility
columnVisibility) {
-    put(columnFamily, columnQualifier, columnVisibility.getExpression(), false, 0l, true,
EMPTY_BYTES);
+    put(columnFamily.toString().getBytes(), columnQualifier.toString().getBytes(), columnVisibility.getExpression(),
false, 0l, true, EMPTY_BYTES);
   }
   
   public void putDelete(CharSequence columnFamily, CharSequence columnQualifier, long timestamp)
{
-    put(columnFamily, columnQualifier, EMPTY_BYTES, true, timestamp, true, EMPTY_BYTES);
+    put(columnFamily.toString().getBytes(), columnQualifier.toString().getBytes(), EMPTY_BYTES,
true, timestamp, true, EMPTY_BYTES);
   }
   
   public void putDelete(CharSequence columnFamily, CharSequence columnQualifier, ColumnVisibility
columnVisibility, long timestamp) {
-    put(columnFamily, columnQualifier, columnVisibility.getExpression(), true, timestamp,
true, EMPTY_BYTES);
+    put(columnFamily.toString().getBytes(), columnQualifier.toString().getBytes(), columnVisibility.getExpression(),
true, timestamp, true, EMPTY_BYTES);
   }
   
   public void put(CharSequence columnFamily, CharSequence columnQualifier, CharSequence value)
{
-    put(columnFamily, columnQualifier, EMPTY_BYTES, false, 0l, false, value);
+    put(columnFamily.toString().getBytes(), columnQualifier.toString().getBytes(), EMPTY_BYTES,
false, 0l, false, value.toString().getBytes());
   }
   
   public void put(CharSequence columnFamily, CharSequence columnQualifier, ColumnVisibility
columnVisibility, CharSequence value) {
-    put(columnFamily, columnQualifier, columnVisibility.getExpression(), false, 0l, false,
value);
+    put(columnFamily.toString().getBytes(), columnQualifier.toString().getBytes(), columnVisibility.getExpression(),
false, 0l, false, value.toString().getBytes());
   }
   
   public void put(CharSequence columnFamily, CharSequence columnQualifier, long timestamp,
CharSequence value) {
-    put(columnFamily, columnQualifier, EMPTY_BYTES, true, timestamp, false, value);
+    put(columnFamily.toString().getBytes(), columnQualifier.toString().getBytes(), EMPTY_BYTES,
true, timestamp, false, value.toString().getBytes());
   }
   
   public void put(CharSequence columnFamily, CharSequence columnQualifier, ColumnVisibility
columnVisibility, long timestamp, CharSequence value) {
-    put(columnFamily, columnQualifier, columnVisibility.getExpression(), true, timestamp,
false, value);
+    put(columnFamily.toString().getBytes(), columnQualifier.toString().getBytes(), columnVisibility.getExpression(),
true, timestamp, false, value.toString().getBytes());
   }
   
   private byte[] oldReadBytes(SimpleReader in) {



Mime
View raw message