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);
}
}
Aggregations