Index: src/java/org/apache/hadoop/hbase/util/Bytes.java
===================================================================
--- src/java/org/apache/hadoop/hbase/util/Bytes.java (revision 740185)
+++ src/java/org/apache/hadoop/hbase/util/Bytes.java (working copy)
@@ -6,6 +6,7 @@
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.Comparator;
+import java.math.BigInteger;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.io.WritableComparator;
@@ -305,8 +306,102 @@
return result;
}
+ /**
+ * @param a
+ * @param length
+ * @return First length bytes from a
+ */
+ public static byte [] head(final byte [] a, final int length) {
+ if(a.length < length) return null;
+ byte [] result = new byte[length];
+ System.arraycopy(a, 0, result, 0, length);
+ return result;
+ }
/**
+ * @param a
+ * @param length
+ * @return Last length bytes from a
+ */
+ public static byte [] tail(final byte [] a, final int length) {
+ if(a.length < length) return null;
+ byte [] result = new byte[length];
+ System.arraycopy(a, a.length - length, result, 0, length);
+ return result;
+ }
+
+ /**
+ * @param a
+ * @param length
+ * @return Value in a plus length prepended 0 bytes
+ */
+ public static byte [] padHead(final byte [] a, final int length) {
+ byte [] padding = new byte[length];
+ for(int i=0;ia plus length appended 0 bytes
+ */
+ public static byte [] padTail(final byte [] a, final int length) {
+ byte [] padding = new byte[length];
+ for(int i=0;i 1) return null;
+ if(num <= 0) return null;
+
+ BigInteger startBI = new BigInteger(padHead(aPadded,1));
+ BigInteger stopBI = new BigInteger(padHead(bPadded,1));
+ BigInteger diffBI = stopBI.subtract(startBI);
+ BigInteger splitsBI = BigInteger.valueOf((long)(num+1));
+
+ if(diffBI.compareTo(splitsBI) <= 0) return null;
+
+ BigInteger intervalBI = null;
+ try {
+ intervalBI = diffBI.divide(splitsBI);
+ } catch(Exception e) {
+ return null;
+ }
+
+ byte [][] result = new byte[num+2][];
+ result[0] = a;
+
+ for(int i=1;i<=num;i++) {
+ BigInteger curBI = startBI.add(intervalBI.multiply(BigInteger.valueOf((long)i)));
+ byte [] padded = curBI.toByteArray();
+ result[i] = Bytes.tail(padded,padded.length-1);
+ }
+ result[num+1] = b;
+ return result;
+ }
+
+ /**
* @param t
* @return Array of byte arrays made from passed array of Text
*/