Search in sources :

Example 1 with ImportOptions

use of org.apache.jackrabbit.vault.fs.io.ImportOptions in project sling by apache.

the class FileVaultContentSerializer method importFromStream.

@Override
public void importFromStream(ResourceResolver resourceResolver, InputStream inputStream) throws DistributionException {
    Session session = null;
    OutputStream outputStream = null;
    File file = null;
    boolean isTmp = true;
    try {
        session = getSession(resourceResolver);
        ImportOptions importOptions = VltUtils.getImportOptions(aclHandling, importMode, autosaveThreshold);
        if (inputStream instanceof FileDistributionPackage.PackageInputStream) {
            file = ((FileDistributionPackage.PackageInputStream) inputStream).getFile();
            isTmp = false;
        } else {
            file = File.createTempFile("distrpck-tmp-" + System.nanoTime(), "." + TYPE);
        }
        outputStream = new BufferedOutputStream(new FileOutputStream(file));
        IOUtils.copy(inputStream, outputStream);
        IOUtils.closeQuietly(outputStream);
        PackageManager packageManager = packaging.getPackageManager();
        VaultPackage vaultPackage = packageManager.open(file);
        vaultPackage.extract(session, importOptions);
        vaultPackage.close();
    } catch (Exception e) {
        throw new DistributionException(e);
    } finally {
        IOUtils.closeQuietly(outputStream);
        if (isTmp) {
            FileUtils.deleteQuietly(file);
        }
        ungetSession(session);
    }
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) DistributionException(org.apache.sling.distribution.common.DistributionException) RepositoryException(javax.jcr.RepositoryException) PackageManager(org.apache.jackrabbit.vault.packaging.PackageManager) FileOutputStream(java.io.FileOutputStream) DistributionException(org.apache.sling.distribution.common.DistributionException) File(java.io.File) FileDistributionPackage(org.apache.sling.distribution.packaging.impl.FileDistributionPackage) BufferedOutputStream(java.io.BufferedOutputStream) ImportOptions(org.apache.jackrabbit.vault.fs.io.ImportOptions) VaultPackage(org.apache.jackrabbit.vault.packaging.VaultPackage) Session(javax.jcr.Session)

Aggregations

BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1 ImportOptions (org.apache.jackrabbit.vault.fs.io.ImportOptions)1 PackageManager (org.apache.jackrabbit.vault.packaging.PackageManager)1 VaultPackage (org.apache.jackrabbit.vault.packaging.VaultPackage)1 DistributionException (org.apache.sling.distribution.common.DistributionException)1 FileDistributionPackage (org.apache.sling.distribution.packaging.impl.FileDistributionPackage)1