InputStream is = null;
try {
ResourceSerializer<?, ?> serializer = getSerializerByType(uri.getType());
if (serializer == null) {
logger.warn("No resource serializer for type '{}' found", uri.getType());
throw new ContentRepositoryException("No resource serializer for type '" + uri.getType() + "' found");
}
ResourceReader<?, ?> reader = serializer.getReader();
is = IOUtils.toInputStream(searchResultItem.getResourceXml(), "utf-8");
return (R) reader.read(is, site);
} catch (Throwable t) {
logger.error("Error loading {}: {}", uri, t.getMessage());
throw new ContentRepositoryException(t);
} finally {
IOUtils.closeQuietly(is);
}
} else {
try {
Resource<?> resource = null;
InputStream is = null;
try {
InputStream resourceStream = loadResource(uri);
if (resourceStream == null) {
return null;
}
is = new BufferedInputStream(resourceStream);
ResourceSerializer<?, ?> serializer = getSerializerByType(uri.getType());
ResourceReader<?, ?> reader = serializer.getReader();
resource = reader.read(is, site);
} catch (Throwable t) {
String version = ResourceUtils.getVersionString(uri.getVersion());
throw new IOException("Error reading " + version + " version of " + uri + " (" + uri.getIdentifier() + ")", t);
} finally {
IOUtils.closeQuietly(is);
}
if (resource == null) {
logger.error("Index inconsistency detected: version '{}' of {} does not exist on disk", ResourceUtils.getVersionString(uri.getVersion()), uri);
return null;
}
return (R) resource;
} catch (IOException e) {
logger.error("Error loading {}: {}", uri, e.getMessage());
throw new ContentRepositoryException(e);
}
}
}