Java Code Examples for org.apache.hadoop.hbase.KeyValue#KEYVALUE_WITH_TAGS_INFRASTRUCTURE_SIZE

The following examples show how to use org.apache.hadoop.hbase.KeyValue#KEYVALUE_WITH_TAGS_INFRASTRUCTURE_SIZE . 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: WALCellCodec.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
protected Cell parseCell() throws IOException {
  int keylength = StreamUtils.readRawVarint32(in);
  int vlength = StreamUtils.readRawVarint32(in);

  int tagsLength = StreamUtils.readRawVarint32(in);
  int length = 0;
  if(tagsLength == 0) {
    length = KeyValue.KEYVALUE_INFRASTRUCTURE_SIZE + keylength + vlength;
  } else {
    length = KeyValue.KEYVALUE_WITH_TAGS_INFRASTRUCTURE_SIZE + keylength + vlength + tagsLength;
  }

  byte[] backingArray = new byte[length];
  int pos = 0;
  pos = Bytes.putInt(backingArray, pos, keylength);
  pos = Bytes.putInt(backingArray, pos, vlength);

  // the row
  int elemLen = readIntoArray(backingArray, pos + Bytes.SIZEOF_SHORT,
    compression.getDictionary(CompressionContext.DictionaryIndex.ROW));
  checkLength(elemLen, Short.MAX_VALUE);
  pos = Bytes.putShort(backingArray, pos, (short)elemLen);
  pos += elemLen;

  // family
  elemLen = readIntoArray(backingArray, pos + Bytes.SIZEOF_BYTE,
    compression.getDictionary(CompressionContext.DictionaryIndex.FAMILY));
  checkLength(elemLen, Byte.MAX_VALUE);
  pos = Bytes.putByte(backingArray, pos, (byte)elemLen);
  pos += elemLen;

  // qualifier
  elemLen = readIntoArray(backingArray, pos,
    compression.getDictionary(CompressionContext.DictionaryIndex.QUALIFIER));
  pos += elemLen;

  // timestamp, type and value
  int tsTypeValLen = length - pos;
  if (tagsLength > 0) {
    tsTypeValLen = tsTypeValLen - tagsLength - KeyValue.TAGS_LENGTH_SIZE;
  }
  IOUtils.readFully(in, backingArray, pos, tsTypeValLen);
  pos += tsTypeValLen;

  // tags
  if (tagsLength > 0) {
    pos = Bytes.putAsShort(backingArray, pos, tagsLength);
    if (compression.tagCompressionContext != null) {
      compression.tagCompressionContext.uncompressTags(in, backingArray, pos, tagsLength);
    } else {
      IOUtils.readFully(in, backingArray, pos, tagsLength);
    }
  }
  return new KeyValue(backingArray, 0, length);
}