Examples of MessageDigestGenerator


Examples of org.rhq.core.util.MessageDigestGenerator

            visitor = new InMemoryZipFileVisitor(realizeRegex, this.deploymentData.getTemplateEngine());
            ZipUtil.walkZipFile(zipFile, visitor);
            fileHashcodeMap.putAll(visitor.getFileHashcodeMap());
        }

        MessageDigestGenerator generator = new MessageDigestGenerator();

        // calculate hashcodes for all raw files, perform in-memory realization when necessary
        for (Map.Entry<File, File> rawFile : this.deploymentData.getRawFiles().entrySet()) {
            // determine where the original file is and where it would go if we were writing it to disk
            File currentLocationFile = rawFile.getKey();
            File newLocationFile = rawFile.getValue();
            String newLocationPath = rawFile.getValue().getPath();
            if (!newLocationFile.isAbsolute()) {
                newLocationFile = new File(this.deploymentData.getDestinationDir(), newLocationFile.getPath());
            }

            String hashcode;

            boolean realize = false;
            if (this.deploymentData.getRawFilesToRealize() != null) {
                realize = this.deploymentData.getRawFilesToRealize().contains(currentLocationFile);
            }

            if (realize) {
                debug("Realizing file [", currentLocationFile, "] in-memory to determine its hashcode");

                // this entry needs to be realized, do it now in-memory (we assume realizable files will not be large)
                // note: tempateEngine will never be null if we got here
                FileInputStream in = new FileInputStream(currentLocationFile);
                byte[] rawFileContent = StreamUtil.slurp(in);
                String content = this.deploymentData.getTemplateEngine().replaceTokens(new String(rawFileContent));

                // now calculate the hashcode of the realized content
                generator.add(content.getBytes());
                hashcode = generator.getDigestString();
            } else {
                debug("Streaming file [", currentLocationFile, "] in-memory to determine its hashcode");

                BufferedInputStream in = new BufferedInputStream(new FileInputStream(currentLocationFile));
                try {
                    hashcode = generator.calcDigestString(in);
                } finally {
                    in.close();
                }
            }
View Full Code Here

Examples of org.rhq.core.util.MessageDigestGenerator

            filesToRealizeRegex = null;
            templateEngine = null;
        }
        this.filesToRealizeRegex = filesToRealizeRegex;
        this.templateEngine = templateEngine;
        this.hashcodeGenerator = new MessageDigestGenerator();
    }
View Full Code Here

