use of com.hazelcast.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class PortablePositionNavigator method createPositionForPortableArrayAccess.
private static PortablePosition createPositionForPortableArrayAccess(PortableNavigatorContext ctx, PortablePathCursor path, int index, boolean singleCellAccess) throws IOException {
BufferObjectDataInput in = ctx.getIn();
in.position(getStreamPositionOfTheField(ctx));
// read and validate portable properties
int len = in.readInt();
int factoryId = in.readInt();
int classId = in.readInt();
int streamPosition = in.position();
validateFactoryAndClass(ctx.getCurrentFieldDefinition(), factoryId, classId, path.path());
// if single-cell access, dead-reckon cell's position that's specified by the index
if (singleCellAccess) {
if (index < len) {
int offset = in.position() + index * Bits.INT_SIZE_IN_BYTES;
in.position(offset);
streamPosition = in.readInt();
} else {
// return null if index out-of-bound
return PortablePositionFactory.nil(path.isLastToken());
}
}
return PortablePositionFactory.createSinglePortablePosition(ctx.getCurrentFieldDefinition(), streamPosition, factoryId, classId, index, len, path.isLastToken());
}
use of com.hazelcast.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class PortableContextImpl method lookupClassDefinition.
@Override
public ClassDefinition lookupClassDefinition(Data data) throws IOException {
if (!data.isPortable()) {
throw new IllegalArgumentException("Data is not Portable!");
}
BufferObjectDataInput in = serializationService.createObjectDataInput(data);
int factoryId = in.readInt();
int classId = in.readInt();
int version = in.readInt();
ClassDefinition classDefinition = lookupClassDefinition(factoryId, classId, version);
if (classDefinition == null) {
classDefinition = readClassDefinition(in, factoryId, classId, version);
}
return classDefinition;
}
use of com.hazelcast.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.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class PortableUtilsTest method getPortableArrayCellPosition.
@Test
public void getPortableArrayCellPosition() throws Exception {
// GIVEN
BufferObjectDataInput in = mock(BufferObjectDataInput.class);
int offset = 10;
int cellIndex = 3;
// WHEN
PortableUtils.getPortableArrayCellPosition(in, offset, cellIndex);
// THEN
verify(in, times(1)).readInt(offset + cellIndex * Bits.INT_SIZE_IN_BYTES);
}
use of com.hazelcast.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class PortableUtilsTest method unknownFieldException.
@Test
public void unknownFieldException() {
// GIVEN
BufferObjectDataInput in = mock(BufferObjectDataInput.class);
ClassDefinition cd = mock(ClassDefinition.class);
PortableNavigatorContext ctx = new PortableNavigatorContext(in, cd, null);
// WHEN
HazelcastSerializationException ex = PortableUtils.createUnknownFieldException(ctx, "person.brain");
// THEN
assertNotNull(ex);
}
Aggregations