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

The following examples show how to use org.apache.hadoop.hbase.util.PositionedByteRange#getRemaining() . 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: LabelConnectionModel.java    From hgraphdb with Apache License 2.0 5 votes vote down vote up
public byte[] serialize(String outVertexLabel, String edgeLabel, String inVertexLabel) {
    PositionedByteRange buffer = new DynamicPositionedMutableByteRange(4096);
    OrderedBytes.encodeString(buffer, outVertexLabel, Order.ASCENDING);
    OrderedBytes.encodeString(buffer, edgeLabel, Order.ASCENDING);
    OrderedBytes.encodeString(buffer, inVertexLabel, Order.ASCENDING);
    buffer.setLength(buffer.getPosition());
    buffer.setPosition(0);
    byte[] bytes = new byte[buffer.getRemaining()];
    buffer.get(bytes);
    return bytes;
}
 
Example 3
Source File: IndexMetadataModel.java    From hgraphdb with Apache License 2.0 5 votes vote down vote up
public byte[] serialize(IndexMetadata.Key index) {
    PositionedByteRange buffer = new DynamicPositionedMutableByteRange(4096);
    OrderedBytes.encodeString(buffer, index.label(), Order.ASCENDING);
    OrderedBytes.encodeString(buffer, index.propertyKey(), Order.ASCENDING);
    OrderedBytes.encodeInt8(buffer, index.type() == ElementType.VERTEX ? (byte) 1 : (byte) 0, Order.ASCENDING);
    buffer.setLength(buffer.getPosition());
    buffer.setPosition(0);
    byte[] bytes = new byte[buffer.getRemaining()];
    buffer.get(bytes);
    return bytes;
}
 
Example 4
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 5
Source File: RawString.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public String decode(PositionedByteRange src) {
  if (Order.ASCENDING == this.order) {
    // avoid unnecessary array copy for ASC case.
    String val =
        Bytes.toString(src.getBytes(), src.getOffset() + src.getPosition(), src.getRemaining());
    src.setPosition(src.getLength());
    return val;
  } else {
    byte[] b = new byte[src.getRemaining()];
    src.get(b);
    order.apply(b, 0, b.length);
    return Bytes.toString(b);
  }
}
 
Example 6
Source File: RawString.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public int skip(PositionedByteRange src) {
  int skipped = src.getRemaining();
  src.setPosition(src.getLength());
  return skipped;
}
 
Example 7
Source File: RawBytes.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public int skip(PositionedByteRange src) {
  int skipped = src.getRemaining();
  src.setPosition(src.getLength());
  return skipped;
}