当前位置: 首页>>代码示例>>Java>>正文


Java ByteBufferUtils.copyFromBufferToArray方法代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.util.ByteBufferUtils.copyFromBufferToArray方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBufferUtils.copyFromBufferToArray方法的具体用法?Java ByteBufferUtils.copyFromBufferToArray怎么用?Java ByteBufferUtils.copyFromBufferToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.hbase.util.ByteBufferUtils的用法示例。


在下文中一共展示了ByteBufferUtils.copyFromBufferToArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getKey

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
@Override
public Cell getKey() {
  assertSeeked();
  // Create a new object so that this getKey is cached as firstKey, lastKey
  ObjectIntPair<ByteBuffer> keyPair = new ObjectIntPair<>();
  blockBuffer.asSubByteBuffer(blockBuffer.position() + KEY_VALUE_LEN_SIZE, currKeyLen, keyPair);
  ByteBuffer keyBuf = keyPair.getFirst();
  if (keyBuf.hasArray()) {
    return new KeyValue.KeyOnlyKeyValue(keyBuf.array(), keyBuf.arrayOffset()
        + keyPair.getSecond(), currKeyLen);
  } else {
    // Better to do a copy here instead of holding on to this BB so that
    // we could release the blocks referring to this key. This key is specifically used
    // in HalfStoreFileReader to get the firstkey and lastkey by creating a new scanner
    // every time. So holding onto the BB (incase of DBB) is not advised here.
    byte[] key = new byte[currKeyLen];
    ByteBufferUtils.copyFromBufferToArray(key, keyBuf, keyPair.getSecond(), 0, currKeyLen);
    return new KeyValue.KeyOnlyKeyValue(key, 0, currKeyLen);
  }
}
 
开发者ID:apache,项目名称:hbase,代码行数:21,代码来源:HFileReaderImpl.java

示例2: read

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
/**
 * Reads up to next <code>len</code> bytes of data from buffer into passed array(starting from
 * given offset).
 * @param b the array into which the data is read.
 * @param off the start offset in the destination array <code>b</code>
 * @param len the maximum number of bytes to read.
 * @return the total number of bytes actually read into the buffer, or <code>-1</code> if not even
 *         1 byte can be read because the end of the stream has been reached.
 */
@Override
public int read(byte[] b, int off, int len) {
  int avail = available();
  if (avail <= 0) {
    return -1;
  }

  if (len > avail) {
    len = avail;
  }
  if (len <= 0) {
    return 0;
  }

  ByteBufferUtils.copyFromBufferToArray(b, this.buf, this.buf.position(), off, len);
  this.buf.position(this.buf.position() + len); // we should advance the buffer position
  return len;
}
 
开发者ID:apache,项目名称:hbase,代码行数:28,代码来源:ByteBufferInputStream.java

示例3: get

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
@Override
public void get(int sourceOffset, byte[] dst, int offset, int length) {
  int itemIndex = getItemIndex(sourceOffset);
  ByteBuffer item = this.items[itemIndex];
  sourceOffset = sourceOffset - this.itemBeginPos[itemIndex];
  while (length > 0) {
    int toRead = Math.min((item.limit() - sourceOffset), length);
    ByteBufferUtils.copyFromBufferToArray(dst, item, sourceOffset, offset,
        toRead);
    length -= toRead;
    if (length == 0)
      break;
    itemIndex++;
    item = this.items[itemIndex];
    offset += toRead;
    sourceOffset = 0;
  }
}
 
开发者ID:apache,项目名称:hbase,代码行数:19,代码来源:MultiByteBuff.java

示例4: asSubByteBuffer

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
/**
 * Returns bytes from current position till length specified, as a single ByteBuffer. When all
 * these bytes happen to be in a single ByteBuffer, which this object wraps, that ByteBuffer item
 * as such will be returned. So users are warned not to change the position or limit of this
 * returned ByteBuffer. The position of the returned byte buffer is at the begin of the required
 * bytes. When the required bytes happen to span across multiple ByteBuffers, this API will copy
 * the bytes to a newly created ByteBuffer of required size and return that.
 *
 * @param length number of bytes required.
 * @return bytes from current position till length specified, as a single ByteButter.
 */
