hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1381670 - in /hbase/trunk/hbase-common/src: main/java/org/apache/hadoop/hbase/util/Bytes.java test/java/org/apache/hadoop/hbase/util/TestBytes.java
Date Thu, 06 Sep 2012 16:37:07 GMT
Author: stack
Date: Thu Sep  6 16:37:07 2012
New Revision: 1381670

URL: http://svn.apache.org/viewvc?rev=1381670&view=rev
Log:
HBASE-6352 Add copy method in Bytes

Modified:
    hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
    hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java

Modified: hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java?rev=1381670&r1=1381669&r2=1381670&view=diff
==============================================================================
--- hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java (original)
+++ hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java Thu Sep
 6 16:37:07 2012
@@ -1655,5 +1655,17 @@ public class Bytes {
 
     return toString(b, 0, n);
   }
-
+  
+  /**
+   * Copy the byte array given in parameter and return an instance 
+   * of a new byte array with the same length and the same content.
+   * @param bytes the byte array to duplicate
+   * @return a copy of the given byte array 
+   */
+  public static byte [] copy(byte [] bytes) {
+    if (bytes == null) return null;
+    byte [] result = new byte[bytes.length];
+    System.arraycopy(bytes, 0, result, 0, bytes.length);	  
+    return result;
+  }
 }

Modified: hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java?rev=1381670&r1=1381669&r2=1381670&view=diff
==============================================================================
--- hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java (original)
+++ hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java Thu
Sep  6 16:37:07 2012
@@ -283,5 +283,12 @@ public class TestBytes extends TestCase 
     assertEquals("World", Bytes.readStringFixedSize(dis, 18));
     assertEquals("", Bytes.readStringFixedSize(dis, 9));
   }
+  
+  public void testCopy() throws Exception {
+    byte [] bytes = Bytes.toBytes("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
+    byte [] copy =  Bytes.copy(bytes);
+    assertFalse(bytes == copy);
+    assertTrue(Bytes.equals(bytes, copy));
+  }
 }
 



Mime
View raw message