Search in sources :

Example 16 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast-jet by hazelcast.

the class HashSetHook method createSerializer.

@Override
@SuppressWarnings("checkstyle:anoninnerlength")
public Serializer createSerializer() {
    return new StreamSerializer<HashSet>() {

        @Override
        public int getTypeId() {
            return SerializerHookConstants.HASH_SET;
        }

        @Override
        public void destroy() {
        }

        @Override
        @SuppressWarnings("checkstyle:illegaltype")
        public void write(ObjectDataOutput out, HashSet set) throws IOException {
            out.writeInt(set.size());
            for (Object o : set) {
                out.writeObject(o);
            }
        }

        @Override
        @SuppressWarnings("checkstyle:illegaltype")
        public HashSet read(ObjectDataInput in) throws IOException {
            int length = in.readInt();
            HashSet set = new HashSet();
            for (int i = 0; i < length; i++) {
                // noinspection unchecked
                set.add(in.readObject());
            }
            return set;
        }
    };
}
Also used : ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) StreamSerializer(com.hazelcast.nio.serialization.StreamSerializer) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) HashSet(java.util.HashSet)

Example 17 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast by hazelcast.

the class Employee method readPortable.

public void readPortable(PortableReader reader) throws IOException {
    name = reader.readString("n");
    age = reader.readInt("a");
    by = reader.readByte("b");
    c = reader.readChar("c");
    bool = reader.readBoolean("bo");
    s = reader.readShort("s");
    i = reader.readInt("i");
    l = reader.readLong("l");
    f = reader.readFloat("f");
    d = reader.readDouble("d");
    str = reader.readString("str");
    utfStr = reader.readString("utfstr");
    byteArray = reader.readByteArray("bb");
    charArray = reader.readCharArray("cc");
    boolArray = reader.readBooleanArray("ba");
    shortArray = reader.readShortArray("ss");
    integerArray = reader.readIntArray("ii");
    floatArray = reader.readFloatArray("ff");
    doubleArray = reader.readDoubleArray("dd");
    ObjectDataInput in = reader.getRawDataInput();
    by = (Byte) in.readObject();
    c = (Character) in.readObject();
    bool = (Boolean) in.readObject();
    s = (Short) in.readObject();
    i = (Integer) in.readObject();
    f = (Float) in.readObject();
    d = (Double) in.readObject();
    str = (String) in.readObject();
    utfStr = (String) in.readObject();
}
Also used : ObjectDataInput(com.hazelcast.nio.ObjectDataInput)

Example 18 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast by hazelcast.

the class CompactInternalGenericRecord method getNullableInt16.

@Nullable
@Override
public Short getNullableInt16(@Nonnull String fieldName) {
    FieldDescriptor fd = getFieldDefinition(fieldName);
    FieldKind fieldKind = fd.getKind();
    switch(fieldKind) {
        case INT16:
            try {
                return in.readShort(readFixedSizePosition(fd));
            } catch (IOException e) {
                throw illegalStateException(e);
            }
        case NULLABLE_INT16:
            return getVariableSize(fd, ObjectDataInput::readShort);
        default:
            throw unexpectedFieldKind(fieldKind, fieldName);
    }
}
Also used : FieldKind(com.hazelcast.nio.serialization.FieldKind) IOException(java.io.IOException) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) Nullable(javax.annotation.Nullable)

Example 19 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast by hazelcast.

the class CompactInternalGenericRecord method getInt64.

@Override
public long getInt64(@Nonnull String fieldName) {
    FieldDescriptor fd = getFieldDefinition(fieldName);
    FieldKind fieldKind = fd.getKind();
    switch(fieldKind) {
        case INT64:
            try {
                return in.readLong(readFixedSizePosition(fd));
            } catch (IOException e) {
                throw illegalStateException(e);
            }
        case NULLABLE_INT64:
            return getVariableSizeAsNonNull(fd, ObjectDataInput::readLong, "Int64");
        default:
            throw unexpectedFieldKind(fieldKind, fieldName);
    }
}
Also used : FieldKind(com.hazelcast.nio.serialization.FieldKind) IOException(java.io.IOException) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) ObjectDataInput(com.hazelcast.nio.ObjectDataInput)

Example 20 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast by hazelcast.

the class CompactInternalGenericRecord method getInt16.

@Override
public short getInt16(@Nonnull String fieldName) {
    FieldDescriptor fd = getFieldDefinition(fieldName);
    FieldKind fieldKind = fd.getKind();
    switch(fieldKind) {
        case INT16:
            try {
                return in.readShort(readFixedSizePosition(fd));
            } catch (IOException e) {
                throw illegalStateException(e);
            }
        case NULLABLE_INT16:
            return getVariableSizeAsNonNull(fd, ObjectDataInput::readShort, "Int16");
        default:
            throw unexpectedFieldKind(fieldKind, fieldName);
    }
}
Also used : FieldKind(com.hazelcast.nio.serialization.FieldKind) IOException(java.io.IOException) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) ObjectDataInput(com.hazelcast.nio.ObjectDataInput)

Aggregations

ObjectDataInput (com.hazelcast.nio.ObjectDataInput)80 Test (org.junit.Test)35 QuickTest (com.hazelcast.test.annotation.QuickTest)32 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)24 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)17 FieldKind (com.hazelcast.nio.serialization.FieldKind)16 IOException (java.io.IOException)13 ObjectDataOutput (com.hazelcast.nio.ObjectDataOutput)12 Nullable (javax.annotation.Nullable)9 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)7 SerializationConfig (com.hazelcast.config.SerializationConfig)6 StreamSerializer (com.hazelcast.nio.serialization.StreamSerializer)6 Data (com.hazelcast.nio.serialization.Data)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Data (com.hazelcast.internal.serialization.Data)3 SerializationService (com.hazelcast.internal.serialization.SerializationService)3 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)3 HeapData (com.hazelcast.internal.serialization.impl.HeapData)3 SerializationService (com.hazelcast.spi.serialization.SerializationService)3 SerializerConfig (com.hazelcast.config.SerializerConfig)2