org.apache.ivy.util.ChecksumHelper Java Examples

The following examples show how to use org.apache.ivy.util.ChecksumHelper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VerifyingExternalResourceDownloader.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private boolean check(ExternalResource resource, File dest, String algorithm) throws IOException {
    if (!ChecksumHelper.isKnownAlgorithm(algorithm)) {
        throw new IllegalArgumentException("Unknown checksum algorithm: " + algorithm);
    }

    ExternalResource checksumResource = repository.getResource(resource.getName() + "." + algorithm);
    if (checksumResource != null && checksumResource.exists()) {
        LOGGER.debug(algorithm + " file found for " + resource + ": checking...");
        File csFile = File.createTempFile("ivytmp", algorithm);
        try {
            get(checksumResource, csFile);
            ChecksumHelper.check(dest, csFile, algorithm);
            LOGGER.debug("{} OK for {}", algorithm, resource);
            return true;
        } finally {
            csFile.delete();
        }
    } else {
        return false;
    }
}
 
Example #2
Source File: VerifyingExternalResourceDownloader.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private boolean check(ExternalResource resource, File dest, String algorithm) throws IOException {
    if (!ChecksumHelper.isKnownAlgorithm(algorithm)) {
        throw new IllegalArgumentException("Unknown checksum algorithm: " + algorithm);
    }

    ExternalResource checksumResource = repository.getResource(resource.getName() + "." + algorithm);
    if (checksumResource != null && checksumResource.exists()) {
        LOGGER.debug(algorithm + " file found for " + resource + ": checking...");
        File csFile = File.createTempFile("ivytmp", algorithm);
        try {
            get(checksumResource, csFile);
            ChecksumHelper.check(dest, csFile, algorithm);
            LOGGER.debug("{} OK for {}", algorithm, resource);
            return true;
        } finally {
            csFile.delete();
        }
    } else {
        return false;
    }
}
 
Example #3
Source File: IvyPublisherForMaven.java    From jeka with Apache License 2.0 6 votes vote down vote up
private void putInRepo(Path source, String destination, boolean overwrite) {
    final Repository repository = this.resolver.getRepository();
    final String dest = completePath(destination);
    JkLog.info("Publish file " + dest);
    try {
        repository.put(null, source.toFile(), dest, overwrite);
        for (final String algo : checksumAlgos) {
            final Path temp = Files.createTempFile("jk-checksum-", algo);
            final String checkSum = ChecksumHelper.computeAsString(source.toFile(), algo);
            Files.write(temp, checkSum.getBytes());
            final String csDest = dest + "." + algo;
            JkLog.info("Publish file " + csDest);
            repository.put(null, temp.toFile(), csDest, overwrite);
            Files.deleteIfExists(temp);
        }
        if (this.signer != null) {
            final Path signed = signer.apply(source);
            final String signedDest = dest + ".asc";
            JkLog.info("Publish file " + signedDest);
            repository.put(null, signed.toFile(), signedDest, overwrite);
        }
    } catch (final IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #4
Source File: BasicResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the given resource checksum if a checksum resource exists.
 *
 * @param resource
 *            the resource to check
 * @param dest
 *            the file where the resource has been downloaded
 * @param algorithm
 *            the checksum algorithm to use
 * @return true if the checksum has been successfully checked, false if the checksum wasn't
 *         available
 * @throws IOException
 *             if a checksum exist but do not match the downloaded file checksum
 */
private boolean check(Resource resource, File dest, String algorithm) throws IOException {
    if (!ChecksumHelper.isKnownAlgorithm(algorithm)) {
        throw new IllegalArgumentException("Unknown checksum algorithm: " + algorithm);
    }

    Resource csRes = resource.clone(resource.getName() + "." + algorithm);
    if (csRes.exists()) {
        Message.debug(algorithm + " file found for " + resource + ": checking...");
        File csFile = File.createTempFile("ivytmp", algorithm);
        try {
            get(csRes, csFile);
            try {
                ChecksumHelper.check(dest, csFile, algorithm);
                Message.verbose(algorithm + " OK for " + resource);
                return true;
            } catch (IOException ex) {
                dest.delete();
                throw ex;
            }
        } finally {
            csFile.delete();
        }
    } else {
        return false;
    }
}
 
Example #5
Source File: RepositoryResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
protected void putChecksum(Artifact artifact, File src, String dest, boolean overwrite,
        String algorithm) throws IOException {
    File csFile = File.createTempFile("ivytemp", algorithm);
    try {
        FileUtil.copy(new ByteArrayInputStream(ChecksumHelper.computeAsString(src, algorithm)
                .getBytes()), csFile, null);
        repository.put(DefaultArtifact.cloneWithAnotherTypeAndExt(artifact, algorithm,
                artifact.getExt() + "." + algorithm), csFile,
                chopQuery(dest, algorithm), overwrite);
    } finally {
        csFile.delete();
    }
}