Search in sources :

Example 26 with BinaryObjectException

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);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ByteArrayInputStream(java.io.ByteArrayInputStream) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 27 with BinaryObjectException

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;
}
Also used : BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 28 with BinaryObjectException

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;
}
Also used : Date(java.util.Date) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 29 with BinaryObjectException

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);
}
Also used : BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 30 with BinaryObjectException

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;
}
Also used : BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Aggregations

BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)42 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)9 BinaryObject (org.apache.ignite.binary.BinaryObject)8 Date (java.util.Date)4 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 TreeMap (java.util.TreeMap)4 BinarySerializer (org.apache.ignite.binary.BinarySerializer)4 BinaryType (org.apache.ignite.binary.BinaryType)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 BigInteger (java.math.BigInteger)2 Time (java.sql.Time)2 Timestamp (java.sql.Timestamp)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 BinaryBasicIdMapper (org.apache.ignite.binary.BinaryBasicIdMapper)2 BinaryInvalidTypeException (org.apache.ignite.binary.BinaryInvalidTypeException)2 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)2 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)2 BinaryEnumObjectImpl (org.apache.ignite.internal.binary.BinaryEnumObjectImpl)2