Search in sources :

Example 16 with HazelcastSerializationException

use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.

the class DataSerializableSerializer method readInternal.

private DataSerializable readInternal(ObjectDataInput in, Class aClass) throws IOException {
    DataSerializable ds = null;
    if (null != aClass) {
        try {
            ds = (DataSerializable) aClass.newInstance();
        } catch (Exception e) {
            throw new HazelcastSerializationException("Requested class " + aClass + " could not be instantiated.", e);
        }
    }
    final byte header = in.readByte();
    int id = 0;
    int factoryId = 0;
    String className = null;
    try {
        // BasicOperationService::extractOperationCallId
        if (isFlagSet(header, IDS_FLAG)) {
            factoryId = in.readInt();
            final DataSerializableFactory dsf = factories.get(factoryId);
            if (dsf == null) {
                throw new HazelcastSerializationException("No DataSerializerFactory registered for namespace: " + factoryId);
            }
            id = in.readInt();
            if (null == aClass) {
                ds = dsf.create(id);
                if (ds == null) {
                    throw new HazelcastSerializationException(dsf + " is not be able to create an instance for id: " + id + " on factoryId: " + factoryId);
                }
            }
        } else {
            className = in.readUTF();
            if (null == aClass) {
                ds = ClassLoaderUtil.newInstance(in.getClassLoader(), className);
            }
        }
        if (isFlagSet(header, EE_FLAG)) {
            in.readByte();
            in.readByte();
        }
        ds.readData(in);
        return ds;
    } catch (Exception e) {
        throw rethrowReadException(id, factoryId, className, e);
    }
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) DataSerializableFactory(com.hazelcast.nio.serialization.DataSerializableFactory) IdentifiedDataSerializable(com.hazelcast.nio.serialization.IdentifiedDataSerializable) TypedDataSerializable(com.hazelcast.nio.serialization.TypedDataSerializable) DataSerializable(com.hazelcast.nio.serialization.DataSerializable) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) IOException(java.io.IOException)

Example 17 with HazelcastSerializationException

use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.

the class PortableNavigatorContext method initFinalPositionAndOffset.

/**
     * Initialises the finalPosition and offset and validates the fieldCount against the given class definition
     */
private void initFinalPositionAndOffset(BufferObjectDataInput in, ClassDefinition cd) {
    int fieldCount;
    try {
        // final position after portable is read
        finalPosition = in.readInt();
        fieldCount = in.readInt();
    } catch (IOException e) {
        throw new HazelcastSerializationException(e);
    }
    if (fieldCount != cd.getFieldCount()) {
        throw new IllegalStateException("Field count[" + fieldCount + "] in stream does not match " + cd);
    }
    offset = in.position();
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) IOException(java.io.IOException)

Aggregations

HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)17 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)5 IOException (java.io.IOException)3 SerializationUtil.createSerializerAdapter (com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)2 BufferObjectDataInput (com.hazelcast.nio.BufferObjectDataInput)2 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)2 DataSerializableFactory (com.hazelcast.nio.serialization.DataSerializableFactory)2 FieldDefinition (com.hazelcast.nio.serialization.FieldDefinition)2 Portable (com.hazelcast.nio.serialization.Portable)2 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)2 Serializer (com.hazelcast.nio.serialization.Serializer)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)1 SerializerConfig (com.hazelcast.config.SerializerConfig)1 HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)1 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 InputOutputFactory (com.hazelcast.internal.serialization.InputOutputFactory)1 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 SerializationUtil.isNullData (com.hazelcast.internal.serialization.impl.SerializationUtil.isNullData)1