use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.
the class BinaryUtils method doReadDecimalArray.
/**
* @return Value.
* @throws BinaryObjectException In case of error.
*/
public static BigDecimal[] doReadDecimalArray(BinaryInputStream in) throws BinaryObjectException {
int len = in.readInt();
BigDecimal[] arr = new BigDecimal[len];
for (int i = 0; i < len; i++) {
byte flag = in.readByte();
if (flag == GridBinaryMarshaller.NULL)
arr[i] = null;
else {
if (flag != GridBinaryMarshaller.DECIMAL)
throw new BinaryObjectException("Invalid flag value: " + flag);
arr[i] = doReadDecimal(in);
}
}
return arr;
}
use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.
the class BinaryContext method descriptorForTypeId.
/**
* @param userType User type or not.
* @param typeId Type ID.
* @param ldr Class loader.
* @return Class descriptor.
*/
public BinaryClassDescriptor descriptorForTypeId(boolean userType, int typeId, ClassLoader ldr, boolean deserialize) {
assert typeId != GridBinaryMarshaller.UNREGISTERED_TYPE_ID;
//TODO: As a workaround for IGNITE-1358 we always check the predefined map before without checking 'userType'
BinaryClassDescriptor desc = predefinedTypes.get(typeId);
if (desc != null)
return desc;
if (ldr == null)
ldr = sysLdr;
Class cls;
try {
cls = marshCtx.getClass(typeId, ldr);
desc = descByCls.get(cls);
} catch (ClassNotFoundException e) {
// Class might have been loaded by default class loader.
if (userType && !ldr.equals(sysLdr) && (desc = descriptorForTypeId(true, typeId, sysLdr, deserialize)) != null)
return desc;
throw new BinaryInvalidTypeException(e);
} catch (IgniteCheckedException e) {
// Class might have been loaded by default class loader.
if (userType && !ldr.equals(sysLdr) && (desc = descriptorForTypeId(true, typeId, sysLdr, deserialize)) != null)
return desc;
throw new BinaryObjectException("Failed resolve class for ID: " + typeId, e);
}
if (desc == null) {
desc = registerClassDescriptor(cls, deserialize);
assert desc.typeId() == typeId : "Duplicate typeId [typeId=" + typeId + ", cls=" + cls + ", desc=" + desc + "]";
}
return desc;
}
use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.
the class BinaryReaderExImpl method findFieldByName.
/**
* Try finding the field by name.
*
* @param name Field name.
* @return Offset.
*/
public boolean findFieldByName(String name) {
if (raw)
throw new BinaryObjectException("Failed to read named field because reader is in raw mode.");
assert dataStart != start;
if (footerLen == 0)
return false;
if (userType) {
int order;
if (matching) {
int expOrder = matchingOrder++;
BinarySchema.Confirmation confirm = schema.confirmOrder(expOrder, name);
switch(confirm) {
case CONFIRMED:
// The best case: got order without ID calculation and (ID -> order) lookup.
if (expOrder == 0)
// When we read the very first field, position is set to start, hence this re-positioning.
streamPosition(dataStart);
return true;
case REJECTED:
// Rejected, no more speculations are possible. Fallback to the slowest scenario.
matching = false;
order = schema.order(fieldId(name));
break;
default:
// Field name is not know for this order. Need to calculate ID and repeat speculation.
assert confirm == BinarySchema.Confirmation.CLARIFY;
int id = fieldId(name);
int realId = schema.fieldId(expOrder);
if (id == realId) {
// IDs matched, cache field name inside schema.
schema.clarifyFieldName(expOrder, name);
if (expOrder == 0)
streamPosition(dataStart);
return true;
} else {
// No match, stop further speculations.
matching = false;
order = schema.order(id);
}
break;
}
} else
order = schema.order(fieldId(name));
return trySetUserFieldPosition(order);
} else
return trySetSystemFieldPosition(fieldId(name));
}
use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.
the class BinaryReaderExImpl method rawReader.
/** {@inheritDoc} */
@Override
public BinaryRawReader rawReader() {
if (!raw) {
streamPositionRandom(rawOff);
raw = true;
return this;
} else
throw new BinaryObjectException("Method \"rawReader\" can be called only once.");
}
use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.
the class BinaryEnumArrayLazyValue method init.
/** {@inheritDoc} */
@Override
protected Object init() {
reader.position(valOff + 1);
//skipping component type id
reader.readInt();
int size = reader.readInt();
BinaryBuilderEnum[] res = new BinaryBuilderEnum[size];
for (int i = 0; i < size; i++) {
byte flag = reader.readByte();
if (flag == GridBinaryMarshaller.NULL)
continue;
if (flag != GridBinaryMarshaller.ENUM)
throw new BinaryObjectException("Invalid flag value: " + flag);
res[i] = new BinaryBuilderEnum(reader);
}
return res;
}
Aggregations