@Override
public ByteBuffer asSubByteBuffer(int length) {
  if (this.curItem.remaining() >= length) {
    return this.curItem;
  }
  int offset = 0;
  byte[] dupB = new byte[length];
  int locCurItemIndex = curItemIndex;
  ByteBuffer locCurItem = curItem;
  while (length > 0) {
    int toRead = Math.min(length, locCurItem.remaining());
    ByteBufferUtils
        .copyFromBufferToArray(dupB, locCurItem, locCurItem.position(), offset, toRead);
    length -= toRead;
    if (length == 0)
      break;
    locCurItemIndex++;
    locCurItem = this.items[locCurItemIndex];
    offset += toRead;
  }
  return ByteBuffer.wrap(dupB);
}
 
开发者ID:apache,项目名称:hbase,代码行数:34,代码来源:MultiByteBuff.java

示例5: getKey

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
@Override
public Cell getKey() {
  if (current.keyBuffer.hasArray()) {
    return new KeyValue.KeyOnlyKeyValue(current.keyBuffer.array(),
        current.keyBuffer.arrayOffset() + current.keyBuffer.position(),
        current.keyLength);
  } else {
    byte[] key = new byte[current.keyLength];
    ByteBufferUtils.copyFromBufferToArray(key, current.keyBuffer,
        current.keyBuffer.position(), 0, current.keyLength);
    return new KeyValue.KeyOnlyKeyValue(key, 0, current.keyLength);
  }
}
 
开发者ID:apache,项目名称:hbase,代码行数:14,代码来源:RowIndexSeekerV1.java

示例6: getTagValuePartAsString

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
private static String getTagValuePartAsString(Tag t, int offset, int length) {
  if (t.hasArray()) {
    return Bytes.toString(t.getValueArray(), offset, length);
  }
  byte[] b = new byte[length];
  ByteBufferUtils.copyFromBufferToArray(b, t.getValueByteBuffer(), offset, 0, length);
  return Bytes.toString(b);
}
 
开发者ID:apache,项目名称:hbase,代码行数:9,代码来源:ExpAsStringVisibilityLabelServiceImpl.java

示例7: copyTagsTo

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
/**
 * Copies the tags info into the tag portion of the cell
 * @param cell
 * @param destination
 * @param destinationOffset
 * @return position after tags
 */
public static int copyTagsTo(Cell cell, byte[] destination, int destinationOffset) {
  int tlen = cell.getTagsLength();
  if (cell instanceof ByteBufferExtendedCell) {
    ByteBufferUtils
      .copyFromBufferToArray(destination, ((ByteBufferExtendedCell) cell).getTagsByteBuffer(),
        ((ByteBufferExtendedCell) cell).getTagsPosition(), destinationOffset, tlen);
  } else {
    System
      .arraycopy(cell.getTagsArray(), cell.getTagsOffset(), destination, destinationOffset, tlen);
  }
  return destinationOffset + tlen;
}
 
开发者ID:apache,项目名称:hbase,代码行数:20,代码来源:PrivateCellUtil.java

示例8: findEntry

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
@Override
public short findEntry(ByteBuffer data, int offset, int length) {
  short ret = backingStore.findIdx(data, offset, length);
  if (ret == NOT_IN_DICTIONARY) {
    byte[] copy = new byte[length];
    ByteBufferUtils.copyFromBufferToArray(copy, data, offset, 0, length);
    addEntryInternal(copy, 0, length, false);
  }
  return ret;
}
 
开发者ID:apache,项目名称:hbase,代码行数:11,代码来源:LRUDictionary.java

示例9: deepClone

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
@Override
public ExtendedCell deepClone() {
  byte[] copy = new byte[this.length];
  ByteBufferUtils.copyFromBufferToArray(copy, this.buf, this.offset, 0, this.length);
  KeyValue kv = new KeyValue(copy, 0, copy.length);
  kv.setSequenceId(this.getSequenceId());
  return kv;
}
 
开发者ID:apache,项目名称:hbase,代码行数:9,代码来源:ByteBufferKeyValue.java

示例10: copyRowTo

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
/**
 * Copies the row to the given byte[]
 * @param cell the cell whose row has to be copied
 * @param destination the destination byte[] to which the row has to be copied
 * @param destinationOffset the offset in the destination byte[]
 * @return the offset of the byte[] after the copy has happened
 */
public static int copyRowTo(Cell cell, byte[] destination, int destinationOffset) {
  short rowLen = cell.getRowLength();
  if (cell instanceof ByteBufferExtendedCell) {
    ByteBufferUtils.copyFromBufferToArray(destination,
        ((ByteBufferExtendedCell) cell).getRowByteBuffer(),
        ((ByteBufferExtendedCell) cell).getRowPosition(), destinationOffset, rowLen);
  } else {
    System.arraycopy(cell.getRowArray(), cell.getRowOffset(), destination, destinationOffset,
      rowLen);
  }
  return destinationOffset + rowLen;
}
 
