private URL addResourceContent(InputStream input, Map<String, Object> atts) throws IOException {
synchronized (storageDir) {
File tempFile = new File(storageDir.getAbsolutePath() + File.separator + "temp-content");
Long size = copyResourceContent(input, tempFile);
atts.put(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE, size);
String sha256;
String algorithm = RepositoryContentHelper.DEFAULT_DIGEST_ALGORITHM;
try {
sha256 = RepositoryContentHelper.getDigest(new FileInputStream(tempFile), algorithm);
atts.put(ContentNamespace.CONTENT_NAMESPACE, sha256);
} catch (NoSuchAlgorithmException ex) {
throw MESSAGES.noSuchAlgorithm(ex, algorithm);
}
String contentPath = sha256.substring(0, 2) + File.separator + sha256.substring(2) + File.separator + "content";
File targetFile = new File(storageDir.getAbsolutePath() + File.separator + contentPath);
targetFile.getParentFile().mkdirs();
tempFile.renameTo(targetFile);
URL url = targetFile.toURI().toURL();
atts.put(ContentNamespace.CAPABILITY_URL_ATTRIBUTE, url.toExternalForm());
return url;
}
}