use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.
the class BinaryUtils method doReadOptimized.
/**
* Read object serialized using optimized marshaller.
*
* @return Result.
*/
public static Object doReadOptimized(BinaryInputStream in, BinaryContext ctx, @Nullable ClassLoader clsLdr) {
int len = in.readInt();
ByteArrayInputStream input = new ByteArrayInputStream(in.array(), in.position(), len);
try {
return ctx.optimizedMarsh().unmarshal(input, U.resolveClassLoader(clsLdr, ctx.configuration()));
} catch (IgniteCheckedException e) {
throw new BinaryObjectException("Failed to unmarshal object with optimized marshaller", e);
} finally {
in.position(in.position() + len);
}
}
use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.
the class BinaryUtils method doReadStringArray.
/**
* @return Value.
* @throws BinaryObjectException In case of error.
*/
public static String[] doReadStringArray(BinaryInputStream in) throws BinaryObjectException {
int len = in.readInt();
String[] arr = new String[len];
for (int i = 0; i < len; i++) {
byte flag = in.readByte();
if (flag == GridBinaryMarshaller.NULL)
arr[i] = null;
else {
if (flag != GridBinaryMarshaller.STRING)
throw new BinaryObjectException("Invalid flag value: " + flag);
arr[i] = doReadString(in);
}
}
return arr;
}
use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.
the class BinaryUtils method doReadDateArray.
/**
* @return Value.
* @throws BinaryObjectException In case of error.
*/
public static Date[] doReadDateArray(BinaryInputStream in) throws BinaryObjectException {
int len = in.readInt();
Date[] arr = new Date[len];
for (int i = 0; i < len; i++) {
byte flag = in.readByte();
if (flag == GridBinaryMarshaller.NULL)
arr[i] = null;
else {
if (flag != GridBinaryMarshaller.DATE)
throw new BinaryObjectException("Invalid flag value: " + flag);
arr[i] = doReadDate(in);
}
}
return arr;
}
use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.
the class BinaryUtils method utf8BytesToStr.
/**
* Reconstructs string from UTF-8 bytes.
*
* @param arr array Byte array.
* @param off offset Offset in the array.
* @param len length Byte array lenght.
* @return string Resulting string.
*/
public static String utf8BytesToStr(byte[] arr, int off, int len) {
int c, charArrCnt = 0, total = off + len;
int c2, c3;
char[] res = new char[len];
// try reading ascii
while (off < total) {
c = (int) arr[off] & 0xff;
if (c > 127)
break;
off++;
res[charArrCnt++] = (char) c;
}
// read other
while (off < total) {
c = (int) arr[off] & 0xff;
switch(c >> 4) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
/* 0xxxxxxx*/
off++;
res[charArrCnt++] = (char) c;
break;
case 12:
case 13:
/* 110x xxxx 10xx xxxx*/
off += 2;
if (off > total)
throw new BinaryObjectException("Malformed input: partial character at end");
c2 = (int) arr[off - 1];
if ((c2 & 0xC0) != 0x80)
throw new BinaryObjectException("Malformed input around byte: " + off);
res[charArrCnt++] = (char) (((c & 0x1F) << 6) | (c2 & 0x3F));
break;
case 14:
/* 1110 xxxx 10xx xxxx 10xx xxxx */
off += 3;
if (off > total)
throw new BinaryObjectException("Malformed input: partial character at end");
c2 = (int) arr[off - 2];
c3 = (int) arr[off - 1];
if (((c2 & 0xC0) != 0x80) || ((c3 & 0xC0) != 0x80))
throw new BinaryObjectException("Malformed input around byte: " + (off - 1));
res[charArrCnt++] = (char) (((c & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F));
break;
default:
/* 10xx xxxx, 1111 xxxx */
throw new BinaryObjectException("Malformed input around byte: " + off);
}
}
return len == charArrCnt ? new String(res) : new String(res, 0, charArrCnt);
}
use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.
the class BinaryEnumObjectImpl method enumName.
/** {@inheritDoc} */
@Override
public String enumName() throws BinaryObjectException {
BinaryMetadata metadata = ctx.metadata0(typeId);
if (metadata == null)
throw new BinaryObjectException("Failed to get metadata for enum [typeId=" + typeId + ", typeName='" + clsName + "', ordinal=" + ord + "]");
String name = metadata.getEnumNameByOrdinal(ord);
if (name == null)
throw new BinaryObjectException("Unable to resolve enum constant name [typeId=" + typeId + ", typeName='" + metadata.typeName() + "', ordinal=" + ord + "]");
return name;
}
Aggregations