Package org.rhq.core.util

Examples of org.rhq.core.util.MessageDigestGenerator


                    config.put(new PropertySimple("sealed", attributes.getValue(Attributes.Name.SEALED)));
                }

                String sha256 = null;
                try {
                    sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(file);
                } catch (Exception e) {
                    // leave as null
                }

                ResourcePackageDetails details = new ResourcePackageDetails(new PackageDetailsKey(file.getName(),
View Full Code Here


     */
    public void createContent(File destination, File content, boolean unzip) {
        try {
            if (unzip) {
                ZipUtil.unzipFile(content, destination);
                String sha = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(content);
                writeSHAToManifest(destination, sha);
            } else {
                InputStream contentStream = new BufferedInputStream(new FileInputStream(content));
                FileUtil.writeFile(contentStream, destination);
            }
View Full Code Here

                if (sha == null || sha.trim().isEmpty()) {
                    sha = computeAndSaveSHA(deploymentFile);
                }
            } else {
                sha = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(deploymentFile);
            }
        } catch (IOException ex) {
            throw new RuntimeException("Problem calculating digest of package [" + deploymentFile.getPath() + "].", ex);
        }
View Full Code Here

     */
    private String computeAndSaveSHA(File deploymentDirectory) {
        String sha = null;
        try {
            if (deploymentDirectory.isDirectory()) {
                MessageDigestGenerator messageDigest = new MessageDigestGenerator(MessageDigestGenerator.SHA_256);

                Stack<File> unvisitedFolders = new Stack<File>();
                unvisitedFolders.add(deploymentDirectory);
                while (!unvisitedFolders.empty()) {
                    File[] files = unvisitedFolders.pop().listFiles();
                    Arrays.sort(files, new Comparator<File>() {
                        public int compare(File f1, File f2) {
                            try {
                                return f1.getCanonicalPath().compareTo(f2.getCanonicalPath());
                            } catch (IOException e) {
                                //do nothing if the sort fails at this point
                            }

                            return 0;
                        }
                    });

                    for (File file : files) {
                        if (file.isDirectory()) {
                            unvisitedFolders.add(file);
                        } else {
                            FileInputStream inputStream = null;
                            try {
                                inputStream = new FileInputStream(file);
                                messageDigest.add(inputStream);
                            } finally {
                                if (inputStream != null) {
                                    inputStream.close();
                                }
                            }
                        }
                    }
                }

                sha = messageDigest.getDigestString();
                writeSHAToManifest(deploymentDirectory, sha);
            }
        } catch (IOException e) {
            throw new RuntimeException("Error creating artifact for contentFile: " + deploymentDirectory, e);
        }
View Full Code Here

        random.nextBytes(bytes);

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

        return rawConfig;
    }
View Full Code Here

    private RawConfiguration createCopyOfRawConfiguration(RawConfiguration rawConfig) {
        RawConfiguration copy = new RawConfiguration();
        copy.setPath(rawConfig.getPath());
        String contents = rawConfig.getContents();
        String sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(contents);
        copy.setContents(contents, sha256);
        copy.setConfiguration(rawConfig.getConfiguration());

        return copy;
    }
View Full Code Here

        assertEquals(original.getContents(), copy.getContents(), "Failed to copy the contents property");
        assertEquals(copy.getContents(), original.getContents(), "Failed to copy contents property.");
    }

    private void setContentsAndSha256(RawConfiguration rc, String contents) {
        String sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(contents);
        rc.setContents(contents, sha256);
    }
View Full Code Here

            Configuration config = createAndSaveConfiguration();

            RawConfiguration rawConfig = new RawConfiguration();
            rawConfig.setConfiguration(config);
            String contents = "contents";
            String sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(contents);
            rawConfig.setContents(contents, sha256);
            rawConfig.setPath("/tmp/foo.txt");

            entityMgr.persist(rawConfig);
View Full Code Here

    }

    RawConfiguration createRawConfiguration() {
        RawConfiguration rawConfig = new RawConfiguration();
        String contents = "contents";
        String sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(contents);
        rawConfig.setContents(contents, sha256);
        rawConfig.setPath("/tmp/foo");

        return rawConfig;
    }
View Full Code Here

        Assert.assertEquals((long) actualResourcePackageDetails.getFileSize(), fileUsedInTest.length());
        if (actualResourcePackageDetails.getInstallationTimestamp() > System.currentTimeMillis()) {
            Assert.fail("Timestamp is not in the past.");
        }

        MessageDigestGenerator digest = new MessageDigestGenerator(MessageDigestGenerator.SHA_256);
        String expectedSha256 = digest.calcDigestString(fileUsedInTest);

        Assert.assertEquals(actualResourcePackageDetails.getSHA256(), expectedSha256);
        Assert.assertEquals(actualResourcePackageDetails.getDisplayVersion(), null);

        verify(mockResourceContext, times(1)).getPluginConfiguration();
View Full Code Here

TOP

Related Classes of org.rhq.core.util.MessageDigestGenerator

Copyright © 2018 www.massapicom. 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.