Java Code Examples for org.apache.hadoop.hbase.util.Bytes#toByteArrays()

The following examples show how to use org.apache.hadoop.hbase.util.Bytes#toByteArrays() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestByteUtil.java    From hraven with Apache License 2.0 6 votes vote down vote up
@Test
public void testSplitWithLimit() {
  // source with more splits than the limit
  byte[][] expectedResult = Bytes.toByteArrays(new String[] {"random", "stuff::"});
  byte[][] splitResult = ByteUtil.split(source2, sep2, 2);
  assertSplitResult(expectedResult, splitResult);

  // source with fewer splits than the limit
  expectedResult = Bytes.toByteArrays(new String[] {"random", "stuff", ""});
  splitResult = ByteUtil.split(source2, sep2, 100);
  assertSplitResult(expectedResult, splitResult);

  // source with limit of 1
  expectedResult = new byte[][] {source2};
  splitResult = ByteUtil.split(source2, sep2, 1);
  assertSplitResult(expectedResult, splitResult);
}
 
Example 2
Source File: TestByteUtil.java    From hraven with Apache License 2.0 5 votes vote down vote up
@Test
public void testSplit() {
  // single byte separator
  byte[][] expected1 = Bytes
      .toByteArrays(new String[] { "abc", "bcd", "cde" });

  byte[][] splitresult = ByteUtil.split(source1, sep1);
  assertSplitResult(expected1, splitresult);

  // multi-byte separator, plus trailing separator
  byte[][] expected2 = Bytes.toByteArrays(new String[] { "random", "stuff",
      "" });
  splitresult = ByteUtil.split(source2, sep2);
  assertSplitResult(expected2, splitresult);

  // leading and trailing separator
  byte[][] expected3 = Bytes.toByteArrays(new String[] { "", "more", "stuff",
      "" });
  splitresult = ByteUtil.split(source3, sep3);
  assertSplitResult(expected3, splitresult);

  // source with no separator
  byte[][] expected4 = Bytes.toByteArrays(new String[] { "singlesource" });
  splitresult = ByteUtil.split(source4, sep4);
  assertSplitResult(expected4, splitresult);

  // source with empty component
  byte[][] expected5 =
      Bytes.toByteArrays(new String[]{ "abc", "", "bcd"});
  splitresult = ByteUtil.split(source5, sep5);
  assertSplitResult(expected5, splitresult);

  byte[][] expected6 = new byte[][] {source6};
  splitresult = ByteUtil.split(source6, sep6);
  assertSplitResult(expected6, splitresult);
}
 
Example 3
Source File: TestHBaseStorage.java    From spork with Apache License 2.0 2 votes vote down vote up
/**
 * Helper to deal with fetching a result based on a cf:colname string spec
 * @param result
 * @param colName
 * @return
 */
private static byte[] getColValue(Result result, String colName) {
    byte[][] colArray = Bytes.toByteArrays(colName.split(":"));
    return result.getValue(colArray[0], colArray[1]);

}