本文整理汇总了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;
}
示例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;
}
示例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;
}
};
}