Java Code Examples for org.apache.hadoop.hbase.util.PositionedByteRange#getOffset()

The following examples show how to use org.apache.hadoop.hbase.util.PositionedByteRange#getOffset() . 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: FixedLengthWrapper.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public int encode(PositionedByteRange dst, T val) {
  if (dst.getRemaining() < length) {
    throw new IllegalArgumentException("Not enough buffer remaining. dst.offset: "
        + dst.getOffset() + " dst.length: " + dst.getLength() + " dst.position: "
        + dst.getPosition() + " max length: " + length);
  }
  int written = base.encode(dst, val);
  if (written > length) {
    throw new IllegalArgumentException("Length of encoded value (" + written
        + ") exceeds max length (" + length + ").");
  }
  // TODO: is the zero-padding appropriate?
  for (; written < length; written++) {
    dst.put((byte) 0x00);
  }
  return written;
}
 
Example 2
Source File: TerminatedWrapper.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Return the position at which {@code term} begins within {@code src},
 * or {@code -1} if {@code term} is not found.
 */
protected int terminatorPosition(PositionedByteRange src) {
  byte[] a = src.getBytes();
  final int offset = src.getOffset();
  int i;
  SKIP: for (i = src.getPosition(); i < src.getLength(); i++) {
    if (a[offset + i] != term[0]) {
      continue;
    }
    int j;
    for (j = 1; j < term.length && offset + j < src.getLength(); j++) {
      if (a[offset + i + j] != term[j]) {
        continue SKIP;
      }
    }
    if (j == term.length) {
      return i; // success
    }
  }
  return -1;
}
 
Example 3
Source File: FixedLengthWrapper.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public T decode(PositionedByteRange src) {
  if (src.getRemaining() < length) {
    throw new IllegalArgumentException("Not enough buffer remaining. src.offset: "
        + src.getOffset() + " src.length: " + src.getLength() + " src.position: "
        + src.getPosition() + " max length: " + length);
  }
  // create a copy range limited to length bytes. boo.
  PositionedByteRange b = new SimplePositionedMutableByteRange(length);
  src.get(b.getBytes());
  return base.decode(b);
}
 
Example 4
Source File: RawByte.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public Byte decode(PositionedByteRange src) {
  byte val = src.getBytes()[src.getOffset() + src.getPosition()];
  skip(src);
  return val;
}