开发者ID:apache,项目名称:hbase,代码行数:20,代码来源:CellUtil.java

示例11: compareTo

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
/**
 * Special compareTo method for subclasses, to avoid copying bytes unnecessarily.
 * @param value bytes to compare within a ByteBuffer
 * @param offset offset into value
 * @param length number of bytes to compare
 * @return a negative integer, zero, or a positive integer as this object
 *         is less than, equal to, or greater than the specified object.
 */
public int compareTo(ByteBuffer value, int offset, int length) {
  // For BC, providing a default implementation here which is doing a bytes copy to a temp byte[]
  // and calling compareTo(byte[]). Make sure to override this method in subclasses to avoid
  // copying bytes unnecessarily.
  byte[] temp = new byte[length];
  ByteBufferUtils.copyFromBufferToArray(temp, value, offset, 0, length);
  return compareTo(temp);
}
 
开发者ID:apache,项目名称:hbase,代码行数:17,代码来源:ByteArrayComparable.java

示例12: copyQualifierTo

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
/**
 * Copies the qualifier to the given byte[]
 * @param cell the cell whose qualifier has to be copied
 * @param destination the destination byte[] to which the qualifier has to be copied
 * @param destinationOffset the offset in the destination byte[]
 * @return the offset of the byte[] after the copy has happened
 */
public static int copyQualifierTo(Cell cell, byte[] destination, int destinationOffset) {
  int qlen = cell.getQualifierLength();
  if (cell instanceof ByteBufferExtendedCell) {
    ByteBufferUtils.copyFromBufferToArray(destination,
      ((ByteBufferExtendedCell) cell).getQualifierByteBuffer(),
      ((ByteBufferExtendedCell) cell).getQualifierPosition(), destinationOffset, qlen);
  } else {
    System.arraycopy(cell.getQualifierArray(), cell.getQualifierOffset(), destination,
      destinationOffset, qlen);
  }
  return destinationOffset + qlen;
}
 
开发者ID:apache,项目名称:hbase,代码行数:20,代码来源:CellUtil.java

示例13: cloneValue

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
/**
 * Returns tag value in a new byte array. Primarily for use client-side. If server-side, use
 * {@link Tag#getValueArray()} with appropriate {@link Tag#getValueOffset()} and
 * {@link Tag#getValueLength()} instead to save on allocations.
 * @param tag The Tag whose value to be returned
 * @return tag value in a new byte array.
 */
public static byte[] cloneValue(Tag tag) {
  int tagLength = tag.getValueLength();
  byte[] tagArr = new byte[tagLength];
  if (tag.hasArray()) {
    Bytes.putBytes(tagArr, 0, tag.getValueArray(), tag.getValueOffset(), tagLength);
  } else {
    ByteBufferUtils.copyFromBufferToArray(tagArr, tag.getValueByteBuffer(), tag.getValueOffset(),
      0, tagLength);
  }
  return tagArr;
}
 
开发者ID:apache,项目名称:hbase,代码行数:19,代码来源:Tag.java

示例14: copyValueTo

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
/**
 * Copies the tag's value bytes to the given byte array
 * @param tag The Tag
 * @param out The byte array where to copy the Tag value.
 * @param offset The offset within 'out' array where to copy the Tag value.
 */
public static void copyValueTo(Tag tag, byte[] out, int offset) {
  if (tag.hasArray()) {
    Bytes.putBytes(out, offset, tag.getValueArray(), tag.getValueOffset(), tag.getValueLength());
  } else {
    ByteBufferUtils.copyFromBufferToArray(out, tag.getValueByteBuffer(), tag.getValueOffset(),
      offset, tag.getValueLength());
  }
}
 
开发者ID:apache,项目名称:hbase,代码行数:15,代码来源:Tag.java

示例15: deepClone

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
@Override
public ExtendedCell deepClone() {
  byte[] copy = new byte[this.length];
  ByteBufferUtils.copyFromBufferToArray(copy, this.buf, this.offset, 0, this.length);
  KeyValue kv = new NoTagsKeyValue(copy, 0, copy.length);
  kv.setSequenceId(this.getSequenceId());
  return kv;
}
 
开发者ID:apache,项目名称:hbase,代码行数:9,代码来源:NoTagsByteBufferKeyValue.java


注:本文中的org.apache.hadoop.hbase.util.ByteBufferUtils.copyFromBufferToArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。