private static <T> void unwrapSerializationMetadata(ContextHolder<T> holder) throws ContextSerializationException {
String rawSerializedForm = holder.getRawSerializedForm();
String[] properties = CONTEXT_SERIALIZATION_PROPS_SEPARATOR_PATTERN.split(rawSerializedForm);
if(properties.length < CONTEXT_SERIALIZATION_PROPS_COUNT) {
throw new ContextSerializationException(
"Invalid serialized context key format. Number of properties in the serialized form: "
+ properties.length + " is less than expected: " + CONTEXT_SERIALIZATION_PROPS_COUNT);
}
String data = properties[CONTEXT_SERIALIZATION_PROPS_DATA_INDEX];
if (properties.length > CONTEXT_SERIALIZATION_PROPS_COUNT) {
// Serialized data has the separator, so we should concat them again
StringBuilder dataBuilder = new StringBuilder();
for (int i = CONTEXT_SERIALIZATION_PROPS_DATA_INDEX; i < properties.length; i++) {
String fragment = properties[i];
if (dataBuilder.length() > 0) {
dataBuilder.append(CONTEXT_SERIALIZATION_PROPS_SEPARATOR);
}
dataBuilder.append(fragment);
}
data = dataBuilder.toString();
} else {
data = unmaskIfEmpty(data);
}
int version;
try {
version = Integer.parseInt(properties[CONTEXT_SERIALIZATION_PROPS_VERSION_INDEX]);
} catch (NumberFormatException e) {
throw new ContextSerializationException(
"Illegal serialization version: " + properties[CONTEXT_SERIALIZATION_PROPS_VERSION_INDEX], e);
}
holder.update(data, version, properties[CONTEXT_SERIALIZATION_PROPS_SERIALIZER_INDEX]);
}