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;
}