use of com.hazelcast.nio.ObjectDataOutput in project hazelcast by hazelcast.
the class ReplicatedMapEntries method writePortable.
@Override
public void writePortable(PortableWriter writer) throws IOException {
int size = size();
writer.writeInt("size", size);
ObjectDataOutput out = writer.getRawDataOutput();
for (int i = 0; i < size; i++) {
out.writeData(keys.get(i));
out.writeData(values.get(i));
}
}
use of com.hazelcast.nio.ObjectDataOutput in project hazelcast by hazelcast.
the class ReplicatedMapKeys method writePortable.
@Override
public void writePortable(PortableWriter writer) throws IOException {
writer.writeInt("size", keys.size());
ObjectDataOutput out = writer.getRawDataOutput();
for (Data key : keys) {
out.writeData(key);
}
}
use of com.hazelcast.nio.ObjectDataOutput in project hazelcast by hazelcast.
the class MigrationListenerAdapterTest method test_migrationEvent_serialization.
@Test
public void test_migrationEvent_serialization() throws IOException {
final MigrationEvent event = new MigrationEvent(0, null, null, STARTED);
final ObjectDataOutput output = mock(ObjectDataOutput.class);
event.writeData(output);
verify(output).writeInt(0);
verify(output, times(2)).writeObject(null);
verify(output).writeByte(0);
}
use of com.hazelcast.nio.ObjectDataOutput in project hazelcast by hazelcast.
the class SerializationTest method testGlobalSerializer_withoutOverrideJavaSerializable.
@Test
public void testGlobalSerializer_withoutOverrideJavaSerializable() {
GlobalSerializerConfig globalSerializerConfig = new GlobalSerializerConfig();
globalSerializerConfig.setOverrideJavaSerialization(false);
final AtomicInteger writeCounter = new AtomicInteger();
final AtomicInteger readCounter = new AtomicInteger();
SerializationConfig serializationConfig = new SerializationConfig().setGlobalSerializerConfig(globalSerializerConfig.setImplementation(new StreamSerializer<Object>() {
@Override
public void write(ObjectDataOutput out, Object v) throws IOException {
writeCounter.incrementAndGet();
out.writeUTF(((DummyValue) v).s);
out.writeInt(((DummyValue) v).k);
}
@Override
public Object read(ObjectDataInput in) throws IOException {
readCounter.incrementAndGet();
return new DummyValue(in.readUTF(), in.readInt());
}
public int getTypeId() {
return 123;
}
public void destroy() {
}
}));
SerializationService ss1 = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
DummyValue value = new DummyValue("test", 111);
Data data1 = ss1.toData(value);
Data data2 = ss1.toData(new Foo());
Assert.assertNotNull(data1);
Assert.assertNotNull(data2);
assertEquals(1, writeCounter.get());
SerializationService ss2 = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
Object o1 = ss2.toObject(data1);
Object o2 = ss2.toObject(data2);
Assert.assertEquals(value, o1);
Assert.assertNotNull(o2);
assertEquals(1, readCounter.get());
}
use of com.hazelcast.nio.ObjectDataOutput in project hazelcast by hazelcast.
the class SerializationV1Portable method writePortable.
@Override
public void writePortable(PortableWriter out) throws IOException {
out.writeByte("1", aByte);
out.writeBoolean("2", aBoolean);
out.writeChar("3", character);
out.writeShort("4", aShort);
out.writeInt("5", integer);
out.writeLong("6", aLong);
out.writeFloat("7", aFloat);
out.writeDouble("8", aDouble);
out.writeUTF("9", string);
out.writeByteArray("a1", bytes);
out.writeBooleanArray("a2", booleans);
out.writeCharArray("a3", chars);
out.writeShortArray("a4", shorts);
out.writeIntArray("a5", ints);
out.writeLongArray("a6", longs);
out.writeFloatArray("a7", floats);
out.writeDoubleArray("a8", doubles);
out.writeUTFArray("a9", strings);
if (innerPortable == null) {
out.writeNullPortable("p", INNER_PORTABLE.getFactoryId(), INNER_PORTABLE.getClassId());
} else {
out.writePortable("p", innerPortable);
}
ObjectDataOutput rawDataOutput = out.getRawDataOutput();
boolean isNotNull = dataSerializable != null;
if (isNotNull) {
rawDataOutput.writeBoolean(isNotNull);
dataSerializable.writeData(rawDataOutput);
} else {
rawDataOutput.writeBoolean(isNotNull);
}
}
Aggregations