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

The following are Jave code examples for showing how to use copy() of the org.apache.hadoop.hbase.util.Bytes class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ditb   File: IntegrationTestBigLinkedList.java   View Source Code Vote up 6 votes
private static CINode getCINode(Result result, CINode node) {
  node.key = Bytes.copy(result.getRow());
  if (result.containsColumn(FAMILY_NAME, COLUMN_PREV)) {
    node.prev = Bytes.copy(result.getValue(FAMILY_NAME, COLUMN_PREV));
  } else {
    node.prev = NO_KEY;
  }
  if (result.containsColumn(FAMILY_NAME, COLUMN_COUNT)) {
    node.count = Bytes.toLong(result.getValue(FAMILY_NAME, COLUMN_COUNT));
  } else {
    node.count = -1;
  }
  if (result.containsColumn(FAMILY_NAME, COLUMN_CLIENT)) {
    node.client = Bytes.toString(result.getValue(FAMILY_NAME, COLUMN_CLIENT));
  } else {
    node.client = "";
  }
  return node;
}
 
Example 2
Project: stroom-stats   File: ColumnQualifier.java   View Source Code Vote up 5 votes
public byte[] getBytes() {
    if (bytes.length == ARRAY_LENGTH) {
        return bytes;
    } else {
        return Bytes.copy(bytes, offset, ARRAY_LENGTH);
    }
}
 
Example 3
Project: stroom-stats   File: UID.java   View Source Code Vote up 5 votes
/**
 * @return A copy of the UID part of the backing array unless the UID part is all of the array,
 * in which case a reference to the backing array is returned
 */
public byte[] getUidBytes() {
    if (bytes.length == UID_ARRAY_LENGTH) {
        return  bytes;
    } else {
        return Bytes.copy(bytes, offset, UID_ARRAY_LENGTH);
    }
}
 
Example 4
Project: ditb   File: TestFromClientSide.java   View Source Code Vote up 5 votes
/**
 * Tests reversed scan under multi regions
 */
@Test
public void testSmallReversedScanUnderMultiRegions() throws Exception {
  // Test Initialization.
  TableName TABLE = TableName.valueOf("testSmallReversedScanUnderMultiRegions");
  byte[][] splitRows = new byte[][]{
      Bytes.toBytes("000"), Bytes.toBytes("002"), Bytes.toBytes("004"),
      Bytes.toBytes("006"), Bytes.toBytes("008"), Bytes.toBytes("010")};
  HTable table = TEST_UTIL.createTable(TABLE, FAMILY, splitRows);
  TEST_UTIL.waitUntilAllRegionsAssigned(table.getName());

  assertEquals(splitRows.length + 1, table.getRegionLocations().size());
  for (byte[] splitRow : splitRows) {
    Put put = new Put(splitRow);
    put.add(FAMILY, QUALIFIER, VALUE);
    table.put(put);

    byte[] nextRow = Bytes.copy(splitRow);
    nextRow[nextRow.length - 1]++;

    put = new Put(nextRow);
    put.add(FAMILY, QUALIFIER, VALUE);
    table.put(put);
  }

  // scan forward
  ResultScanner scanner = table.getScanner(new Scan());
  int count = 0;
  for (Result r : scanner) {
    assertTrue(!r.isEmpty());
    count++;
  }
  assertEquals(12, count);

  reverseScanTest(table, false);
  reverseScanTest(table, true);

  table.close();
}
 
Example 5
Project: ditb   File: Put.java   View Source Code Vote up 5 votes
/**
 * We make a copy of the passed in row key to keep local.
 * @param rowArray
 * @param rowOffset
 * @param rowLength
 * @param ts
 */
public Put(byte [] rowArray, int rowOffset, int rowLength, long ts) {
  checkRow(rowArray, rowOffset, rowLength);
  this.row = Bytes.copy(rowArray, rowOffset, rowLength);
  this.ts = ts;
  if (ts < 0) {
    throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + ts);
  }
}
 
Example 6
Project: ditb   File: RowMutations.java   View Source Code Vote up 4 votes
/**
 * Create an atomic mutation for the specified row.
 * @param row row key
 */
public RowMutations(byte [] row) {
  Mutation.checkRow(row);
  this.row = Bytes.copy(row);
}
 
Example 7
Project: ditb   File: Delete.java   View Source Code Vote up 2 votes
/**
 * Create a Delete operation for the specified row and timestamp.<p>
 *
 * If no further operations are done, this will delete all columns in all
 * families of the specified row with a timestamp less than or equal to the
 * specified timestamp.<p>
 *
 * This timestamp is ONLY used for a delete row operation.  If specifying
 * families or columns, you must specify each timestamp individually.
 * @param rowArray We make a local copy of this passed in row.
 * @param rowOffset
 * @param rowLength
 * @param ts maximum version timestamp (only for delete row)
 */
public Delete(final byte [] rowArray, final int rowOffset, final int rowLength, long ts) {
  checkRow(rowArray, rowOffset, rowLength);
  this.row = Bytes.copy(rowArray, rowOffset, rowLength);
  setTimestamp(ts);
}
 
Example 8
Project: ditb   File: Append.java   View Source Code Vote up 2 votes
/** Create a Append operation for the specified row.
 * <p>
 * At least one column must be appended to.
 * @param rowArray Makes a copy out of this buffer.
 * @param rowOffset
 * @param rowLength
 */
public Append(final byte [] rowArray, final int rowOffset, final int rowLength) {
  checkRow(rowArray, rowOffset, rowLength);
  this.row = Bytes.copy(rowArray, rowOffset, rowLength);
}
 
Example 9
Project: ditb   File: Increment.java   View Source Code Vote up 2 votes
/**
 * Create a Increment operation for the specified row.
 * <p>
 * At least one column must be incremented.
 * @param row row key (we will make a copy of this).
 */
public Increment(final byte [] row, final int offset, final int length) {
  checkRow(row, offset, length);
  this.row = Bytes.copy(row, offset, length);
}