use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class BufferPoolImpl method takeInputBuffer.
@Override
public BufferObjectDataInput takeInputBuffer(Data data) {
BufferObjectDataInput in = inputQueue.poll();
if (in == null) {
in = serializationService.createObjectDataInput((byte[]) null);
}
in.init(data.toByteArray(), HeapData.DATA_OFFSET);
return in;
}
use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class ExplodeSnapshotP method traverser.
/* We can't close the BufferObjectDataInput cleanly. We close it when the returned traverser is fully iterated,
but the caller might not fully iterate it and we have no opportunity to close it.
On the other hand, the returned object doesn't hold any resources, so relying on the GC is sufficient.
See #19799 */
@SuppressWarnings("squid:S2095")
private Traverser<Object> traverser(byte[] data) {
BufferObjectDataInput in = serializationService.createObjectDataInput(data);
return () -> uncheckCall(() -> {
Object key = in.readObject();
if (key == SnapshotDataValueTerminator.INSTANCE) {
return null;
}
Object value = in.readObject();
return key instanceof BroadcastKey ? new BroadcastEntry(key, value) : entry(key, value);
});
}
use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class AsyncSnapshotWriterImplTest method test_serializeAndDeserialize.
@Test
public void test_serializeAndDeserialize() throws Exception {
// This is the way we serialize and deserialize objects into the snapshot. We depend on some internals of IMDG:
// - using the HeapData.toByteArray() from offset 4
// - concatenate them into one array
// - read that array with createObjectDataInput(byte[])
// Purpose of this test is to check that they didn't change anything...
Data serialized1 = serializationService.toData("foo");
Data serialized2 = serializationService.toData("bar");
ByteArrayOutputStream os = new ByteArrayOutputStream();
Stream.of(serialized1, serialized2).forEach(serialized -> {
Assert.assertTrue("unexpected class: " + serialized.getClass(), serialized instanceof HeapData);
byte[] bytes = serialized.toByteArray();
os.write(bytes, HeapData.TYPE_OFFSET, bytes.length - HeapData.TYPE_OFFSET);
});
BufferObjectDataInput in = serializationService.createObjectDataInput(os.toByteArray());
Assert.assertEquals("foo", in.readObject());
Assert.assertEquals("bar", in.readObject());
}
use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class BufferPoolTest method takeInputBuffer_whenPooledInstance.
// ======================= in ==========================================
@Test
public void takeInputBuffer_whenPooledInstance() {
Data data = new HeapData(new byte[] {});
BufferObjectDataInput found1 = bufferPool.takeInputBuffer(data);
bufferPool.returnInputBuffer(found1);
BufferObjectDataInput found2 = bufferPool.takeInputBuffer(data);
assertSame(found1, found2);
}
use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class StringSerializationTest method testNullStringEncodeDecode2.
@Test
public void testNullStringEncodeDecode2() throws Exception {
BufferObjectDataOutput objectDataOutput = serializationService.createObjectDataOutput();
objectDataOutput.writeString(null);
byte[] bytes = objectDataOutput.toByteArray();
objectDataOutput.close();
BufferObjectDataInput objectDataInput = serializationService.createObjectDataInput(bytes);
String decodedStr = objectDataInput.readString();
assertNull(decodedStr);
}
Aggregations