Search in sources :

Example 1 with FileBackedMemoryOutputStream

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;
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) FileBackedMemoryOutputStream(org.apache.sling.distribution.util.impl.FileBackedMemoryOutputStream) DigestUtils.openDigestOutputStream(org.apache.sling.distribution.util.impl.DigestUtils.openDigestOutputStream) DigestOutputStream(java.security.DigestOutputStream) InputStream(java.io.InputStream) Resource(org.apache.sling.api.resource.Resource) DistributionException(org.apache.sling.distribution.common.DistributionException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 DigestOutputStream (java.security.DigestOutputStream)1 Resource (org.apache.sling.api.resource.Resource)1 DistributionException (org.apache.sling.distribution.common.DistributionException)1 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)1 DigestUtils.openDigestOutputStream (org.apache.sling.distribution.util.impl.DigestUtils.openDigestOutputStream)1 FileBackedMemoryOutputStream (org.apache.sling.distribution.util.impl.FileBackedMemoryOutputStream)1