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

The following are Jave code examples for showing how to use getBytes() 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: HFileReaderV2.java   View Source Code Vote up 5 votes
@Override
public boolean seekBefore(Cell key) throws IOException {
  HFileBlock seekToBlock = reader.getDataBlockIndexReader().seekToDataBlock(key, block,
      cacheBlocks, pread, isCompaction,
      ((HFileReaderV2) reader).getEffectiveEncodingInCache(isCompaction));
  if (seekToBlock == null) {
    return false;
  }
  ByteBuffer firstKey = getFirstKeyInBlock(seekToBlock);

  if (reader.getComparator()
      .compareOnlyKeyPortion(
          new KeyValue.KeyOnlyKeyValue(firstKey.array(), firstKey.arrayOffset(),
              firstKey.limit()), key) >= 0) {
    long previousBlockOffset = seekToBlock.getPrevBlockOffset();
    // The key we are interested in
    if (previousBlockOffset == -1) {
      // we have a 'problem', the key we want is the first of the file.
      return false;
    }

    // It is important that we compute and pass onDiskSize to the block
    // reader so that it does not have to read the header separately to
    // figure out the size.  Currently, we do not have a way to do this
    // correctly in the general case however.
    // TODO: See https://issues.apache.org/jira/browse/HBASE-14576
    int prevBlockSize = -1;
    seekToBlock = reader.readBlock(previousBlockOffset,
        prevBlockSize, cacheBlocks,
        pread, isCompaction, true, BlockType.DATA, getEffectiveDataBlockEncoding());
    // TODO shortcut: seek forward in this block to the last key of the
    // block.
  }
  Cell firstKeyInCurrentBlock = new KeyValue.KeyOnlyKeyValue(Bytes.getBytes(firstKey));
  loadBlockAndSeekToKey(seekToBlock, firstKeyInCurrentBlock, true, key, true);
  return true;
}