protected DistributionPackage readPackageInternal()

in src/main/java/org/apache/sling/distribution/packaging/impl/FileDistributionPackageBuilder.java [122:155]


    protected DistributionPackage readPackageInternal(@NotNull ResourceResolver resourceResolver, @NotNull InputStream stream)
            throws DistributionException {
        DistributionPackage distributionPackage;
        final File file;
        DigestOutputStream outputStream = null;
        try {
            String name;
            // stable id
            Map<String, Object> info = new HashMap<String, Object>();
            DistributionPackageUtils.readInfo(stream, info);
            Object remoteId = info.get(DistributionPackageUtils.PROPERTY_REMOTE_PACKAGE_ID);
            if (remoteId != null) {
                name = remoteId.toString();
                log.debug("preserving remote id {}", name);
            } else {
                name = "distrpck-read-" + System.nanoTime();
                log.debug("generating a new id {}", name);
            }
            file = File.createTempFile(name, "." + getType(), tempDirectory);
            outputStream = openDigestOutputStream(new FileOutputStream(file), digestAlgorithm);

            IOUtils.copy(stream, outputStream);
            outputStream.flush();

            String digestMessage = readDigestMessage(outputStream);
            distributionPackage = new FileDistributionPackage(file, getType(), digestAlgorithm, digestMessage, null);
        } catch (Exception e) {
            throw new DistributionException(e);
        } finally {
            IOUtils.closeQuietly(outputStream);
        }

        return distributionPackage;
    }