return valueSerializer.fromStream(stream.getAsByteArray(serializedValues[iIndex]));
}
private byte[] convertIntoNewSerializationFormat(byte[] stream) throws IOException {
final OMemoryStream oldStream = new OMemoryStream(stream);
try {
int oldPageSize = oldStream.getAsInteger();
ORecordId oldParentRid = new ORecordId().fromStream(oldStream.getAsByteArrayFixed(ORecordId.PERSISTENT_SIZE));
ORecordId oldLeftRid = new ORecordId().fromStream(oldStream.getAsByteArrayFixed(ORecordId.PERSISTENT_SIZE));
ORecordId oldRightRid = new ORecordId().fromStream(oldStream.getAsByteArrayFixed(ORecordId.PERSISTENT_SIZE));
boolean oldColor = oldStream.getAsBoolean();
int oldSize = oldStream.getAsInteger();
if (oldSize > oldPageSize)
throw new OConfigurationException("Loaded index with page size set to " + oldPageSize
+ " while the loaded was built with: " + oldSize);
K[] oldKeys = (K[]) new Object[oldPageSize];
for (int i = 0; i < oldSize; ++i) {
oldKeys[i] = (K) ((OMVRBTreeMapProvider<K, V>) treeDataProvider).streamKeySerializer.fromStream(oldStream.getAsByteArray());
}
V[] oldValues = (V[]) new Object[oldPageSize];
for (int i = 0; i < oldSize; ++i) {
oldValues[i] = (V) ((OMVRBTreeMapProvider<K, V>) treeDataProvider).valueSerializer.fromStream(oldStream.getAsByteArray());
}
byte[] result;
if (((OMVRBTreeMapProvider<K, V>) treeDataProvider).valueSerializer instanceof OBinarySerializer)
result = convertNewSerializationFormatBinarySerializer(oldSize, oldPageSize, oldParentRid, oldLeftRid, oldRightRid,
oldColor, oldKeys, oldValues);
else
result = convertNewSerializationFormatStreamSerializer(oldSize, oldPageSize, oldParentRid, oldLeftRid, oldRightRid,
oldColor, oldKeys, oldValues);
return result;
} finally {
oldStream.close();
}
}