}
private Blob getBlobFromRecord(Record record, QName fieldName, FieldType fieldType, int... indexes)
throws BlobNotFoundException {
Object value = record.getField(fieldName);
ValueType valueType = fieldType.getValueType();
if (!valueType.getDeepestValueType().getBaseName().equals("BLOB")) {
throw new BlobNotFoundException("Blob could not be retrieved from '" + record.getId() + "', '" +
fieldName + "' at index: " + Ints.join("/", indexes));
}
if (indexes == null) {
indexes = new int[0];
}
for (int i = 0; i < indexes.length; i++) {
int index = indexes[i];
try {
if (valueType.getBaseName().equals("LIST")) {
value = ((List<Object>) value).get(index);
valueType = valueType.getNestedValueType();
continue;
}
if (valueType.getBaseName().equals("PATH")) {
value = ((HierarchyPath)value).getElements()[index];
valueType = valueType.getNestedValueType();
continue;
}
throw new BlobNotFoundException("Invalid index to retrieve Blob from '" + record.getId() +
"', '" + fieldName + "' : " + Ints.join("/", Arrays.copyOf(indexes, i + 1)));
} catch (IndexOutOfBoundsException e) {
throw new BlobNotFoundException("Invalid index to retrieve Blob from '" + record.getId() +
"', '" + fieldName + "' : " + Ints.join("/", Arrays.copyOf(indexes, i + 1)), e);
}
}
if (!valueType.getBaseName().equals("BLOB")) {
throw new BlobNotFoundException("Blob could not be retrieved from '" + record.getId() +
"', '" + fieldName + "' at index: " + Ints.join("/", indexes));
}
return (Blob)value;
}