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


Java ByteBufferUtil.arrayCopy方法代码示例

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


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

示例1: markLocalToBeCleared

import org.apache.cassandra.utils.ByteBufferUtil; //导入方法依赖的package包/类
/**
 * Mark context to delete local references afterward.
 * Marking is done by multiply #elt by -1 to preserve header length
 * and #elt count in order to clear all local refs later.
 *
 * @param context a counter context
 * @return context that marked to delete local refs
 */
public ByteBuffer markLocalToBeCleared(ByteBuffer context)
{
    short count = context.getShort(context.position());
    if (count <= 0)
        return context; // already marked or all are remote.

    boolean hasLocalShards = false;
    for (int i = 0; i < count; i++)
    {
        if (context.getShort(context.position() + HEADER_SIZE_LENGTH + i * HEADER_ELT_LENGTH) >= 0)
        {
            hasLocalShards = true;
            break;
        }
    }

    if (!hasLocalShards)
        return context; // all shards are global or remote.

    ByteBuffer marked = ByteBuffer.allocate(context.remaining());
    marked.putShort(marked.position(), (short) (count * -1));
    ByteBufferUtil.arrayCopy(context,
                             context.position() + HEADER_SIZE_LENGTH,
                             marked,
                             marked.position() + HEADER_SIZE_LENGTH,
                             context.remaining() - HEADER_SIZE_LENGTH);
    return marked;
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:37,代码来源:CounterContext.java

示例2: clearAllLocal

import org.apache.cassandra.utils.ByteBufferUtil; //导入方法依赖的package包/类
/**
 * Remove all the local of a context (but keep global).
 *
 * @param context a counter context
 * @return a version of {@code context} where no shards are local.
 */
public ByteBuffer clearAllLocal(ByteBuffer context)
{
    int count = Math.abs(context.getShort(context.position()));
    if (count == 0)
        return context; // no local or global shards present.

    List<Short> globalShardIndexes = new ArrayList<>(count);
    for (int i = 0; i < count; i++)
    {
        short elt = context.getShort(context.position() + HEADER_SIZE_LENGTH + i * HEADER_ELT_LENGTH);
        if (elt < 0)
            globalShardIndexes.add(elt);
    }

    if (count == globalShardIndexes.size())
        return context; // no local shards detected.

    // allocate a smaller BB for the cleared context - with no local header elts.
    ByteBuffer cleared = ByteBuffer.allocate(context.remaining() - (count - globalShardIndexes.size()) * HEADER_ELT_LENGTH);

    cleared.putShort(cleared.position(), (short) globalShardIndexes.size());
    for (int i = 0; i < globalShardIndexes.size(); i++)
        cleared.putShort(cleared.position() + HEADER_SIZE_LENGTH + i * HEADER_ELT_LENGTH, globalShardIndexes.get(i));

    int origHeaderLength = headerLength(context);
    ByteBufferUtil.arrayCopy(context,
                             context.position() + origHeaderLength,
                             cleared,
                             cleared.position() + headerLength(cleared),
                             context.remaining() - origHeaderLength);

    return cleared;
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:40,代码来源:CounterContext.java

示例3: newDefaultChannel

import org.apache.cassandra.utils.ByteBufferUtil; //导入方法依赖的package包/类
protected WritableByteChannel newDefaultChannel()
{
    return new WritableByteChannel()
    {

        @Override
        public boolean isOpen()
        {
            return true;
        }

        @Override
        public void close()
        {
        }

        @Override
        public int write(ByteBuffer src) throws IOException
        {
            int toWrite = src.remaining();

            if (src.hasArray())
            {
                DataOutputStreamPlus.this.write(src.array(), src.arrayOffset() + src.position(), src.remaining());
                src.position(src.limit());
                return toWrite;
            }

            if (toWrite < 16)
            {
                int offset = src.position();
                for (int i = 0 ; i < toWrite ; i++)
                    DataOutputStreamPlus.this.write(src.get(i + offset));
                src.position(src.limit());
                return toWrite;
            }

            byte[] buf = retrieveTemporaryBuffer(toWrite);

            int totalWritten = 0;
            while (totalWritten < toWrite)
            {
                int toWriteThisTime = Math.min(buf.length, toWrite - totalWritten);

                ByteBufferUtil.arrayCopy(src, src.position() + totalWritten, buf, 0, toWriteThisTime);

                DataOutputStreamPlus.this.write(buf, 0, toWriteThisTime);

                totalWritten += toWriteThisTime;
            }

            src.position(src.limit());
            return totalWritten;
        }

    };
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:58,代码来源:DataOutputStreamPlus.java


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