本文整理汇总了Java中org.apache.cassandra.utils.ByteBufferUtil.readBytes方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBufferUtil.readBytes方法的具体用法?Java ByteBufferUtil.readBytes怎么用?Java ByteBufferUtil.readBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.cassandra.utils.ByteBufferUtil
的用法示例。
在下文中一共展示了ByteBufferUtil.readBytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import org.apache.cassandra.utils.ByteBufferUtil; //导入方法依赖的package包/类
@Override
public void validate(ByteBuffer bytes) throws MarshalException
{
ByteBuffer bb = bytes.duplicate();
readIsStatic(bb);
int i = 0;
ByteBuffer previous = null;
while (bb.remaining() > 0)
{
AbstractType<?> comparator = validateComparator(i, bb);
if (bb.remaining() < 2)
throw new MarshalException("Not enough bytes to read value size of component " + i);
int length = ByteBufferUtil.readShortLength(bb);
if (bb.remaining() < length)
throw new MarshalException("Not enough bytes to read value of component " + i);
ByteBuffer value = ByteBufferUtil.readBytes(bb, length);
comparator.validateCollectionMember(value, previous);
if (bb.remaining() == 0)
throw new MarshalException("Not enough bytes to read the end-of-component byte of component" + i);
byte b = bb.get();
if (b != 0 && bb.remaining() != 0)
throw new MarshalException("Invalid bytes remaining after an end-of-component at component" + i);
previous = value;
++i;
}
}
示例2: readValue
import org.apache.cassandra.utils.ByteBufferUtil; //导入方法依赖的package包/类
public static ByteBuffer readValue(ByteBuffer input, ProtocolVersion version)
{
int size = input.getInt();
if (size < 0)
return null;
return ByteBufferUtil.readBytes(input, size);
}
示例3: validateComparator
import org.apache.cassandra.utils.ByteBufferUtil; //导入方法依赖的package包/类
protected AbstractType<?> validateComparator(int i, ByteBuffer bb) throws MarshalException
{
AbstractType<?> comparator = null;
if (bb.remaining() < 2)
throw new MarshalException("Not enough bytes to header of the comparator part of component " + i);
int header = ByteBufferUtil.readShortLength(bb);
if ((header & 0x8000) == 0)
{
if (bb.remaining() < header)
throw new MarshalException("Not enough bytes to read comparator name of component " + i);
ByteBuffer value = ByteBufferUtil.readBytes(bb, header);
String valueStr = null;
try
{
valueStr = ByteBufferUtil.string(value);
comparator = TypeParser.parse(valueStr);
}
catch (CharacterCodingException ce)
{
// ByteBufferUtil.string failed.
// Log it here and we'll further throw an exception below since comparator == null
logger.error("Failed with [{}] when decoding the byte buffer in ByteBufferUtil.string()",
ce.toString());
}
catch (Exception e)
{
// parse failed.
// Log it here and we'll further throw an exception below since comparator == null
logger.error("Failed to parse value string \"{}\" with exception: [{}]",
valueStr, e.toString());
}
}
else
{
comparator = aliases.get((byte)(header & 0xFF));
}
if (comparator == null)
throw new MarshalException("Cannot find comparator for component " + i);
else
return comparator;
}