use of org.apache.sling.distribution.serialization.DistributionExportFilter in project sling by apache.
the class FileDistributionPackageBuilder method createPackageForAdd.
@Override
protected DistributionPackage createPackageForAdd(@Nonnull ResourceResolver resourceResolver, @Nonnull final DistributionRequest request) throws DistributionException {
DistributionPackage distributionPackage;
OutputStream outputStream = null;
String digestMessage = null;
final File file;
try {
file = File.createTempFile("distrpck-create-" + randomUUID(), "." + getType(), tempDirectory);
if (digestAlgorithm != null) {
outputStream = openDigestOutputStream(new FileOutputStream(file), digestAlgorithm);
} else {
outputStream = new FileOutputStream(file);
}
final DistributionExportFilter filter = distributionContentSerializer.isRequestFiltering() ? null : DistributionExportFilter.createFilter(request, nodeFilters, propertyFilters);
DistributionExportOptions distributionExportOptions = new DistributionExportOptions(request, filter);
distributionContentSerializer.exportToStream(resourceResolver, distributionExportOptions, outputStream);
outputStream.flush();
if (digestAlgorithm != null) {
digestMessage = readDigestMessage((DigestOutputStream) outputStream);
}
distributionPackage = new FileDistributionPackage(file, getType(), digestAlgorithm, digestMessage);
} catch (IOException e) {
throw new DistributionException(e);
} finally {
IOUtils.closeQuietly(outputStream);
}
return distributionPackage;
}
use of org.apache.sling.distribution.serialization.DistributionExportFilter in project sling by apache.
the class ResourceDistributionPackageBuilder method export.
private void export(@Nonnull ResourceResolver resourceResolver, @Nonnull final DistributionRequest request, OutputStream outputStream) throws DistributionException {
final DistributionExportFilter filter = distributionContentSerializer.isRequestFiltering() ? null : DistributionExportFilter.createFilter(request, nodeFilters, propertyFilters);
DistributionExportOptions distributionExportOptions = new DistributionExportOptions(request, filter);
distributionContentSerializer.exportToStream(resourceResolver, distributionExportOptions, outputStream);
}
use of org.apache.sling.distribution.serialization.DistributionExportFilter in project sling by apache.
the class KryoContentSerializerTest method testExtract.
@Test
public void testExtract() throws Exception {
KryoContentSerializer kryoContentSerializer = new KryoContentSerializer("kryo");
DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/libs");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
NavigableMap<String, List<String>> nodeFilters = new TreeMap<String, List<String>>();
NavigableMap<String, List<String>> propertyFilters = new TreeMap<String, List<String>>();
try {
DistributionExportFilter filter = DistributionExportFilter.createFilter(request, nodeFilters, propertyFilters);
kryoContentSerializer.exportToStream(resourceResolver, new DistributionExportOptions(request, filter), outputStream);
byte[] bytes = outputStream.toByteArray();
assertNotNull(bytes);
assertTrue(bytes.length > 0);
} finally {
outputStream.close();
}
}
Aggregations