@Test public void testSplitBytes() { byte[] startRow = Bytes.toBytes("EA"); byte[] stopRow = Bytes.toBytes("EZ"); byte[][] splitPoints = Bytes.split(startRow, stopRow, 10); for (byte[] splitPoint : splitPoints) { assertTrue(Bytes.toStringBinary(splitPoint), Bytes.compareTo(startRow, splitPoint) <= 0); assertTrue(Bytes.toStringBinary(splitPoint), Bytes.compareTo(stopRow, splitPoint) >= 0); } }
public static byte[] toBytes(byte[][] byteArrays) { int size = 0; for (byte[] b : byteArrays) { if (b == null) { size++; } else { size += b.length; size += WritableUtils.getVIntSize(b.length); } } TrustedByteArrayOutputStream bytesOut = new TrustedByteArrayOutputStream(size); DataOutputStream out = new DataOutputStream(bytesOut); try { for (byte[] b : byteArrays) { if (b == null) { WritableUtils.writeVInt(out, 0); } else { WritableUtils.writeVInt(out, b.length); out.write(b); } } } catch (IOException e) { throw new RuntimeException(e); } finally { try { out.close(); } catch (IOException e) { throw new RuntimeException(e); } } return bytesOut.getBuffer(); }
ByteUtil { public static byte[] toBytes(byte[][] byteArrays) { int size = 0; for (byte[] b : byteArrays) { if (b == null) { size++; } else { size += b.length; size += WritableUtils.getVIntSize(b.length); } } TrustedByteArrayOutputStream bytesOut = new TrustedByteArrayOutputStream(size); DataOutputStream out = new DataOutputStream(bytesOut); try { for (byte[] b : byteArrays) { if (b == null) { WritableUtils.writeVInt(out, 0); } else { WritableUtils.writeVInt(out, b.length); out.write(b); } } } catch (IOException e) { throw new RuntimeException(e); } finally { try { out.close(); } catch (IOException e) { throw new RuntimeException(e); } } return bytesOut.getBuffer(); } }
ByteUtil { public static byte[] toBytes(byte[][] byteArrays) { int size = 0; for (byte[] b : byteArrays) { if (b == null) { size++; } else { size += b.length; size += WritableUtils.getVIntSize(b.length); } } TrustedByteArrayOutputStream bytesOut = new TrustedByteArrayOutputStream(size); DataOutputStream out = new DataOutputStream(bytesOut); try { for (byte[] b : byteArrays) { if (b == null) { WritableUtils.writeVInt(out, 0); } else { WritableUtils.writeVInt(out, b.length); out.write(b); } } } catch (IOException e) { throw new RuntimeException(e); } finally { try { out.close(); } catch (IOException e) { throw new RuntimeException(e); } } return bytesOut.getBuffer(); }  }
ByteUtil { public static byte[] toBytes(byte[][] byteArrays) { int size = 0; for (byte[] b : byteArrays) { if (b == null) { size++; } else { size += b.length; size += WritableUtils.getVIntSize(b.length); } } TrustedByteArrayOutputStream bytesOut = new TrustedByteArrayOutputStream(size); DataOutputStream out = new DataOutputStream(bytesOut); try { for (byte[] b : byteArrays) { if (b == null) { WritableUtils.writeVInt(out, 0); } else { WritableUtils.writeVInt(out, b.length); out.write(b); } } } catch (IOException e) { throw new RuntimeException(e); } finally { try { out.close(); } catch (IOException e) { throw new RuntimeException(e); } } return bytesOut.getBuffer(); }  static byte[] toBytes(byte[][] byteArrays); static byte[][] toByteArrays(byte[] b, int length); static byte[][] toByteArrays(byte[] b, int offset, int length); static byte[] serializeVIntArray(int[] intArray); static byte[] serializeVIntArray(int[] intArray, int encodedLength); static void serializeVIntArray(DataOutput output, int[] intArray); static void serializeVIntArray(DataOutput output, int[] intArray, int encodedLength); static long[] readFixedLengthLongArray(DataInput input, int length); static void writeFixedLengthLongArray(DataOutput output, long[] longArray); static int[] deserializeVIntArray(byte[] b); static int[] deserializeVIntArray(DataInput in); static int[] deserializeVIntArray(DataInput in, int length); static int[] deserializeVIntArray(byte[] b, int length); static byte[] concat(byte[] first, byte[]... rest); static T[] concat(T[] first, T[]... rest); static byte[] concat(ColumnModifier columnModifier, ImmutableBytesWritable... writables); static int vintFromBytes(byte[] buffer, int offset); static int vintFromBytes(ImmutableBytesWritable ptr); static long vlongFromBytes(ImmutableBytesWritable ptr); static int vintToBytes(byte[] result, int offset, final long vint); static byte[] nextKey(byte[] key); static boolean nextKey(byte[] key, int length); static boolean nextKey(byte[] key, int offset, int length); static byte[] previousKey(byte[] key); static boolean previousKey(byte[] key, int length); static boolean previousKey(byte[] key, int offset, int length); static byte[] fillKey(byte[] key, int length); static int getSize(CharSequence sequence); static boolean isInclusive(CompareOp op); static boolean compare(CompareOp op, int compareResult); static byte[] copyKeyBytesIfNecessary(ImmutableBytesWritable ptr); static KeyRange getKeyRange(byte[] key, CompareOp op, PDataType type); }
ByteUtil { public static byte[] toBytes(byte[][] byteArrays) { int size = 0; for (byte[] b : byteArrays) { if (b == null) { size++; } else { size += b.length; size += WritableUtils.getVIntSize(b.length); } } TrustedByteArrayOutputStream bytesOut = new TrustedByteArrayOutputStream(size); DataOutputStream out = new DataOutputStream(bytesOut); try { for (byte[] b : byteArrays) { if (b == null) { WritableUtils.writeVInt(out, 0); } else { WritableUtils.writeVInt(out, b.length); out.write(b); } } } catch (IOException e) { throw new RuntimeException(e); } finally { try { out.close(); } catch (IOException e) { throw new RuntimeException(e); } } return bytesOut.getBuffer(); }  static byte[] toBytes(byte[][] byteArrays); static byte[][] toByteArrays(byte[] b, int length); static byte[][] toByteArrays(byte[] b, int offset, int length); static byte[] serializeVIntArray(int[] intArray); static byte[] serializeVIntArray(int[] intArray, int encodedLength); static void serializeVIntArray(DataOutput output, int[] intArray); static void serializeVIntArray(DataOutput output, int[] intArray, int encodedLength); static long[] readFixedLengthLongArray(DataInput input, int length); static void writeFixedLengthLongArray(DataOutput output, long[] longArray); static int[] deserializeVIntArray(byte[] b); static int[] deserializeVIntArray(DataInput in); static int[] deserializeVIntArray(DataInput in, int length); static int[] deserializeVIntArray(byte[] b, int length); static byte[] concat(byte[] first, byte[]... rest); static T[] concat(T[] first, T[]... rest); static byte[] concat(ColumnModifier columnModifier, ImmutableBytesWritable... writables); static int vintFromBytes(byte[] buffer, int offset); static int vintFromBytes(ImmutableBytesWritable ptr); static long vlongFromBytes(ImmutableBytesWritable ptr); static int vintToBytes(byte[] result, int offset, final long vint); static byte[] nextKey(byte[] key); static boolean nextKey(byte[] key, int length); static boolean nextKey(byte[] key, int offset, int length); static byte[] previousKey(byte[] key); static boolean previousKey(byte[] key, int length); static boolean previousKey(byte[] key, int offset, int length); static byte[] fillKey(byte[] key, int length); static int getSize(CharSequence sequence); static boolean isInclusive(CompareOp op); static boolean compare(CompareOp op, int compareResult); static byte[] copyKeyBytesIfNecessary(ImmutableBytesWritable ptr); static KeyRange getKeyRange(byte[] key, CompareOp op, PDataType type); static final byte[] EMPTY_BYTE_ARRAY; static final ImmutableBytesPtr EMPTY_BYTE_ARRAY_PTR; static final Comparator<ImmutableBytesPtr> BYTES_PTR_COMPARATOR; }