use of com.hazelcast.nio.ObjectDataOutput in project hazelcast-jet by hazelcast.
the class HashMapHook method createSerializer.
@Override
@SuppressWarnings("checkstyle:anoninnerlength")
public Serializer createSerializer() {
return new StreamSerializer<HashMap>() {
@Override
public int getTypeId() {
return SerializerHookConstants.HASH_MAP;
}
@Override
public void destroy() {
}
@Override
@SuppressWarnings("checkstyle:illegaltype")
public void write(ObjectDataOutput out, HashMap map) throws IOException {
out.writeInt(map.size());
for (Object o : map.entrySet()) {
Map.Entry e = (Map.Entry) o;
out.writeObject(e.getKey());
out.writeObject(e.getValue());
}
}
@Override
@SuppressWarnings("checkstyle:illegaltype")
public HashMap read(ObjectDataInput in) throws IOException {
int length = in.readInt();
HashMap map = new HashMap();
for (int i = 0; i < length; i++) {
// noinspection unchecked
map.put(in.readObject(), in.readObject());
}
return map;
}
};
}
use of com.hazelcast.nio.ObjectDataOutput 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;
}
};
}
use of com.hazelcast.nio.ObjectDataOutput in project hazelcast by hazelcast.
the class SerializationIssueTest method testEmptyData.
@Test
public void testEmptyData() {
SerializationConfig serializationConfig = new SerializationConfig().addSerializerConfig(new SerializerConfig().setTypeClass(SingletonValue.class).setImplementation(new StreamSerializer<SingletonValue>() {
@Override
public void write(ObjectDataOutput out, SingletonValue v) throws IOException {
}
@Override
public SingletonValue read(ObjectDataInput in) throws IOException {
return new SingletonValue();
}
@Override
public int getTypeId() {
return 123;
}
@Override
public void destroy() {
}
}));
SerializationService ss1 = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
Data data = ss1.toData(new SingletonValue());
Assert.assertNotNull(data);
SerializationService ss2 = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
Object o = ss2.toObject(data);
Assert.assertEquals(new SingletonValue(), o);
}
use of com.hazelcast.nio.ObjectDataOutput in project hazelcast by hazelcast.
the class DataInputOutputTest method testDataStreams.
private void testDataStreams(Object object, ByteOrder byteOrder, boolean allowUnsafe) throws IOException {
InternalSerializationService ss = createSerializationServiceBuilder().setUseNativeByteOrder(false).setAllowUnsafe(allowUnsafe).setByteOrder(byteOrder).build();
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectDataOutput out = createObjectDataOutputStream(bout, ss);
out.writeObject(object);
byte[] data1 = bout.toByteArray();
ObjectDataOutput out2 = ss.createObjectDataOutput(1024);
out2.writeObject(object);
byte[] data2 = out2.toByteArray();
assertEquals(data1.length, data2.length);
assertTrue(Arrays.equals(data1, data2));
final ByteArrayInputStream bin = new ByteArrayInputStream(data2);
final ObjectDataInput in = createObjectDataInputStream(bin, ss);
final Object object1 = in.readObject();
final ObjectDataInput in2 = ss.createObjectDataInput(data1);
final Object object2 = in2.readObject();
Assert.assertEquals(object, object1);
Assert.assertEquals(object, object2);
}
use of com.hazelcast.nio.ObjectDataOutput in project hazelcast by hazelcast.
the class DataSerializableImplementsVersionedTest method getObjectDataOutput.
// overridden in EE
protected ObjectDataOutput getObjectDataOutput() {
ObjectDataOutput output = mock(ObjectDataOutput.class, withSettings().extraInterfaces(SerializationServiceSupport.class, DataWriter.class));
when(((SerializationServiceSupport) output).getSerializationService()).thenReturn(serializationService);
return output;
}
Aggregations