Examples of org.rhq.core.util.MessageDigestGenerator

                } finally {
                    fos.close();
                }
            }

            MessageDigestGenerator hashcodeGenerator = this.copierAndHashcodeGenerator.getMessageDigestGenerator();
            hashcodeGenerator.add(bytes);
            hashcode = hashcodeGenerator.getDigestString();
        } else {
            if (!dryRun) {
                FileOutputStream fos = new FileOutputStream(entryFile);
                try {
                    hashcode = this.copierAndHashcodeGenerator.copyAndCalculateHashcode(stream, fos);
View Full Code Here

Examples of org.rhq.core.util.MessageDigestGenerator

                    }

                    //any jar should be fine. Use canned jar
                    InputStream originalBinaryStream = this.getClass().getClassLoader()
                        .getResourceAsStream("binary-blob-sample.jar");
                    String originalDigest = new MessageDigestGenerator(MessageDigestGenerator.SHA_256)
                        .calcDigestString(originalBinaryStream);
                    originalBinaryStream.close();
                    originalBinaryStream = this.getClass().getClassLoader()
                        .getResourceAsStream("binary-blob-sample.jar");
                    contentManager.updateBlobStream(originalBinaryStream, packageBits, null);
                    packageBits = em.find(PackageBits.class, packageBits.getId());

                    // test that the bits are available and stored in the DB: Reading the Blob
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer.getId();
                    assert composite.getPackageBitsId() == packageBits.getId();
                    assert composite.isPackageBitsAvailable();
                    assert composite.isPackageBitsInDatabase();

                    FileOutputStream outputStream = new FileOutputStream(retrieved);
                    contentManager.writeBlobOutToStream(outputStream, packageBits, false);

                    //Check that db content equal to file system content
                    String newDigest = new MessageDigestGenerator(MessageDigestGenerator.SHA_256)
                        .calcDigestString(retrieved);
                    assertEquals("Uploaded and retrieved digests differ:", originalDigest, newDigest);

                } catch (Throwable t) {
                    t.printStackTrace();
View Full Code Here

Examples of org.rhq.core.util.MessageDigestGenerator

    MessageDigestGenerator digestGenerator;

    @Override
    protected void beforeMethod() throws Exception {
        digestGenerator = new MessageDigestGenerator(MessageDigestGenerator.SHA_256);
        jpaDriftServer = LookupUtil.getJPADriftServer();
        driftManager = LookupUtil.getDriftManager();
        overlord = LookupUtil.getSubjectManager().getOverlord();

        driftServerService = new DriftServerServiceImpl();
View Full Code Here

Examples of org.rhq.core.util.MessageDigestGenerator

    }

    RawConfiguration createRawConfiguration(String path) {
        RawConfiguration rawConfig = new RawConfiguration();
        String contents = new String(randomBytes());
        String sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(contents);
        rawConfig.setContents(contents, sha256);
        rawConfig.setPath(path);

        return rawConfig;
    }
View Full Code Here

Examples of org.rhq.core.util.MessageDigestGenerator

        return new PageList<PackageVersionMetadataComposite>(results, (int) count, pc);
    }

    @SuppressWarnings("unchecked")
    public String getResourceSubscriptionMD5(int resourceId) {
        MessageDigestGenerator md5Generator = new MessageDigestGenerator();

        Query q = entityManager.createNamedQuery(Repo.QUERY_FIND_REPOS_BY_RESOURCE_ID);
        q.setParameter("resourceId", resourceId);
        List<Repo> repos = q.getResultList();

        for (Repo repo : repos) {
            long modifiedTimestamp = repo.getLastModifiedDate();
            Date modifiedDate = new Date(modifiedTimestamp);
            md5Generator.add(Integer.toString(modifiedDate.hashCode()).getBytes());
        }

        String digestString = md5Generator.getDigestString();
        return digestString;
    }
View Full Code Here

Examples of org.rhq.core.util.MessageDigestGenerator

        // update contentDetails in needed
        if (null != contentDetails) {
            contentDetails.put(UPLOAD_FILE_SIZE, String.valueOf(bytes.length));
            try {
                contentDetails.put(UPLOAD_SHA256,
                    new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(bytes));
            } catch (Exception e) {
                throw new RuntimeException("Failed to calculate SHA256 for package bits: ", e);
            }
        }
View Full Code Here

Examples of org.rhq.core.util.MessageDigestGenerator

    @SuppressWarnings("resource")
    private long copyAndDigest(InputStream input, OutputStream output, boolean closeStreams,
        Map<String, String> contentDetails) throws RuntimeException {
        long numBytesCopied = 0;
        int bufferSize = 32768;
        MessageDigestGenerator digestGenerator = null;
        if (contentDetails != null) {
            digestGenerator = new MessageDigestGenerator(MessageDigestGenerator.SHA_256);
        }
        try {
            // make sure we buffer the input
            input = new BufferedInputStream(input, bufferSize);

            byte[] buffer = new byte[bufferSize];

            for (int bytesRead = input.read(buffer); bytesRead != -1; bytesRead = input.read(buffer)) {
                output.write(buffer, 0, bytesRead);
                numBytesCopied += bytesRead;
                if (digestGenerator != null) {
                    digestGenerator.add(buffer, 0, bytesRead);
                }
            }

            if (contentDetails != null) {//if we're calculating a digest as well
                contentDetails.put(UPLOAD_FILE_SIZE, String.valueOf(numBytesCopied));
                contentDetails.put(UPLOAD_SHA256, digestGenerator.getDigestString());
            }
            output.flush();
        } catch (IOException ioe) {
            throw new RuntimeException("Stream data cannot be copied", ioe);
        } finally {
View Full Code Here

Examples of org.rhq.core.util.MessageDigestGenerator

    private ResourceConfigurationUpdate persistNewAgentReportedResourceConfiguration(Resource resource,
        Configuration liveConfig) throws ConfigurationUpdateStillInProgressException {

        if (liveConfig.getRawConfigurations() != null) {
            for (RawConfiguration raw : liveConfig.getRawConfigurations()) {
                MessageDigestGenerator sha256Generator = new MessageDigestGenerator(MessageDigestGenerator.SHA_256);
                sha256Generator.add(raw.getContents().getBytes());
                raw.setSha256(sha256Generator.getDigestString());
            }
        }

        /*
        * NOTE: We pass the overlord, since this is a system side-effect.  here, the system
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.