use of org.apache.sling.distribution.util.impl.FileBackedMemoryOutputStream in project sling by apache.
the class ResourceDistributionPackageBuilder method createPackageForAdd.
@Override
protected DistributionPackage createPackageForAdd(@Nonnull ResourceResolver resourceResolver, @Nonnull DistributionRequest request) throws DistributionException {
DistributionPackage distributionPackage;
try {
FileBackedMemoryOutputStream outputStream = null;
DigestOutputStream digestStream = null;
String digestMessage = null;
try {
outputStream = new FileBackedMemoryOutputStream(fileThreshold, memoryUnit, useOffHeapMemory, tempDirectory, "distrpck-create-", "." + getType());
if (digestAlgorithm != null) {
digestStream = openDigestOutputStream(outputStream, digestAlgorithm);
export(resourceResolver, request, digestStream);
} else {
export(resourceResolver, request, outputStream);
}
outputStream.flush();
if (digestAlgorithm != null) {
digestMessage = readDigestMessage(digestStream);
}
} finally {
IOUtils.closeQuietly(outputStream);
IOUtils.closeQuietly(digestStream);
}
Resource packagesRoot = DistributionPackageUtils.getPackagesRoot(resourceResolver, packagesPath);
InputStream inputStream = null;
Resource packageResource = null;
try {
inputStream = outputStream.openWrittenDataInputStream();
packageResource = uploadStream(resourceResolver, packagesRoot, inputStream, outputStream.size());
} finally {
IOUtils.closeQuietly(inputStream);
outputStream.clean();
}
distributionPackage = new ResourceDistributionPackage(packageResource, getType(), resourceResolver, digestAlgorithm, digestMessage);
} catch (IOException e) {
throw new DistributionException(e);
}
return distributionPackage;
}
Aggregations