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

The following examples show how to use org.apache.hadoop.hbase.util.PositionedByteRange#getPosition() . 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: TerminatedWrapper.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Skip {@code src}'s position forward over one encoded value.
 * @param src the buffer containing the encoded value.
 * @return number of bytes skipped.
 * @throws IllegalArgumentException when the terminator sequence is not found.
 */
@Override
public int skip(PositionedByteRange src) {
  if (wrapped.isSkippable()) {
    int ret = wrapped.skip(src);
    src.setPosition(src.getPosition() + term.length);
    return ret + term.length;
  } else {
    // find the terminator position
    final int start = src.getPosition();
    int skipped = terminatorPosition(src);
    if (-1 == skipped) {
      throw new IllegalArgumentException("Terminator sequence not found.");
    }
    skipped += term.length;
    src.setPosition(skipped);
    return skipped - start;
  }
}
 
Example 4
Source File: PDataType.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public int encode(PositionedByteRange pbr, T val) {
  // default implementation based on existing PDataType methods.
  int pos = pbr.getPosition();
  pbr.put(toBytes(val));
  return pbr.getPosition() - pos;
}
 
Example 5
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 6
Source File: TerminatedWrapper.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Write instance {@code val} into buffer {@code dst}.
 * @throws IllegalArgumentException when the encoded representation of
 *           {@code val} contains the {@code term} sequence.
 */
@Override
public int encode(PositionedByteRange dst, T val) {
  final int start = dst.getPosition();
  int written = wrapped.encode(dst, val);
  PositionedByteRange b = dst.shallowCopy();
  b.setLength(dst.getPosition());
  b.setPosition(start);
  if (-1 != terminatorPosition(b)) {
    dst.setPosition(start);
    throw new IllegalArgumentException("Encoded value contains terminator sequence.");
  }
  dst.put(term);
  return written + term.length;
}
 
Example 7
Source File: PDataType.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public int encode(PositionedByteRange pbr, T val) {
    // default implementation based on existing PDataType methods.
    int pos = pbr.getPosition();
    pbr.put(toBytes(val));
    return pbr.getPosition() - pos;
}
 
Example 8
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;
}